denchclaw 3.0.6 → 3.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/apps/web/.next/standalone/apps/web/.next/BUILD_ID +1 -1
  2. package/apps/web/.next/standalone/apps/web/.next/app-build-manifest.json +290 -290
  3. package/apps/web/.next/standalone/apps/web/.next/app-path-routes-manifest.json +49 -49
  4. package/apps/web/.next/standalone/apps/web/.next/build-manifest.json +5 -5
  5. package/apps/web/.next/standalone/apps/web/.next/cache/config.json +3 -3
  6. package/apps/web/.next/standalone/apps/web/.next/prerender-manifest.json +3 -3
  7. package/apps/web/.next/standalone/apps/web/.next/react-loadable-manifest.json +2 -2
  8. package/apps/web/.next/standalone/apps/web/.next/required-server-files.json +1 -1
  9. package/apps/web/.next/standalone/apps/web/.next/routes-manifest.json +1 -1
  10. package/apps/web/.next/standalone/apps/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  11. package/apps/web/.next/standalone/apps/web/.next/server/app/api/apps/cron/route_client-reference-manifest.js +1 -1
  12. package/apps/web/.next/standalone/apps/web/.next/server/app/api/apps/proxy/route_client-reference-manifest.js +1 -1
  13. package/apps/web/.next/standalone/apps/web/.next/server/app/api/apps/route_client-reference-manifest.js +1 -1
  14. package/apps/web/.next/standalone/apps/web/.next/server/app/api/apps/serve/[...path]/route_client-reference-manifest.js +1 -1
  15. package/apps/web/.next/standalone/apps/web/.next/server/app/api/apps/store/route_client-reference-manifest.js +1 -1
  16. package/apps/web/.next/standalone/apps/web/.next/server/app/api/apps/webhooks/[...path]/route_client-reference-manifest.js +1 -1
  17. package/apps/web/.next/standalone/apps/web/.next/server/app/api/chat/active/route_client-reference-manifest.js +1 -1
  18. package/apps/web/.next/standalone/apps/web/.next/server/app/api/chat/route.js +1 -1
  19. package/apps/web/.next/standalone/apps/web/.next/server/app/api/chat/route_client-reference-manifest.js +1 -1
  20. package/apps/web/.next/standalone/apps/web/.next/server/app/api/chat/runs/route_client-reference-manifest.js +1 -1
  21. package/apps/web/.next/standalone/apps/web/.next/server/app/api/chat/stop/route.js +1 -1
  22. package/apps/web/.next/standalone/apps/web/.next/server/app/api/chat/stop/route_client-reference-manifest.js +1 -1
  23. package/apps/web/.next/standalone/apps/web/.next/server/app/api/chat/stream/route_client-reference-manifest.js +1 -1
  24. package/apps/web/.next/standalone/apps/web/.next/server/app/api/chat/subagents/route_client-reference-manifest.js +1 -1
  25. package/apps/web/.next/standalone/apps/web/.next/server/app/api/composio/callback/route.js +2 -2
  26. package/apps/web/.next/standalone/apps/web/.next/server/app/api/composio/callback/route_client-reference-manifest.js +1 -1
  27. package/apps/web/.next/standalone/apps/web/.next/server/app/api/composio/connect/route.js +1 -1
  28. package/apps/web/.next/standalone/apps/web/.next/server/app/api/composio/connect/route_client-reference-manifest.js +1 -1
  29. package/apps/web/.next/standalone/apps/web/.next/server/app/api/composio/connections/route_client-reference-manifest.js +1 -1
  30. package/apps/web/.next/standalone/apps/web/.next/server/app/api/composio/disconnect/route_client-reference-manifest.js +1 -1
  31. package/apps/web/.next/standalone/apps/web/.next/server/app/api/composio/status/route.js +2 -2
  32. package/apps/web/.next/standalone/apps/web/.next/server/app/api/composio/status/route_client-reference-manifest.js +1 -1
  33. package/apps/web/.next/standalone/apps/web/.next/server/app/api/composio/toolkits/route_client-reference-manifest.js +1 -1
  34. package/apps/web/.next/standalone/apps/web/.next/server/app/api/crm/calendar/[id]/route_client-reference-manifest.js +1 -1
  35. package/apps/web/.next/standalone/apps/web/.next/server/app/api/crm/calendar/route_client-reference-manifest.js +1 -1
  36. package/apps/web/.next/standalone/apps/web/.next/server/app/api/crm/companies/[id]/route_client-reference-manifest.js +1 -1
  37. package/apps/web/.next/standalone/apps/web/.next/server/app/api/crm/enrich/[type]/[id]/route_client-reference-manifest.js +1 -1
  38. package/apps/web/.next/standalone/apps/web/.next/server/app/api/crm/inbox/[threadId]/route_client-reference-manifest.js +1 -1
  39. package/apps/web/.next/standalone/apps/web/.next/server/app/api/crm/inbox/route_client-reference-manifest.js +1 -1
  40. package/apps/web/.next/standalone/apps/web/.next/server/app/api/crm/people/[id]/activity/route_client-reference-manifest.js +1 -1
  41. package/apps/web/.next/standalone/apps/web/.next/server/app/api/crm/people/[id]/route_client-reference-manifest.js +1 -1
  42. package/apps/web/.next/standalone/apps/web/.next/server/app/api/crm/people/route_client-reference-manifest.js +1 -1
  43. package/apps/web/.next/standalone/apps/web/.next/server/app/api/crm/photos/proxy/route_client-reference-manifest.js +1 -1
  44. package/apps/web/.next/standalone/apps/web/.next/server/app/api/crm/photos/sync/route_client-reference-manifest.js +1 -1
  45. package/apps/web/.next/standalone/apps/web/.next/server/app/api/cron/heartbeat/route_client-reference-manifest.js +1 -1
  46. package/apps/web/.next/standalone/apps/web/.next/server/app/api/cron/jobs/[jobId]/runs/route_client-reference-manifest.js +1 -1
  47. package/apps/web/.next/standalone/apps/web/.next/server/app/api/cron/jobs/route_client-reference-manifest.js +1 -1
  48. package/apps/web/.next/standalone/apps/web/.next/server/app/api/cron/runs/[sessionId]/route_client-reference-manifest.js +1 -1
  49. package/apps/web/.next/standalone/apps/web/.next/server/app/api/cron/runs/search-transcript/route_client-reference-manifest.js +1 -1
  50. package/apps/web/.next/standalone/apps/web/.next/server/app/api/feedback/route.js +1 -1
  51. package/apps/web/.next/standalone/apps/web/.next/server/app/api/feedback/route_client-reference-manifest.js +1 -1
  52. package/apps/web/.next/standalone/apps/web/.next/server/app/api/gateway/channels/route_client-reference-manifest.js +1 -1
  53. package/apps/web/.next/standalone/apps/web/.next/server/app/api/gateway/chat/route_client-reference-manifest.js +1 -1
  54. package/apps/web/.next/standalone/apps/web/.next/server/app/api/gateway/chat/stream/route_client-reference-manifest.js +1 -1
  55. package/apps/web/.next/standalone/apps/web/.next/server/app/api/gateway/sessions/[id]/route_client-reference-manifest.js +1 -1
  56. package/apps/web/.next/standalone/apps/web/.next/server/app/api/gateway/sessions/route_client-reference-manifest.js +1 -1
  57. package/apps/web/.next/standalone/apps/web/.next/server/app/api/integrations/[id]/toggle/route_client-reference-manifest.js +1 -1
  58. package/apps/web/.next/standalone/apps/web/.next/server/app/api/integrations/repair/route_client-reference-manifest.js +1 -1
  59. package/apps/web/.next/standalone/apps/web/.next/server/app/api/integrations/route_client-reference-manifest.js +1 -1
  60. package/apps/web/.next/standalone/apps/web/.next/server/app/api/memories/route_client-reference-manifest.js +1 -1
  61. package/apps/web/.next/standalone/apps/web/.next/server/app/api/onboarding/connections/route.js +1 -1
  62. package/apps/web/.next/standalone/apps/web/.next/server/app/api/onboarding/connections/route_client-reference-manifest.js +1 -1
  63. package/apps/web/.next/standalone/apps/web/.next/server/app/api/onboarding/dench-cloud/route.js +1 -1
  64. package/apps/web/.next/standalone/apps/web/.next/server/app/api/onboarding/dench-cloud/route_client-reference-manifest.js +1 -1
  65. package/apps/web/.next/standalone/apps/web/.next/server/app/api/onboarding/identity/route.js +1 -1
  66. package/apps/web/.next/standalone/apps/web/.next/server/app/api/onboarding/identity/route_client-reference-manifest.js +1 -1
  67. package/apps/web/.next/standalone/apps/web/.next/server/app/api/onboarding/state/route.js +1 -1
  68. package/apps/web/.next/standalone/apps/web/.next/server/app/api/onboarding/state/route_client-reference-manifest.js +1 -1
  69. package/apps/web/.next/standalone/apps/web/.next/server/app/api/onboarding/sync/progress/route_client-reference-manifest.js +1 -1
  70. package/apps/web/.next/standalone/apps/web/.next/server/app/api/onboarding/sync/start/route.js +1 -1
  71. package/apps/web/.next/standalone/apps/web/.next/server/app/api/onboarding/sync/start/route_client-reference-manifest.js +1 -1
  72. package/apps/web/.next/standalone/apps/web/.next/server/app/api/profiles/route_client-reference-manifest.js +1 -1
  73. package/apps/web/.next/standalone/apps/web/.next/server/app/api/profiles/switch/route_client-reference-manifest.js +1 -1
  74. package/apps/web/.next/standalone/apps/web/.next/server/app/api/sessions/[sessionId]/route_client-reference-manifest.js +1 -1
  75. package/apps/web/.next/standalone/apps/web/.next/server/app/api/sessions/route_client-reference-manifest.js +1 -1
  76. package/apps/web/.next/standalone/apps/web/.next/server/app/api/settings/cloud/route.js +1 -1
  77. package/apps/web/.next/standalone/apps/web/.next/server/app/api/settings/cloud/route_client-reference-manifest.js +1 -1
  78. package/apps/web/.next/standalone/apps/web/.next/server/app/api/settings/mcp/connect/callback/route_client-reference-manifest.js +1 -1
  79. package/apps/web/.next/standalone/apps/web/.next/server/app/api/settings/mcp/connect/start/route_client-reference-manifest.js +1 -1
  80. package/apps/web/.next/standalone/apps/web/.next/server/app/api/settings/mcp/connect/token/route_client-reference-manifest.js +1 -1
  81. package/apps/web/.next/standalone/apps/web/.next/server/app/api/settings/mcp/probe/route_client-reference-manifest.js +1 -1
  82. package/apps/web/.next/standalone/apps/web/.next/server/app/api/settings/mcp/route_client-reference-manifest.js +1 -1
  83. package/apps/web/.next/standalone/apps/web/.next/server/app/api/skills/[slug]/content/route_client-reference-manifest.js +1 -1
  84. package/apps/web/.next/standalone/apps/web/.next/server/app/api/skills/[slug]/route_client-reference-manifest.js +1 -1
  85. package/apps/web/.next/standalone/apps/web/.next/server/app/api/skills/browse/route_client-reference-manifest.js +1 -1
  86. package/apps/web/.next/standalone/apps/web/.next/server/app/api/skills/install/route_client-reference-manifest.js +1 -1
  87. package/apps/web/.next/standalone/apps/web/.next/server/app/api/skills/route_client-reference-manifest.js +1 -1
  88. package/apps/web/.next/standalone/apps/web/.next/server/app/api/sync/poll-tick/route_client-reference-manifest.js +1 -1
  89. package/apps/web/.next/standalone/apps/web/.next/server/app/api/sync/refresh/route_client-reference-manifest.js +1 -1
  90. package/apps/web/.next/standalone/apps/web/.next/server/app/api/sync/status/route_client-reference-manifest.js +1 -1
  91. package/apps/web/.next/standalone/apps/web/.next/server/app/api/terminal/port/route_client-reference-manifest.js +1 -1
  92. package/apps/web/.next/standalone/apps/web/.next/server/app/api/voice/speech/route.js +1 -1
  93. package/apps/web/.next/standalone/apps/web/.next/server/app/api/voice/speech/route_client-reference-manifest.js +1 -1
  94. package/apps/web/.next/standalone/apps/web/.next/server/app/api/voice/transcribe/route.js +1 -1
  95. package/apps/web/.next/standalone/apps/web/.next/server/app/api/voice/transcribe/route_client-reference-manifest.js +1 -1
  96. package/apps/web/.next/standalone/apps/web/.next/server/app/api/voice/voices/route.js +1 -1
  97. package/apps/web/.next/standalone/apps/web/.next/server/app/api/voice/voices/route_client-reference-manifest.js +1 -1
  98. package/apps/web/.next/standalone/apps/web/.next/server/app/api/web-sessions/[id]/messages/route_client-reference-manifest.js +1 -1
  99. package/apps/web/.next/standalone/apps/web/.next/server/app/api/web-sessions/[id]/route_client-reference-manifest.js +1 -1
  100. package/apps/web/.next/standalone/apps/web/.next/server/app/api/web-sessions/route.js +1 -1
  101. package/apps/web/.next/standalone/apps/web/.next/server/app/api/web-sessions/route_client-reference-manifest.js +1 -1
  102. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/assets/[...path]/route_client-reference-manifest.js +1 -1
  103. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/browse/route_client-reference-manifest.js +1 -1
  104. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/browse-file/route_client-reference-manifest.js +1 -1
  105. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/context/route_client-reference-manifest.js +1 -1
  106. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/copy/route_client-reference-manifest.js +1 -1
  107. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/db/introspect/route_client-reference-manifest.js +1 -1
  108. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/db/query/route_client-reference-manifest.js +1 -1
  109. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/delete/route.js +1 -1
  110. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/delete/route_client-reference-manifest.js +1 -1
  111. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/enrichment-status/route_client-reference-manifest.js +1 -1
  112. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/execute/route_client-reference-manifest.js +1 -1
  113. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/file/route.js +1 -1
  114. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/file/route_client-reference-manifest.js +1 -1
  115. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/init/route.js +1 -1
  116. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/init/route_client-reference-manifest.js +1 -1
  117. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/link-preview/route_client-reference-manifest.js +1 -1
  118. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/list/route_client-reference-manifest.js +1 -1
  119. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/mkdir/route_client-reference-manifest.js +1 -1
  120. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/move/route_client-reference-manifest.js +1 -1
  121. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/actions/route_client-reference-manifest.js +1 -1
  122. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/actions/runs/route_client-reference-manifest.js +1 -1
  123. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/display-field/route_client-reference-manifest.js +1 -1
  124. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/enrich/route.js +7 -7
  125. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/enrich/route_client-reference-manifest.js +1 -1
  126. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/entries/[id]/content/route_client-reference-manifest.js +1 -1
  127. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/entries/[id]/route_client-reference-manifest.js +1 -1
  128. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/entries/bulk-delete/route_client-reference-manifest.js +1 -1
  129. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/entries/options/route_client-reference-manifest.js +1 -1
  130. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/entries/route.js +1 -1
  131. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/entries/route_client-reference-manifest.js +1 -1
  132. 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
  133. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/fields/[fieldId]/route_client-reference-manifest.js +1 -1
  134. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/fields/reorder/route_client-reference-manifest.js +1 -1
  135. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/fields/route_client-reference-manifest.js +1 -1
  136. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/icon/route_client-reference-manifest.js +1 -1
  137. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/route_client-reference-manifest.js +1 -1
  138. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/views/route_client-reference-manifest.js +1 -1
  139. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/route_client-reference-manifest.js +1 -1
  140. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/open-file/route_client-reference-manifest.js +1 -1
  141. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/path-info/route_client-reference-manifest.js +1 -1
  142. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/query/route_client-reference-manifest.js +1 -1
  143. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/raw-file/route_client-reference-manifest.js +1 -1
  144. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/rename/route_client-reference-manifest.js +1 -1
  145. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/reports/execute/route.js +1 -1
  146. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/reports/execute/route_client-reference-manifest.js +1 -1
  147. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/search-index/route_client-reference-manifest.js +1 -1
  148. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/suggest-files/route_client-reference-manifest.js +1 -1
  149. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/switch/route.js +1 -1
  150. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/switch/route_client-reference-manifest.js +1 -1
  151. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/thumbnail/route_client-reference-manifest.js +1 -1
  152. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/tree/route.js +6 -1
  153. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/tree/route_client-reference-manifest.js +1 -1
  154. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/upload/route.js +1 -1
  155. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/upload/route_client-reference-manifest.js +1 -1
  156. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/virtual-file/route_client-reference-manifest.js +1 -1
  157. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/watch/route_client-reference-manifest.js +1 -1
  158. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/write-binary/route_client-reference-manifest.js +1 -1
  159. package/apps/web/.next/standalone/apps/web/.next/server/app/onboarding/page.js +3 -3
  160. package/apps/web/.next/standalone/apps/web/.next/server/app/onboarding/page_client-reference-manifest.js +1 -1
  161. package/apps/web/.next/standalone/apps/web/.next/server/app/page.js +63 -63
  162. package/apps/web/.next/standalone/apps/web/.next/server/app/page_client-reference-manifest.js +1 -1
  163. package/apps/web/.next/standalone/apps/web/.next/server/app/workspace/page_client-reference-manifest.js +1 -1
  164. package/apps/web/.next/standalone/apps/web/.next/server/app-paths-manifest.json +49 -49
  165. package/apps/web/.next/standalone/apps/web/.next/server/chunks/27488.js +1 -1
  166. package/apps/web/.next/standalone/apps/web/.next/server/chunks/44877.js +1 -1
  167. package/apps/web/.next/standalone/apps/web/.next/server/chunks/6787.js +1 -1
  168. package/apps/web/.next/standalone/apps/web/.next/server/chunks/86796.js +1 -1
  169. package/apps/web/.next/standalone/apps/web/.next/server/chunks/93349.js +1 -1
  170. package/apps/web/.next/standalone/apps/web/.next/server/functions-config-manifest.json +20 -20
  171. package/apps/web/.next/standalone/apps/web/.next/server/middleware-build-manifest.js +1 -1
  172. package/apps/web/.next/standalone/apps/web/.next/server/middleware-react-loadable-manifest.js +1 -1
  173. package/apps/web/.next/standalone/apps/web/.next/server/pages/500.html +1 -1
  174. package/apps/web/.next/standalone/apps/web/.next/server/server-reference-manifest.json +1 -1
  175. package/apps/web/.next/{static/chunks/42368-5b62eb1fbad248e6.js → standalone/apps/web/.next/static/chunks/42368-2351626c2a79f605.js} +1 -1
  176. package/apps/web/.next/{static/chunks/63228.ecfdd111ba7f1528.js → standalone/apps/web/.next/static/chunks/63228.a9cd6a7ef5349953.js} +1 -1
  177. package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/{layout-3e4e00e9ca429710.js → layout-1593fe8efa94d5d8.js} +1 -1
  178. package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/onboarding/page-30326ac19cf2ce87.js +1 -0
  179. package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/page-e98634d56d0b3903.js +1 -0
  180. package/apps/web/.next/standalone/apps/web/.next/static/chunks/{webpack-e5fcf8af7026ed16.js → webpack-8c669cd60da27349.js} +1 -1
  181. package/apps/web/.next/standalone/apps/web/server.js +1 -1
  182. package/apps/web/.next/standalone/extensions/apollo-enrichment/index.test.ts +121 -28
  183. package/apps/web/.next/standalone/extensions/apollo-enrichment/index.ts +51 -8
  184. package/apps/web/.next/standalone/extensions/dench-ai-gateway/models.ts +1 -1
  185. package/apps/web/.next/standalone/extensions/posthog-analytics/lib/build-env.js +1 -1
  186. package/apps/web/.next/standalone/package.json +1 -1
  187. package/apps/web/.next/{standalone/apps/web/.next/static/chunks/42368-5b62eb1fbad248e6.js → static/chunks/42368-2351626c2a79f605.js} +1 -1
  188. package/apps/web/.next/{standalone/apps/web/.next/static/chunks/63228.ecfdd111ba7f1528.js → static/chunks/63228.a9cd6a7ef5349953.js} +1 -1
  189. package/apps/web/.next/static/chunks/app/{layout-3e4e00e9ca429710.js → layout-1593fe8efa94d5d8.js} +1 -1
  190. package/apps/web/.next/static/chunks/app/onboarding/page-30326ac19cf2ce87.js +1 -0
  191. package/apps/web/.next/static/chunks/app/page-e98634d56d0b3903.js +1 -0
  192. package/apps/web/.next/static/chunks/{webpack-e5fcf8af7026ed16.js → webpack-8c669cd60da27349.js} +1 -1
  193. package/assets/seed/workspace.duckdb +0 -0
  194. package/dist/entry.js +1 -1
  195. package/dist/{program-CX_f4ysH.js → program-JflTwsUD.js} +1 -1
  196. package/dist/{run-main-RQeyyBrT.js → run-main-Db7zNm4h.js} +1 -1
  197. package/extensions/apollo-enrichment/index.test.ts +121 -28
  198. package/extensions/apollo-enrichment/index.ts +51 -8
  199. package/extensions/dench-ai-gateway/models.ts +1 -1
  200. package/extensions/posthog-analytics/lib/build-env.js +1 -1
  201. package/package.json +1 -1
  202. package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/onboarding/page-39ffff251e8b2d87.js +0 -1
  203. package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/page-3f9ce19396952dc1.js +0 -1
  204. package/apps/web/.next/static/chunks/app/onboarding/page-39ffff251e8b2d87.js +0 -1
  205. package/apps/web/.next/static/chunks/app/page-3f9ce19396952dc1.js +0 -1
  206. /package/apps/web/.next/standalone/apps/web/.next/static/{Bt_OkvizcbEBAFmp82HK0 → tXOdT0964sqzfxZm_X_3S}/_buildManifest.js +0 -0
  207. /package/apps/web/.next/standalone/apps/web/.next/static/{Bt_OkvizcbEBAFmp82HK0 → tXOdT0964sqzfxZm_X_3S}/_ssgManifest.js +0 -0
  208. /package/apps/web/.next/static/{Bt_OkvizcbEBAFmp82HK0 → tXOdT0964sqzfxZm_X_3S}/_buildManifest.js +0 -0
  209. /package/apps/web/.next/static/{Bt_OkvizcbEBAFmp82HK0 → tXOdT0964sqzfxZm_X_3S}/_ssgManifest.js +0 -0
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[58974],{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=(0,o.useMemo)(()=>{var e;return null!=(e=l.Mb[t])?e:l.Mb.braille},[t]),u=d.frames.length,p=u>0?d.frames[i%u]:"";return(0,o.useEffect)(()=>{if(c(0),u<=1||d.interval<=0)return;let e=window.setInterval(()=>c(e=>(e+1)%u),d.interval);return()=>window.clearInterval(e)},[d,u]),(0,n.jsxs)("span",{className:a,style:{fontFamily:"monospace",...s},children:[p,null!=r&&(0,n.jsxs)(n.Fragment,{children:[" ",r]})]})}},4582:()=>{},8509:(e,t,r)=>{"use strict";r.d(t,{A3:()=>p,PV:()=>u});let n=new Set(["vc","yc","ipo","kpi","kyc","roi","mrr","arr","ai","ml","llm","nlp","api","sdk","url","uri","uuid","ios","css","html","json","yaml","sql","b2b","b2c","saas","iaas","paas","ceo","cto","cfo","coo","cmo","cro","vp","sdr","bdr","ae","am","csm","crm","erp","hr","pr","it","ip","id","qa","qc","ux","ui","sla","nda","msa","us","uk","eu","uae","usa"]),o=new Map([["person","people"],["man","men"],["woman","women"],["child","children"],["mouse","mice"],["goose","geese"],["foot","feet"],["tooth","teeth"],["datum","data"],["criterion","criteria"],["phenomenon","phenomena"],["leaf","leaves"],["life","lives"],["wife","wives"],["knife","knives"]]),l=new Map(Array.from(o.entries(),e=>{let[t,r]=e;return[r,t]})),a=new Set(["address","process","status","lens","series","species","news","analysis","basis","thesis","axis","business","boss","class","glass","miss","pass"]);function s(e){let t=(null!=e?e:"").trim();return t?t.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").replace(/[_\-\s]+/g," ").trim().toLowerCase().split(" ").filter(Boolean):[]}function i(e){return e?n.has(e)?e.toUpperCase():e.charAt(0).toUpperCase()+e.slice(1):""}function c(e){return!!e&&(!!l.has(e)||!a.has(e)&&!!(e.endsWith("ies")||e.endsWith("ses")||e.endsWith("xes")||e.endsWith("zes")||e.endsWith("ches")||e.endsWith("shes")||e.endsWith("s")&&e.length>2&&!e.endsWith("ss")))}function d(e){if(!e)return e;let t=l.get(e);return t||(a.has(e)?e:e.endsWith("ies")&&e.length>3?"".concat(e.slice(0,-3),"y"):e.endsWith("sses")||(e.endsWith("ches")||e.endsWith("shes")||e.endsWith("xes")||e.endsWith("zes"))&&e.length>3?e.slice(0,-2):e.endsWith("s")&&!e.endsWith("ss")&&e.length>2?e.slice(0,-1):e)}function u(e){let t=s(e);if(0===t.length)return null!=e?e:"";let r=t.length-1;return t.map((e,t)=>t===r?function(e){if(!e)return"";if(n.has(e))return"".concat(e.toUpperCase(),"s");if(c(e)){let t=d(e);if(n.has(t)){let r=e.slice(t.length);return"".concat(t.toUpperCase()).concat(r)}return i(e)}let t=function(e){if(!e||c(e))return e;let t=o.get(e);return t||(/(s|x|z|ch|sh)$/.test(e)?"".concat(e,"es"):/[^aeiou]y$/.test(e)?"".concat(e.slice(0,-1),"ies"):"".concat(e,"s"))}(e);return t.charAt(0).toUpperCase()+t.slice(1)}(e):i(e)).join(" ")}function p(e){let t=s(e);if(0===t.length)return null!=e?e:"";let r=t.length-1;return t.map((e,t)=>t===r?function(e){if(!e)return"";if(n.has(e))return e.toUpperCase();let t=d(e);return n.has(t)?t.toUpperCase():i(t)}(e):i(e)).join(" ")}},10610:(e,t,r)=>{Promise.resolve().then(r.bind(r,61239))},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),p=r(3224),h=r(13707),m=r(23173),x=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),T=r(13847),L=r(49166);let I=["#2563eb","#60a5fa","#22c55e","#f59e0b","#c084fc","#fb923c","#14b8a6","#f43f5e","#a78bfa","#38bdf8"],_={fontSize:11,fill:"var(--color-text-muted)"},R={stroke:"var(--color-border-strong)",strokeDasharray:"3 3"};function E(){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 D(e){return null==e?"":"object"==typeof e?JSON.stringify(e):"string"==typeof e?e:String(e)}function A(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):D(e)}function F(e){if(null==e)return"";let t=D(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,m,x,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!=(x=w.yAxis)?x:Object.keys(null!=(m=g[0])?m:{}).filter(e=>e!==N),S=null!=(f=w.colors)?f:I,M=E();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:_,tickFormatter:F,axisLine:{stroke:"var(--color-border)"},tickLine:!1}),(0,n.jsx)(i.h,{tick:_,tickFormatter:A,axisLine:!1,tickLine:!1,width:48}),(0,n.jsx)(c.m,{...M,formatter:A,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===p.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 B(e){var t,r,o,a,s,i,u;let{config:p,data:h,compact:v}=e,{mapping:g,type:y}=p,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:I,w=E();return(0,n.jsx)(l.u,{width:"100%",height:v?200:320,children:(0,n.jsxs)(m.r,{children:[(0,n.jsx)(x.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:A}),!v&&(0,n.jsx)(d.s,{wrapperStyle:{fontSize:11}})]})})}function W(e){var t,r,o,a,s,i,u,p;let{config:h,data:m,compact:x}=e,{mapping:f}=h,k=null!=(a=null!=(o=null!=(t=f.xAxis)?t:f.nameKey)?o:Object.keys(null!=(r=m[0])?r:{})[0])?a:"name",w=null!=(u=f.yAxis)?u:[null!=(i=Object.keys(null!=(s=m[0])?s:{})[1])?i:"value"],N=null!=(p=f.colors)?p:I,C=E();return(0,n.jsx)(l.u,{width:"100%",height:x?200:320,children:(0,n.jsxs)(v.V,{data:m,cx:"50%",cy:"50%",outerRadius:x?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}),!x&&w.length>1&&(0,n.jsx)(d.s,{wrapperStyle:{fontSize:11}})]})})}function O(e){var t,r,o,u,p,h,m;let{config:x,data:f,compact:v}=e,{mapping:g}=x,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!=(p=Object.keys(null!=(u=f[0])?u:{})[1])?p:"y"],j=null!=(m=g.colors)?m:I,N=E();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:_,name:y,axisLine:{stroke:"var(--color-border)"},tickLine:!1}),(0,n.jsx)(i.h,{tick:_,tickFormatter:A,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 z(e){var t,r,o,a,s,i,d;let{config:u,data:p,compact:h}=e,{mapping:m}=u,x=null!=(o=null!=(r=m.nameKey)?r:Object.keys(null!=(t=p[0])?t:{})[0])?o:"name",f=null!=(i=null!=(s=m.valueKey)?s:Object.keys(null!=(a=p[0])?a:{})[1])?i:"value",v=null!=(d=m.colors)?d:I,g=E(),y=p.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:x,isAnimationActive:!0,children:(0,n.jsx)(S.Ze,{position:"right",fill:"var(--color-text-muted)",stroke:"none",fontSize:11,dataKey:x})})]})})}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:T.b,SeriesComponent:p.N1});case"area":return(0,n.jsx)(P,{config:t,data:a,compact:l,ChartComponent:L.Q,SeriesComponent:h.Gk});case"pie":case"donut":return(0,n.jsx)(B,{config:t,data:a,compact:l});case"radar":case"radialBar":return(0,n.jsx)(W,{config:t,data:a,compact:l});case"scatter":return(0,n.jsx)(O,{config:t,data:a,compact:l});case"funnel":return(0,n.jsx)(z,{config:t,data:a,compact:l})}}},52597:(e,t,r)=>{"use strict";r.r(t),r.d(t,{BubbleButton:()=>J.zM,MarkdownEditor:()=>$,ToolbarButton:()=>J.IB,ToolbarDivider:()=>J.x_,ToolbarGroup:()=>J.$Q});var n=r(80534),o=r(69176),l=r(87131),a=r(22856),s=r(64652),i=r(3087),c=r(86233),d=r(79919),u=r(34872),p=r(8466),h=r(83879),m=r(14273),x=r(54602),f=r(95107),v=r(74166),g=r(79534);let y=(0,r(24946).default)(()=>r.e(45477).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",style:{background:"var(--color-surface)"}})});function b(e){let{node:t,updateAttributes:r,deleteNode:l,selected:a}=e,s=t.attrs.config,[i,c]=(0,v.useState)(!1),[d,u]=(0,v.useState)(s),p=null,h=null;try{let e=JSON.parse(s);(null==e?void 0:e.panels)&&Array.isArray(e.panels)?p=e:h="Invalid report config: missing panels array"}catch(e){h="Invalid JSON in report block"}let m=(0,v.useCallback)(()=>{try{JSON.parse(d),r({config:d}),c(!1)}catch(e){}},[d,r]);return(0,n.jsxs)(o.VR,{className:"report-block-wrapper","data-selected":a||void 0,children:[(0,n.jsxs)("div",{className:"report-block-toolbar",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{i?m():(u(s),c(!0))},className:"report-block-btn",title:i?"Apply & show chart":"Edit JSON source",children:[i?(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)("polyline",{points:"20 6 9 17 4 12"})}):(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"})]}),(0,n.jsx)("span",{children:i?"Apply":"Edit JSON"})]}),(0,n.jsx)("button",{type:"button",onClick:l,className:"report-block-btn report-block-btn-danger",title:"Remove report block",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:"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"})]})})]}),i?(0,n.jsxs)("div",{className:"report-block-source",children:[(0,n.jsx)("div",{className:"report-block-source-label",children:"report-json"}),(0,n.jsx)("textarea",{className:"report-block-textarea",value:d,onChange:e=>u(e.target.value),spellCheck:!1,rows:Math.min(20,d.split("\n").length+2)})]}):h?(0,n.jsxs)("div",{className:"report-block-error",children:[(0,n.jsx)("span",{children:h}),(0,n.jsx)("button",{type:"button",onClick:()=>{u(s),c(!0)},className:"report-block-btn",children:"Fix JSON"})]}):(0,n.jsx)(y,{config:p})]})}let j=g.bP.create({name:"reportBlock",group:"block",atom:!0,addAttributes:()=>({config:{default:"{}",parseHTML:e=>e.getAttribute("data-config")||"{}",renderHTML:e=>({"data-config":e.config})}}),parseHTML:()=>[{tag:'div[data-type="report-block"]'}],renderHTML(e){let{HTMLAttributes:t}=e;return["div",(0,g.KV)(t,{"data-type":"report-block"})]},addNodeView:()=>(0,o.gu)(b)});function k(e){return e.replace(/```report-json\s*\n([\s\S]*?)```/g,(e,t)=>{let r=t.trim().replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;");return'<div data-type="report-block" data-config="'.concat(r,'"></div>')})}var w=r(48997),N=r(63550),C=r(17763),S=r(68840),M=r(8509);let T=new N.hs("slashCommand"),L=new N.hs("fileMention"),I=e=>(0,n.jsxs)("span",{className:"slash-cmd-icon-text",children:["H",e]}),_=(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"})]}),R=(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"})]}),E=(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"})]}),D=(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"})]}),A=(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"})}),F=(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"})]}),P=(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"})]}),B=(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"})]}),W=(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:"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"})]}),O=(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:"M16 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V8Z"}),(0,n.jsx)("path",{d:"M15 3v4a2 2 0 0 0 2 2h4"}),(0,n.jsx)("path",{d:"M10 16h4"}),(0,n.jsx)("path",{d:"M10 12h4"})]});function z(e){var t;if("entry"===e.kind){let t=e.label||"(".concat(e.objectName," entry)"),r=e.objectName?(0,M.A3)(e.objectName):"";return{title:e.label||(e.objectName?"(".concat(r," entry)"):t),description:e.fields?Object.entries(e.fields).slice(0,2).map(e=>{let[t,r]=e;return"".concat(t,": ").concat(r)}).join(" | "):void 0,badge:r||e.objectName,icon:O,category:"entry",command:r=>{let{editor:n,range:o}=r,l=(0,S.VE)(e.objectName,e.entryId);n.chain().focus().deleteRange(o).insertContent({type:"text",text:t,marks:[{type:"link",attrs:{href:l,target:null}}]}).run()}}}let r=null!=(t=e.nodeType)?t:"object"===e.kind?"object":"file",o=e.label||e.path||e.id;return{title:"object"===e.kind?(0,M.PV)(o):o,description:e.sublabel,icon:function(e){switch(e){case"document":default: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"})]});case"object":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"})]});case"report":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:"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"})]})}}(r),category:"file",command:t=>{var r;let{editor:n,range:l}=t,a=(0,S.bJ)(null!=(r=e.path)?r:e.id);n.chain().focus().deleteRange(l).insertContent({type:"text",text:o,marks:[{type:"link",attrs:{href:a,target:null}}]}).run()}}}let U=(0,v.forwardRef)((e,t)=>{let{items:r,command:o}=e,[l,a]=(0,v.useState)(0),s=(0,v.useRef)(null);(0,v.useEffect)(()=>{a(0)},[r]),(0,v.useEffect)(()=>{var e;let t=null==(e=s.current)?void 0:e.children[l];null==t||t.scrollIntoView({block:"nearest"})},[l]);let i=(0,v.useCallback)(e=>{let t=r[e];t&&o(t)},[r,o]);return((0,v.useImperativeHandle)(t,()=>({onKeyDown:e=>{let{event:t}=e;return"ArrowUp"===t.key?(a(e=>(e+r.length-1)%r.length),!0):"ArrowDown"===t.key?(a(e=>(e+1)%r.length),!0):"Enter"===t.key&&(i(l),!0)}})),0===r.length)?(0,n.jsx)("div",{className:"slash-cmd-popup",children:(0,n.jsx)("div",{className:"slash-cmd-empty",children:"No results"})}):(0,n.jsx)("div",{className:"slash-cmd-popup",ref:s,children:r.map((e,t)=>(0,n.jsxs)("button",{type:"button",className:"slash-cmd-item ".concat(t===l?"slash-cmd-item-active":""),onClick:()=>i(t),onMouseEnter:()=>a(t),children:[(0,n.jsx)("span",{className:"slash-cmd-item-icon",children:e.icon}),(0,n.jsxs)("span",{className:"slash-cmd-item-body",children:[(0,n.jsxs)("span",{className:"slash-cmd-item-title",children:[e.title,e.badge&&(0,n.jsx)("span",{className:"slash-cmd-item-badge",children:e.badge})]}),e.description&&(0,n.jsx)("span",{className:"slash-cmd-item-desc",children:e.description})]})]},"".concat(e.category,"-").concat(e.title,"-").concat(t)))})});function H(e){let{items:t,command:r,clientRect:o,componentRef:l}=e,a=(0,v.useRef)(null);return(0,v.useLayoutEffect)(()=>{if(!a.current||!o)return;let e=o();if(!e)return;let t=a.current;t.style.position="fixed",t.style.left="".concat(e.left,"px"),t.style.top="".concat(e.bottom+4,"px"),t.style.zIndex="50"},[o,t]),(0,C.createPortal)((0,n.jsx)("div",{ref:a,children:(0,n.jsx)(U,{ref:l,items:t,command:r})}),document.body)}function V(){return()=>{let e=null,t=null,o={current:null};return{onStart:l=>{e=document.createElement("div"),document.body.appendChild(e),Promise.resolve().then(r.t.bind(r,80282,19)).then(r=>{let{createRoot:a}=r;(t=a(e)).render((0,n.jsx)(H,{items:l.items,command:l.command,clientRect:l.clientRect,componentRef:o}))})},onUpdate:e=>{null==t||t.render((0,n.jsx)(H,{items:e.items,command:e.command,clientRect:e.clientRect,componentRef:o}))},onKeyDown:r=>{var n,l;return"Escape"===r.event.key?(null==t||t.unmount(),null==e||e.remove(),e=null,t=null,!0):null!=(l=null==(n=o.current)?void 0:n.onKeyDown(r))&&l},onExit:()=>{null==t||t.unmount(),null==e||e.remove(),e=null,t=null}}}}function K(e){return g.YY.create({name:"fileMention",addOptions:()=>({suggestion:{char:"@",pluginKey:L,startOfLine:!1,command:e=>{let{editor:t,range:r,props:n}=e;n.command({editor:t,range:r})},items:t=>{let{query:r}=t;return e(r,15).map(z)},render:V()}}),addProseMirrorPlugins(){return[(0,w.Ay)({editor:this.editor,...this.options.suggestion})]}})}U.displayName="CommandList";var J=r(77704),q=r(90425);function G(e){let t=e.match(/^(---\s*\n[\s\S]*?\n---\s*\n)/);return t?t[1]:""}function $(e){var t;let{content:r,rawContent:y,filePath:b,tree:N,onSave:C,onDirty:M,onNavigate:L,searchFn:O}=e,[z,U]=(0,v.useState)(!1),[H,$]=(0,v.useState)("idle"),[Z,Q]=(0,v.useState)(!1),X=(0,v.useRef)(r),ee=(0,v.useRef)(null),et=(0,v.useRef)(G(null!=y?y:"")),er=(0,v.useMemo)(()=>(function(){let e=[{title:"Heading 1",description:"Large section heading",icon:I(1),category:"block",command:e=>{let{editor:t,range:r}=e;t.chain().focus().deleteRange(r).setNode("heading",{level:1}).run()}},{title:"Heading 2",description:"Medium section heading",icon:I(2),category:"block",command:e=>{let{editor:t,range:r}=e;t.chain().focus().deleteRange(r).setNode("heading",{level:2}).run()}},{title:"Heading 3",description:"Small section heading",icon:I(3),category:"block",command:e=>{let{editor:t,range:r}=e;t.chain().focus().deleteRange(r).setNode("heading",{level:3}).run()}},{title:"Bullet List",description:"Unordered list",icon:_,category:"block",command:e=>{let{editor:t,range:r}=e;t.chain().focus().deleteRange(r).toggleBulletList().run()}},{title:"Numbered List",description:"Ordered list",icon:R,category:"block",command:e=>{let{editor:t,range:r}=e;t.chain().focus().deleteRange(r).toggleOrderedList().run()}},{title:"Task List",description:"Checklist with checkboxes",icon:B,category:"block",command:e=>{let{editor:t,range:r}=e;t.chain().focus().deleteRange(r).toggleTaskList().run()}},{title:"Blockquote",description:"Quote block",icon:E,category:"block",command:e=>{let{editor:t,range:r}=e;t.chain().focus().deleteRange(r).toggleBlockquote().run()}},{title:"Code Block",description:"Fenced code block",icon:D,category:"block",command:e=>{let{editor:t,range:r}=e;t.chain().focus().deleteRange(r).toggleCodeBlock().run()}},{title:"Horizontal Rule",description:"Divider line",icon:A,category:"block",command:e=>{let{editor:t,range:r}=e;t.chain().focus().deleteRange(r).setHorizontalRule().run()}},{title:"Image",description:"Insert image from URL",icon:F,category:"block",command:e=>{let{editor:t,range:r}=e,n=window.prompt("Image URL:");n&&t.chain().focus().deleteRange(r).setImage({src:n}).run()}},{title:"Table",description:"Insert a 3x3 table",icon:P,category:"block",command:e=>{let{editor:t,range:r}=e;t.chain().focus().deleteRange(r).insertTable({rows:3,cols:3,withHeaderRow:!0}).run()}},{title:"Report Chart",description:"Interactive report-json block",icon:W,category:"block",command:e=>{let{editor:t,range:r}=e,n=JSON.stringify({version:1,title:"New Report",panels:[{id:"panel-1",title:"Chart",type:"bar",sql:"SELECT 1 as x, 10 as y",mapping:{xAxis:"x",yAxis:["y"]}}]},null,2);t.chain().focus().deleteRange(r).insertContent({type:"reportBlock",attrs:{config:n}}).run()}}];return g.YY.create({name:"slashCommand",addOptions:()=>({suggestion:{char:"/",pluginKey:T,startOfLine:!1,command:e=>{let{editor:t,range:r,props:n}=e;n.command({editor:t,range:r})},items:t=>{let{query:r}=t,n=r.toLowerCase();return n?e.filter(e=>{var t,r;return e.title.toLowerCase().includes(n)||null!=(r=null==(t=e.description)?void 0:t.toLowerCase().includes(n))&&r}):e},render:V()}}),addProseMirrorPlugins(){return[(0,w.Ay)({editor:this.editor,...this.options.suggestion})]}})})(),[]),en=(0,v.useMemo)(()=>O?K(O):function(e){let t=(function e(t){let r=[];for(let n of t)"folder"!==n.type&&r.push(n),n.children&&r.push(...e(n.children));return r})(e).map(e=>({id:e.path,label:e.name.replace(/\.md$/,""),sublabel:e.path,kind:"object"===e.type?"object":"file",path:e.path,nodeType:e.type}));return K(function(e){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:15;if(!e)return t.slice(0,r);let n=e.toLowerCase();return t.filter(e=>{var t,r;return e.label.toLowerCase().includes(n)||null!=(r=null==(t=e.sublabel)?void 0:t.toLowerCase().includes(n))&&r}).slice(0,r)})}(N),[O,N]),eo=(0,o.hG)({extensions:[a.A.configure({codeBlock:{HTMLAttributes:{class:"code-block"}}}),s.oz.configure({markedOptions:{gfm:!0}}),i.Ay.configure({inline:!1,allowBase64:!0,HTMLAttributes:{class:"editor-image"}}),c.Ay.configure({openOnClick:!1,autolink:!0,HTMLAttributes:{class:"editor-link",rel:"noopener"}}),d.XI.configure({resizable:!1}),u.A,p.A,h.h,m.A,x.A.configure({nested:!0}),f.A.configure({placeholder:"Start writing, or type / for commands..."}),j,er,en],content:k(r),contentType:"markdown",immediatelyRender:!1,onUpdate:()=>{Q(!0),$("idle"),null==M||M()}}),el=(0,v.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}},[]),ea=(0,v.useCallback)(async e=>{if(eo)for(let t of e){let e=await el(t);e&&eo.chain().focus().setImage({src:e,alt:t.name}).run()}},[eo,el]);(0,v.useEffect)(()=>{if(!eo)return;let e=eo.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(),ea(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/"));if(t.length>0){e.preventDefault(),e.stopPropagation(),ea(t);return}let r=e.clipboardData.getData("text/plain");if(r&&(r.startsWith("file://")||/^(\/|~\/|[A-Z]:\\).*\.(png|jpe?g|gif|webp|svg|bmp|ico)$/i.test(r.trim()))){e.preventDefault(),e.stopPropagation();let t=r.trim().replace(/^file:\/\//,"");null==eo||eo.chain().focus().setImage({src:t}).run()}};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)}},[eo,ea]),(0,v.useEffect)(()=>{if(!eo||!L)return;let e=e=>{let t=e.target.closest("a");if(!t)return;let r=t.getAttribute("href");if(r){if(r.startsWith("#")){var n;e.preventDefault(),e.stopPropagation();let t=r.slice(1),o=eo.view.dom,l=null!=(n=o.querySelector('[id="'.concat(CSS.escape(t),'"]')))?n:o.querySelector("h1, h2, h3, h4, h5, h6");if(l){let e=Array.from(o.querySelectorAll("h1, h2, h3, h4, h5, h6")).find(e=>(e.textContent||"").trim().toLowerCase().replace(/[^\w\s-]/g,"").replace(/\s+/g,"-")===t);(null!=e?e:l).scrollIntoView({behavior:"smooth",block:"start"})}return}if((0,S.m9)(r)||!r.startsWith("http://")&&!r.startsWith("https://")&&!r.startsWith("mailto:")){e.preventDefault(),e.stopPropagation(),L(r);return}e.preventDefault(),e.stopPropagation(),window.open(r,"_blank","noopener,noreferrer")}},t=eo.view.dom;return t.addEventListener("click",e,!0),()=>t.removeEventListener("click",e,!0)},[eo,L]);let es=(0,v.useCallback)(async()=>{if(eo&&!z){U(!0),$("idle");try{let e=("function"==typeof eo.getMarkdown?eo.getMarkdown():eo.getHTML()).replace(/<div data-type="report-block" data-config="([^"]*)">\s*<\/div>/g,(e,t)=>"```report-json\n"+t.replace(/&gt;/g,">").replace(/&lt;/g,"<").replace(/&quot;/g,'"').replace(/&amp;/g,"&")+"\n```"),t=et.current+e;(await fetch((0,q.nC)(b),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:b,content:t})})).ok?($("saved"),Q(!1),X.current=r,null==C||C(),ee.current&&clearTimeout(ee.current),ee.current=setTimeout(()=>$("idle"),2e3)):$("error")}catch(e){$("error")}finally{U(!1)}}},[eo,b,z,C]);return((0,v.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&(e.preventDefault(),es())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[es]),(0,v.useEffect)(()=>{if(eo&&!Z&&r!==X.current){X.current=r,et.current=G(null!=y?y:"");let e=k(r);eo.commands.setContent(e,{contentType:"markdown"}),Q(!1)}},[r,y,eo,Z]),eo)?(0,n.jsxs)("div",{className:"markdown-editor-container",children:[(0,n.jsxs)("div",{className:"editor-top-bar",children:[(0,n.jsxs)("div",{className:"editor-top-bar-left",children:[Z&&(0,n.jsx)("span",{className:"editor-save-indicator editor-save-unsaved",children:"Unsaved changes"}),"saved"===H&&!Z&&(0,n.jsx)("span",{className:"editor-save-indicator editor-save-saved",children:"Saved"}),"error"===H&&(0,n.jsx)("span",{className:"editor-save-indicator editor-save-error",children:"Save failed"})]}),(0,n.jsxs)("div",{className:"editor-top-bar-right",children:[(0,n.jsxs)("span",{className:"editor-save-hint",children:["undefined"!=typeof navigator&&(null==(t=navigator.platform)?void 0:t.includes("Mac"))?"⌘":"Ctrl","+S"]}),(0,n.jsx)("button",{type:"button",onClick:()=>void es(),disabled:z||!Z,className:"editor-save-button",children:z?"Saving...":"Save"})]})]}),(0,n.jsx)(Y,{editor:eo,onUploadImages:ea}),(0,n.jsx)(l.m,{editor:eo,children:(0,n.jsxs)("div",{className:"bubble-menu",children:[(0,n.jsx)(J.zM,{active:eo.isActive("bold"),onClick:()=>eo.chain().focus().toggleBold().run(),title:"Bold",children:(0,n.jsx)("strong",{children:"B"})}),(0,n.jsx)(J.zM,{active:eo.isActive("italic"),onClick:()=>eo.chain().focus().toggleItalic().run(),title:"Italic",children:(0,n.jsx)("em",{children:"I"})}),(0,n.jsx)(J.zM,{active:eo.isActive("strike"),onClick:()=>eo.chain().focus().toggleStrike().run(),title:"Strikethrough",children:(0,n.jsx)("s",{children:"S"})}),(0,n.jsx)(J.zM,{active:eo.isActive("code"),onClick:()=>eo.chain().focus().toggleCode().run(),title:"Inline code",children:"<>"}),(0,n.jsx)(J.zM,{active:eo.isActive("link"),onClick:()=>{if(eo.isActive("link"))eo.chain().focus().unsetLink().run();else{let e=window.prompt("URL:");e&&eo.chain().focus().setLink({href:e}).run()}},title:"Link",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:"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"})]})})]})}),(0,n.jsx)("div",{className:"editor-content-area workspace-prose",children:(0,n.jsx)(o.$Z,{editor:eo})})]}):(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 Y(e){let{editor:t,onUploadImages:r}=e,o=(0,v.useRef)(null);return t?(0,n.jsxs)("div",{className:"editor-toolbar",children:[(0,n.jsxs)(J.$Q,{children:[(0,n.jsx)(J.IB,{active:t.isActive("heading",{level:1}),onClick:()=>t.chain().focus().toggleHeading({level:1}).run(),title:"Heading 1",children:"H1"}),(0,n.jsx)(J.IB,{active:t.isActive("heading",{level:2}),onClick:()=>t.chain().focus().toggleHeading({level:2}).run(),title:"Heading 2",children:"H2"}),(0,n.jsx)(J.IB,{active:t.isActive("heading",{level:3}),onClick:()=>t.chain().focus().toggleHeading({level:3}).run(),title:"Heading 3",children:"H3"})]}),(0,n.jsx)(J.x_,{}),(0,n.jsxs)(J.$Q,{children:[(0,n.jsx)(J.IB,{active:t.isActive("bold"),onClick:()=>t.chain().focus().toggleBold().run(),title:"Bold",children:(0,n.jsx)("strong",{children:"B"})}),(0,n.jsx)(J.IB,{active:t.isActive("italic"),onClick:()=>t.chain().focus().toggleItalic().run(),title:"Italic",children:(0,n.jsx)("em",{children:"I"})}),(0,n.jsx)(J.IB,{active:t.isActive("strike"),onClick:()=>t.chain().focus().toggleStrike().run(),title:"Strikethrough",children:(0,n.jsx)("s",{children:"S"})}),(0,n.jsx)(J.IB,{active:t.isActive("code"),onClick:()=>t.chain().focus().toggleCode().run(),title:"Inline code",children:"<>"})]}),(0,n.jsx)(J.x_,{}),(0,n.jsxs)(J.$Q,{children:[(0,n.jsx)(J.IB,{active:t.isActive("bulletList"),onClick:()=>t.chain().focus().toggleBulletList().run(),title:"Bullet list",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)("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"})]})}),(0,n.jsx)(J.IB,{active:t.isActive("orderedList"),onClick:()=>t.chain().focus().toggleOrderedList().run(),title:"Ordered list",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)("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"})]})}),(0,n.jsx)(J.IB,{active:t.isActive("taskList"),onClick:()=>t.chain().focus().toggleTaskList().run(),title:"Task list",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:"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"})]})}),(0,n.jsx)(J.IB,{active:t.isActive("blockquote"),onClick:()=>t.chain().focus().toggleBlockquote().run(),title:"Blockquote",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 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"})]})}),(0,n.jsx)(J.IB,{active:t.isActive("codeBlock"),onClick:()=>t.chain().focus().toggleCodeBlock().run(),title:"Code block",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)("polyline",{points:"16 18 22 12 16 6"}),(0,n.jsx)("polyline",{points:"8 6 2 12 8 18"})]})})]}),(0,n.jsx)(J.x_,{}),(0,n.jsxs)(J.$Q,{children:[(0,n.jsx)(J.IB,{active:!1,onClick:()=>{let e=window.prompt("Link URL:");e&&t.chain().focus().setLink({href:e}).run()},title:"Insert link",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:"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"})]})}),(0,n.jsx)(J.IB,{active:!1,onClick:()=>{if(r){var e;null==(e=o.current)||e.click()}else{let e=window.prompt("Image URL:");e&&t.chain().focus().setImage({src:e}).run()}},title:"Insert image (click to upload, or drag & drop)",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",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"})]})}),(0,n.jsx)("input",{ref:o,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:e=>{var t;let n=Array.from(null!=(t=e.target.files)?t:[]);n.length>0&&r&&r(n),e.target.value=""}}),(0,n.jsx)(J.IB,{active:!1,onClick:()=>{t.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run()},title:"Insert table",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 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"})]})}),(0,n.jsx)(J.IB,{active:!1,onClick:()=>{t.chain().focus().setHorizontalRule().run()},title:"Horizontal rule",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)("line",{x1:"2",x2:"22",y1:"12",y2:"12"})})})]})]}):null}},61239:(e,t,r)=>{"use strict";r.d(t,{WorkspaceShell:()=>hF});var n=r(80534),o=r(74166),l=r(99197),a=r(80584),s=r(45454),i=r(80902),c=r(38094),d=r(94326),u=r(1811),p=r(85628),h=r(31804);let m=a.i,x=o.forwardRef((e,t)=>{let{className:r,...o}=e;return(0,n.jsx)(s.o,{ref:t,"data-slot":"combobox-input",className:(0,h.cn)("w-full rounded-xl py-2 text-sm outline-none transition-colors",r),...o})});function f(e){let{className:t,side:r="bottom",sideOffset:o=8,align:l="start",alignOffset:a=0,anchor:s,...u}=e;return(0,n.jsx)(i.K,{children:(0,n.jsx)(c.o,{side:r,sideOffset:o,align:l,alignOffset:a,anchor:s,className:"isolate z-[10000]",children:(0,n.jsx)(d.I,{"data-slot":"combobox-content",className:(0,h.cn)("bg-neutral-100/[0.67] dark:bg-neutral-900/[0.67] border border-white dark:border-white/10 backdrop-blur-md text-[var(--color-text)] max-h-[var(--available-height)] w-[calc(var(--anchor-width)+48px)] overflow-hidden 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",t),...u})})})}function v(e){let{className:t,...r}=e;return(0,n.jsx)(u.e,{"data-slot":"combobox-list",className:(0,h.cn)("max-h-[300px] overflow-y-auto overscroll-contain thin-scrollbar",t),...r})}function g(e){let{className:t,children:r,...o}=e;return(0,n.jsx)(p.x,{"data-slot":"combobox-item",className:(0,h.cn)("bg-transparent data-highlighted:bg-neutral-400/15 text-sm transition-all relative flex w-full cursor-pointer items-center gap-2.5 rounded-2xl px-3 py-2 outline-none select-none","data-disabled:pointer-events-none data-disabled:opacity-50",t),...o,children:r})}x.displayName="ComboboxInput";var y=r(69517),b=r(65547),j=r(86482),k=r(82311),w=r(94626),N=r(5742),C=r(67465),S=r(46009),M=r(8509),T=r(75902),L=r(42433);function I(e){let{name:t,size:r=16}=e,o=()=>(0,n.jsx)(L.A,{size:r,style:{flexShrink:0}});return t?(0,n.jsx)(T.A,{name:t,size:r,fallback:o,className:"shrink-0"}):o()}function _(e){var t,r,n;let o=null!=(t=e.path)?t:e.id,l=null!=(r=o.split("/").pop())?r:e.label;return{name:"object"===e.kind?(0,M.PV)(e.label):l,path:o,type:null!=(n=e.nodeType)?n:"object"===e.kind?"folder":"file"}}function R(){let{resolvedTheme:e,setTheme:t}=(0,N.D)(),[r,l]=(0,o.useState)(!1);if((0,o.useEffect)(()=>l(!0),[]),!r)return(0,n.jsx)("div",{className:"w-[26px] h-[26px]"});let a="dark"===e;return(0,n.jsx)("button",{type:"button",onClick:()=>t(a?"light":"dark"),className:"p-1.5 rounded-lg transition-colors",style:{color:"var(--color-text-muted)"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},title:a?"Switch to light mode":"Switch to dark mode",children:a?(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:"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:"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 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"})})})}function 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)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("path",{d:"m21 21-4.3-4.3"})]})}function D(e){let{type:t}=e;switch(t){case"folder":return(0,n.jsx)(y.A,{size:16,style:{flexShrink:0,color:"#60a5fa"}});case"document":default:return(0,n.jsx)(b.A,{size:16,style:{flexShrink:0,opacity:.7}});case"database":return(0,n.jsx)(j.A,{size:16,style:{flexShrink:0}})}}function A(e){let{onSelect:t,searchFn:r}=e,[l,a]=(0,o.useState)([]),[s,i]=(0,o.useState)(!1),[c,d]=(0,o.useState)(""),u=(0,o.useRef)(!1),p=(0,o.useRef)(null),h=(0,o.useRef)(null);(0,o.useEffect)(()=>()=>{p.current&&clearTimeout(p.current)},[]);let y=(0,o.useCallback)(e=>{if(u.current){u.current=!1;return}if(d(e),!e.trim()){a([]),i(!1);return}r?(a(r(e.trim(),20).map(_)),i(!0)):(p.current&&clearTimeout(p.current),p.current=setTimeout(async()=>{try{var t;let r=await fetch("/api/workspace/suggest-files?q=".concat(encodeURIComponent(e.trim()))),n=await r.json();a(null!=(t=n.items)?t:[]),i(!0)}catch(e){a([])}},150))},[r]);return(0,n.jsxs)(m,{value:null,open:s,onOpenChange:e=>{e||i(!1)},onValueChange:e=>{e&&(u.current=!0,t(e),i(!1),d(""),a([]))},onInputValueChange:y,filter:null,itemToStringLabel:()=>"",children:[(0,n.jsxs)("div",{ref:h,className:"relative",children:[(0,n.jsx)("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none z-10",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(E,{})}),(0,n.jsx)(x,{placeholder:"Search",className:"w-full pl-9 pr-10 py-1.5 rounded-xl text-sm outline-none transition-colors",style:{background:"var(--color-surface-hover)",color:"var(--color-text)"}})]}),(0,n.jsxs)(f,{anchor:h,children:[(0,n.jsx)(v,{children:l.map(e=>(0,n.jsxs)(g,{value:e,children:[(0,n.jsx)("span",{className:"flex-shrink-0",style:{color:"var(--color-text-muted)",opacity:.55},children:(0,n.jsx)(D,{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 text-xs",style:{color:"var(--color-text-muted)"},children:e.path.split("/").slice(0,-1).join("/")})]})]},e.path))}),c.trim()&&0===l.length&&(0,n.jsx)("div",{className:"py-3 text-center text-sm",style:{color:"var(--color-text-muted)"},children:"No files found"})]})]})}function F(e){let{orgName:t,onFileSearchSelect:r,mobile:l,onClose:a,showHidden:s,onToggleHidden:i,width:c,onCollapse:d,compact:u=!1,onToggleCompact:p,activeWorkspace:h,onWorkspaceChanged:m,onNavigate:x,activeCrmTarget:f=null,customCrmObjects:v,activeCrmObjectName:g=null,onNavigateToCrmObject:y,chatsPanel:b,onNewChatSession:j}=e,N=l?"280px":null!=c?c:260,[T,L]=(0,o.useState)(!1),[_,E]=(0,o.useState)("home"),D=[{id:"crm-people",label:"People",target:"people",icon:(0,n.jsxs)("svg",{className:"h-4 w-4 shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,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"})]})},{id:"crm-companies",label:"Companies",target:"companies",icon:(0,n.jsxs)("svg",{className:"h-4 w-4 shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[(0,n.jsx)("path",{d:"M3 21h18"}),(0,n.jsx)("path",{d:"M5 21V7l8-4v18"}),(0,n.jsx)("path",{d:"M19 21V11l-6-4"}),(0,n.jsx)("path",{d:"M9 9h0"}),(0,n.jsx)("path",{d:"M9 13h0"}),(0,n.jsx)("path",{d:"M9 17h0"})]})},{id:"crm-inbox",label:"Inbox",target:"inbox",icon:(0,n.jsxs)("svg",{className:"h-4 w-4 shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[(0,n.jsx)("polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12"}),(0,n.jsx)("path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11Z"})]})},{id:"crm-calendar",label:"Calendar",target:"calendar",icon:(0,n.jsxs)("svg",{className:"h-4 w-4 shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2",ry:"2"}),(0,n.jsx)("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),(0,n.jsx)("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),(0,n.jsx)("line",{x1:"3",y1:"10",x2:"21",y2:"10"})]})}],A=[{id:"cloud",label:"Cloud",icon:(0,n.jsx)("svg",{className:"h-4 w-4 shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z"})})},{id:"integrations",label:"Integrations",icon:(0,n.jsx)(w.qX3,{className:"h-4 w-4 shrink-0","aria-hidden":!0})},{id:"skills",label:"Skills",icon:(0,n.jsx)(k.abJ,{className:"h-4 w-4 shrink-0","aria-hidden":!0})},{id:"cron",label:"Cron",icon:(0,n.jsxs)("svg",{className:"h-4 w-4 shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("polyline",{points:"12 6 12 12 16 14"})]})}],F=(0,n.jsxs)("aside",{className:"flex flex-col h-screen shrink-0 border-r",style:{width:"number"==typeof N?"".concat(N,"px"):N,minWidth:"number"==typeof N?"".concat(N,"px"):N,background:"var(--color-bg)",borderColor:"var(--color-border)"},children:[p&&(0,n.jsx)("div",{className:"flex items-center justify-center h-[44px] shrink-0",children:(0,n.jsx)("button",{type:"button",onClick:p,className:"w-9 h-9 rounded-lg flex items-center justify-center transition-colors",style:{color:"var(--color-text-muted)"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},title:"Expand sidebar",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)("div",{className:"flex items-center justify-center pb-0.5 shrink-0",children:(0,n.jsx)(C.N,{activeWorkspaceHint:null!=h?h:null,onWorkspaceSwitch:()=>{null==m||m()},onWorkspaceDelete:()=>{null==m||m()},onCreateWorkspace:()=>{L(!0)},trigger:e=>{let{onClick:r,activeWorkspace:o,switching:l}=e;return(0,n.jsx)("button",{type:"button",onClick:r,disabled:l,className:"w-7 h-7 mx-auto rounded-lg overflow-hidden flex items-center justify-center transition-opacity hover:opacity-90",title:"".concat(t||"Workspace").concat(o?" — ".concat(o):""),children:(0,n.jsx)("img",{src:"/dench-workspace-icon.png",alt:"",className:"w-7 h-7 object-cover",draggable:!1})})}})}),x&&(0,n.jsxs)("div",{className:"flex flex-col items-center gap-0.5 pt-1 pb-1",children:[D.map(e=>{let t=f===e.target;return(0,n.jsx)("button",{type:"button",onClick:()=>x(e.id),className:"w-9 h-9 rounded-lg flex items-center justify-center transition-colors",style:{color:"var(--color-text)",background:t?"var(--color-surface-hover)":"transparent"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="transparent")},title:e.label,"aria-label":e.label,children:e.icon},e.id)}),v&&v.length>0&&y&&v.map(e=>{let t=g===e.name,r=(0,M.PV)(e.name);return(0,n.jsx)("button",{type:"button",onClick:()=>y(e.name),className:"w-9 h-9 rounded-lg flex items-center justify-center transition-colors",style:{color:"var(--color-text)",background:t?"var(--color-surface-hover)":"transparent"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="transparent")},title:r,"aria-label":r,children:(0,n.jsx)(I,{name:e.icon,size:16})},"crm-object-".concat(e.name))})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0"}),x&&(0,n.jsx)("div",{className:"flex flex-col items-center gap-0.5 py-1",children:A.map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>x(e.id),className:"w-9 h-9 rounded-lg flex items-center justify-center transition-colors",style:{color:"var(--color-text)"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},title:e.label,"aria-label":e.label,children:e.icon},e.id))}),(0,n.jsxs)("div",{className:"flex flex-col items-center py-1.5 gap-0.5",children:[i&&(0,n.jsx)("button",{type:"button",onClick:i,className:"w-9 h-9 rounded-lg flex items-center justify-center transition-colors",style:{color:s?"var(--color-text)":"var(--color-text-muted)"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},title:s?"Hide dotfiles":"Show dotfiles",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:s?(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)(R,{})]})]}),P=(0,n.jsxs)("aside",{className:"flex flex-col h-screen shrink-0 ".concat(l?"drawer-left":"border-r"),style:{width:"number"==typeof N?"".concat(N,"px"):N,minWidth:"number"==typeof N?"".concat(N,"px"):N,background:"var(--color-bg)",borderColor:"var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 px-2 h-[44px] shrink-0",children:[(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(C.N,{activeWorkspaceHint:null!=h?h:null,onWorkspaceSwitch:()=>{null==m||m()},onWorkspaceDelete:()=>{null==m||m()},onCreateWorkspace:()=>{L(!0)},trigger:e=>{let{onClick:r,activeWorkspace:o,switching:l}=e;return(0,n.jsxs)("button",{type:"button",onClick:r,disabled:l,className:"text-[13px] flex items-center gap-1.5 truncate w-full transition-colors rounded-lg px-2 py-1.5",style:{color:"var(--color-text)"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},title:"Switch workspace",children:[(0,n.jsx)("span",{className:"truncate font-semibold",children:t||"Workspace"}),o&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"shrink-0 opacity-40",children:"/"}),(0,n.jsx)("span",{className:"truncate text-[12px]",style:{color:"var(--color-text-muted)"},children:o})]}),(0,n.jsx)("span",{className:"flex-1"}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)("path",{d:"m6 9 6 6 6-6"})})]})}})}),(p||d)&&(0,n.jsx)("button",{type:"button",onClick:null!=p?p:d,className:"p-1.5 rounded-lg shrink-0 transition-colors",style:{color:"var(--color-text-muted)"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},title:p?"Collapse to icons":"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"})]})})]}),b&&(0,n.jsxs)("div",{className:"px-2 pt-1 pb-1 flex items-center gap-1",children:[[{id:"home",label:"Home"},{id:"chats",label:"Chats"}].map(e=>{let t=_===e.id;return(0,n.jsx)("button",{type:"button",onClick:()=>E(e.id),className:"flex-1 px-2 py-1 rounded-md text-[12px] font-medium transition-colors cursor-pointer",style:{color:t?"var(--color-text)":"var(--color-text-muted)",background:t?"var(--color-surface-hover)":"transparent"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="transparent")},children:e.label},e.id)}),"chats"===_&&j&&(0,n.jsx)("button",{type:"button",onClick:j,className:"p-1 rounded-md transition-colors cursor-pointer 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"},title:"New chat","aria-label":"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","aria-hidden":!0,children:[(0,n.jsx)("path",{d:"M5 12h14"}),(0,n.jsx)("path",{d:"M12 5v14"})]})})]}),"chats"===_&&b?(0,n.jsx)("div",{className:"flex-1 min-h-0 flex flex-col relative",children:b}):(0,n.jsxs)(n.Fragment,{children:[x&&(0,n.jsxs)("div",{className:"px-2 pt-1 pb-1",children:[(0,n.jsx)("div",{className:"px-2 pt-2 pb-1 text-[9px] lowercase",style:{color:"var(--color-text-muted)",letterSpacing:"0.05em"},children:"workspace"}),(0,n.jsxs)("div",{className:"space-y-0.5",children:[D.map(e=>{let t=f===e.target;return(0,n.jsxs)("button",{type:"button",onClick:()=>x(e.id),className:"w-full flex items-center gap-2.5 px-2 py-1.5 rounded-lg text-[13px] transition-colors",style:{color:"var(--color-text)",background:t?"var(--color-surface-hover)":"transparent"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="transparent")},children:[(0,n.jsx)("span",{className:"shrink-0",style:{color:"var(--color-text-muted)"},children:e.icon}),e.label]},e.id)}),v&&v.length>0&&y&&v.map(e=>{let t=g===e.name,r=(0,M.PV)(e.name);return(0,n.jsxs)("button",{type:"button",onClick:()=>y(e.name),className:"w-full flex items-center gap-2.5 px-2 py-1.5 rounded-lg text-[13px] transition-colors",style:{color:"var(--color-text)",background:t?"var(--color-surface-hover)":"transparent"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="transparent")},title:r,children:[(0,n.jsx)("span",{className:"shrink-0",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(I,{name:e.icon,size:16})}),r]},"crm-object-".concat(e.name))})]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0"}),x&&(0,n.jsx)("div",{className:"px-2 py-1 space-y-0.5",children:A.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>x(e.id),className:"w-full flex items-center gap-2.5 px-2 py-1.5 rounded-lg text-[13px] transition-colors",style:{color:"var(--color-text)"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,n.jsx)("span",{className:"shrink-0",style:{color:"var(--color-text-muted)"},children:e.icon}),e.label]},e.id))})]}),(0,n.jsxs)("div",{className:"px-2 py-1.5 flex items-center justify-between",children:[(0,n.jsxs)("a",{href:"https://dench.com",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 px-2 py-1 rounded-lg text-[11px]",style:{color:"var(--color-text-muted)"},children:["dench.com"," v".concat("3.0.8")]}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[i&&(0,n.jsx)("button",{type:"button",onClick:i,className:"p-1.5 rounded-lg transition-colors",style:{color:s?"var(--color-text)":"var(--color-text-muted)"},title:s?"Hide dotfiles":"Show dotfiles",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:s?(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)(R,{})]})]})]});return l?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"drawer-backdrop",onClick:()=>void(null==a||a()),children:(0,n.jsx)("div",{onClick:e=>e.stopPropagation(),className:"fixed inset-y-0 left-0 z-50",children:P})}),(0,n.jsx)(S.s,{isOpen:T,onClose:()=>L(!1),onCreated:()=>{null==m||m()}})]}):(0,n.jsxs)(n.Fragment,{children:[!l&&u?F:P,(0,n.jsx)(S.s,{isOpen:T,onClose:()=>L(!1),onCreated:()=>{null==m||m()}})]})}var P=r(26165);function B(e){let{...t}=e;return(0,n.jsx)(P.bL,{"data-slot":"context-menu",...t})}function W(e){let{className:t,...r}=e;return(0,n.jsx)(P.l9,{"data-slot":"context-menu-trigger",className:(0,h.cn)("select-none",t),...r})}function O(e){let{className:t,...r}=e;return(0,n.jsx)(P.ZL,{children:(0,n.jsx)(P.UC,{"data-slot":"context-menu-content",className:(0,h.cn)("bg-neutral-100/[0.67] dark:bg-neutral-900/[0.67] border border-white dark:border-white/10 backdrop-blur-md text-[var(--color-text)] z-[9999] max-h-[var(--radix-context-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",t),...r})})}function z(e){let{className:t,inset:r,variant:o="default",...l}=e;return(0,n.jsx)(P.q7,{"data-slot":"context-menu-item","data-inset":r,"data-variant":o,className:(0,h.cn)("bg-transparent hover:bg-neutral-400/15 focus: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 select-none","data-[variant=destructive]:text-[var(--color-error)] data-[variant=destructive]:hover:bg-[var(--color-error)]/10 data-[variant=destructive]:focus: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),...l})}function U(e){let{className:t,...r}=e;return(0,n.jsx)(P.wv,{"data-slot":"context-menu-separator",className:(0,h.cn)("bg-neutral-400/15 -mx-1 my-1 h-px",t),...r})}function H(e){let{className:t,...r}=e;return(0,n.jsx)("span",{"data-slot":"context-menu-shortcut",className:(0,h.cn)("text-[var(--color-text-muted)] ml-auto text-xs tracking-widest",t),...r})}var V=r(56269),K=r(74039),J=r(31264),q=r(91361),G=r(87694);function $(){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 Y(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("\\"))},[]),p=(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(),p()):"Escape"===e.key&&(e.preventDefault(),l())},[p,l]);return(0,n.jsx)("input",{ref:d,type:"text",value:a,onChange:e=>{s(e.target.value),c(!1)},onBlur:p,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()})}var Z=r(90425);function Q(e){return!!e.virtual||(0,Z.L6)(e.path)}let X=[/^\.object\.yaml$/,/\.wal$/,/\.tmp$/],ee=[/^workspace\.duckdb/,/^workspace_context\.yaml$/];function et(e,t){var r;let n=function(e,t){let r=(0,Z.Bv)(e);return"virtual"===r||"homeRelative"===r?null:"workspaceRelative"===r?e:t&&(e===t||e.startsWith("".concat(t,"/")))?e===t?"":e.slice(t.length+1):null}(e,t);if(null==n)return!1;let o=null!=(r=n.split("/").pop())?r:"";return!!X.some(e=>e.test(o))||""!==n&&!n.includes("/")&&ee.some(e=>e.test(o))}function er(e){let{open:t}=e;return t?(0,n.jsx)(V.A,{size:18,style:{flexShrink:0,color:"#60a5fa"}}):(0,n.jsx)(y.A,{size:18,style:{flexShrink:0,color:"#60a5fa"}})}function en(){return(0,n.jsx)(b.A,{size:18,style:{flexShrink:0,opacity:.7}})}function eo(){return(0,n.jsx)(b.A,{size:18,style:{flexShrink:0,opacity:.7}})}function el(){return(0,n.jsx)(j.A,{size:18,style:{flexShrink:0}})}function ea(){return(0,n.jsx)(K.A,{size:18,style:{flexShrink:0}})}function es(){return(0,n.jsx)(J.A,{size:18,style:{flexShrink:0}})}function ei(){return(0,n.jsx)(q.A,{size:18,style:{flexShrink:0}})}function ec(e){let{node:t,open:r}=e;if(t.path.startsWith("~chats/")||"~chats"===t.path)return(0,n.jsx)(es,{});switch(t.type){case"object":return(0,n.jsx)(I,{name:t.icon,size:18});case"folder":return(0,n.jsx)(er,{open:r});case"document":return(0,n.jsx)(en,{});case"database":return(0,n.jsx)(el,{});case"report":return(0,n.jsx)(ea,{});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)(ei,{})}default:return(0,n.jsx)(eo,{})}}async function ed(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 eu(e){return(await fetch("/api/workspace/file",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})})).json()}async function ep(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 eh(e){return(await fetch("/api/workspace/copy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})})).json()}async function em(e){return(await fetch("/api/workspace/mkdir",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})})).json()}async function ex(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return(await fetch("/api/workspace/objects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e,...t?{parentPath:t}:{}})})).json()}async function ef(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return(await fetch((0,Z.nC)(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,content:t})})).json()}function ev(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 eg(e){let{kind:t,parentPath:r,onSubmit:l,onCancel:a}=e,[s,i]=(0,o.useState)("file"===t?"untitled.md":"table"===t?"new_table":"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 ey(e){let{node:t,depth:r,activePath:l,selectedPath:a,onSelect:s,onNodeSelect:i,expandedPaths:c,onToggleExpand:d,renamingPath:u,onStartRename:p,onCommitRename:h,onCancelRename:m,onContextMenu:x,compact:f,dragOverPath:v,workspaceRoot:g}=e,y=!!g&&t.path===g,b=t.children&&t.children.length>0,j=!y&&!!b,k=!y&&c.has(t.path),w=l===t.path,N=a===t.path,C=u===t.path,S=et(t.path,g),M=Q(t),T=S||M||y,L=v===t.path&&j,{attributes:I,listeners:_,setNodeRef:R,isDragging:E}=(0,G.PM)({id:"drag-".concat(t.path),data:{node:t},disabled:T}),{setNodeRef:D,isOver:A}=(0,G.zM)({id:"drop-".concat(t.path),data:{node:t},disabled:!j||M}),F=(0,o.useCallback)(()=>{i(t.path),s(t),j&&d(t.path)},[t,s,i,d,j]),P=(0,o.useCallback)(()=>{},[]),B=(0,o.useCallback)(e=>{i(t.path),x(e,t)},[t,i,x]),W=(0,o.useCallback)(e=>{R(e),D(e)},[R,D]),O=(A||L)&&j;return(0,n.jsxs)("div",{style:{opacity:E?.4:1},children:[(0,n.jsxs)("div",{ref:W,...I,..._,role:"treeitem",tabIndex:-1,draggable:!T,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:F,onDoubleClick:P,onContextMenu:B,className:"w-full flex items-center gap-2 py-1.5 px-2 rounded-xl text-left text-sm transition-all duration-100 cursor-pointer select-none",style:{paddingLeft:"".concat(20*r+14,"px"),background:O?"var(--color-accent-light)":N||w?"var(--color-surface-hover)":"transparent",color:w||N?"var(--color-text)":"var(--color-text-secondary)",outline:O?"1px dashed var(--color-accent)":"none",outlineOffset:"-1px"},onMouseEnter:e=>{w||N||O||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{w||N||O||(e.currentTarget.style.background="transparent")},children:[(0,n.jsx)("span",{className:"flex-shrink-0 flex items-center",style:{color:"var(--color-text-muted)",opacity:.55,filter:"drop-shadow(0 0.5px 1px rgba(0,0,0,0.15))"},children:(0,n.jsx)(ec,{node:t,open:k})}),C?(0,n.jsx)(Y,{currentName:t.name,onCommit:h,onCancel:m}):(0,n.jsx)("span",{className:"truncate flex-1",children:t.name})]}),k&&b&&(0,n.jsx)("div",{children:t.children.map(e=>(0,n.jsx)(ey,{node:e,depth:r+1,activePath:l,selectedPath:a,onSelect:s,onNodeSelect:i,expandedPaths:c,onToggleExpand:d,renamingPath:u,onStartRename:p,onCommitRename:h,onCancelRename:m,onContextMenu:x,compact:f,dragOverPath:v,workspaceRoot:g},e.path))})]})}function eb(e){let{isDragging:t}=e,{setNodeRef:r,isOver:o}=(0,G.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 ej(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:function(e){switch(e.type){case"document":return"#60a5fa";case"database":return"#c084fc";case"report":return"#22c55e";case"app":return"#6366f1";default:return"var(--color-text-muted)"}}(t)},children:(0,n.jsx)(ec,{node:t})}),(0,n.jsx)("span",{children:t.name})]})}function ek(e){let t=e.split("/");return t.pop(),t.join("/")||"."}let ew="denchclaw-tree-expanded";function eN(e){let{tree:t,activePath:r,onSelect:l,onRefresh:a,compact:s,parentDir:i,onNavigateUp:c,browseDir:d,workspaceRoot:u,onExternalDrop:p}=e,[h,m]=(0,o.useState)(()=>(function(){try{let e=window.localStorage.getItem(ew);if(e){let t=JSON.parse(e);if(Array.isArray(t))return new Set(t)}}catch(e){}return new Set})()),[x,f]=(0,o.useState)(null);(0,o.useEffect)(()=>{if(null===r)return void f(null);f(null);let e=(u&&r.startsWith(u+"/")?r.slice(u.length+1):r).split("/");e.length>1&&m(t=>{let r=new Set(t),n=!1;for(let t=1;t<e.length;t++){let o=e.slice(0,t).join("/");r.has(o)||(r.add(o),n=!0)}return n?r:t})},[r,u]);let[v,g]=(0,o.useState)(null),[y,b]=(0,o.useState)(null),[j,k]=(0,o.useState)(null),w=(0,o.useRef)({x:0,y:0}),N=(0,o.useRef)(null),C=(0,o.useCallback)(()=>{let e=e=>{w.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")};N.current=e,window.addEventListener("pointermove",e,!0)},[]),S=(0,o.useCallback)(()=>{var e;N.current&&(window.removeEventListener("pointermove",N.current,!0),N.current=null),null==(e=document.querySelector("[data-drag-hover]"))||e.removeAttribute("data-drag-hover")},[]);(0,o.useEffect)(()=>S,[S]);let[M,T]=(0,o.useState)({kind:"empty"}),L=(0,o.useRef)(0),[I,_]=(0,o.useState)(null),[R,E]=(0,o.useState)(null),D=(0,o.useRef)(null),A=(0,o.useRef)(null),F=(0,o.useRef)(null);(0,o.useEffect)(()=>{try{window.localStorage.setItem(ew,JSON.stringify([...h]))}catch(e){}},[h]);let P=(0,o.useCallback)(e=>{m(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),O=(0,G.FR)((0,G.MS)(G.AN,{activationConstraint:{distance:8}})),z=(0,o.useCallback)(e=>{let t=e.active.data.current;(null==t?void 0:t.node)&&(k(t.node),C())},[C]),U=(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__"!==F.current&&(A.current&&clearTimeout(A.current),F.current="__root__"),b("__root__");else if(null==r?void 0:r.node){let e=r.node.path;b(e),F.current!==e&&(A.current&&clearTimeout(A.current),F.current=e,("folder"===r.node.type||"object"===r.node.type)&&(A.current=setTimeout(()=>{F.current===e&&m(t=>{if(t.has(e))return t;let r=new Set(t);return r.add(e),r})},300)))}else A.current&&clearTimeout(A.current),F.current=null,b(null)},[]),H=(0,o.useCallback)(async e=>{var t;k(null),b(null),A.current&&clearTimeout(A.current),F.current=null,S();let r=e.active.data.current;if(!(null==r?void 0:r.node))return;let n=r.node;if(p){let{x:e,y:t}=w.current,r=document.elementFromPoint(e,t);if(null==r?void 0:r.closest("[data-chat-drop-target]"))return void p(n)}let o=null==(t=e.over)?void 0:t.data.current;if(null==o?void 0:o.rootDrop){if("."===ek(n.path))return;(await ep(n.path,".")).ok&&a();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+"/"))&&ek(n.path)!==l.path&&(await ep(n.path,l.path)).ok&&a()},[a,p,S]),V=(0,o.useCallback)(()=>{k(null),b(null),A.current&&clearTimeout(A.current),F.current=null,S()},[S]),K=(0,o.useCallback)((e,t)=>{if(L.current===e.timeStamp)return;L.current=e.timeStamp;let r=et(t.path,u)||Q(t);T({kind:"folder"===t.type||"object"===t.type?"folder":"file",path:t.path,name:t.name,isSystem:r})},[u]),J=(0,o.useCallback)(e=>{L.current!==e.timeStamp&&(L.current=e.timeStamp,T({kind:"empty"}))},[]),q=(0,o.useCallback)(async e=>{if(M)switch(e){case"open":if("empty"!==M.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,M.path);e&&l(e)}break;case"rename":"empty"!==M.kind&&g(M.path);break;case"duplicate":"empty"!==M.kind&&(await eh(M.path),a());break;case"copy":case"getInfo":"empty"!==M.kind&&await navigator.clipboard.writeText((0,Z.WW)(M.path,u));break;case"delete":"empty"!==M.kind&&_(M.path);break;case"newFile":E({kind:"file",parentPath:"folder"===M.kind?M.path:"file"===M.kind?ek(M.path):""});break;case"newFolder":E({kind:"folder",parentPath:"folder"===M.kind?M.path:"file"===M.kind?ek(M.path):""});break;case"newTable":E({kind:"table",parentPath:"folder"===M.kind?M.path:"file"===M.kind?ek(M.path):""})}},[M,t,l,a,u]),$=(0,o.useCallback)(async e=>{if(!v)return;let t=await ed(v,e);g(null),t.ok&&a()},[v,a]),Y=(0,o.useCallback)(()=>{g(null)},[]),X=(0,o.useCallback)(async()=>{if(!I)return;let e=await eu(I);_(null),e.ok&&a()},[I,a]),ee=(0,o.useCallback)(async e=>{if(!R||!e)return;let t=R.parentPath?"".concat(R.parentPath,"/").concat(e):e,r=t;if("folder"===R.kind)await em(t);else if("table"===R.kind){let o=await ex(e,R.parentPath);if(!(null==o?void 0:o.ok)){var n;window.alert(null!=(n=null==o?void 0:o.error)?n:"Failed to create table.");return}r="string"==typeof o.path&&o.path?o.path:t}else await ef(t,"");E(null),a(),"table"===R.kind&&(f(r),l({name:e,path:r,type:"object",defaultView:"table"})),m(e=>{let t=new Set(e);return t.add(R.parentPath),t})},[R,a,l]),er=(0,o.useCallback)(e=>{if(v)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,h),n=r.findIndex(e=>e.path===x),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&&f(t.path);break}case"ArrowUp":{e.preventDefault();let t=n>0?r[n-1]:r[r.length-1];t&&f(t.path);break}case"ArrowRight":e.preventDefault(),o&&("folder"===o.type||"object"===o.type)&&m(e=>new Set([...e,o.path]));break;case"ArrowLeft":e.preventDefault(),o&&h.has(o.path)&&m(e=>{let t=new Set(e);return t.delete(o.path),t});break;case"Enter":if(e.preventDefault(),o){let t=et(o.path,u)||Q(o);e.shiftKey||t?l(o):g(o.path)}break;case"F2":e.preventDefault(),!o||et(o.path,u)||Q(o)||g(o.path);break;case"Backspace":case"Delete":!o||et(o.path,u)||Q(o)||(e.preventDefault(),_(o.path));break;default:if(e.metaKey||e.ctrlKey){if("c"===e.key&&o)e.preventDefault(),navigator.clipboard.writeText((0,Z.WW)(o.path,u));else if("d"===e.key&&o&&!et(o.path,u))e.preventDefault(),eh(o.path).then(()=>a());else if("n"===e.key){e.preventDefault();let t=o?"folder"===o.type||"object"===o.type?o.path:ek(o.path):"";e.shiftKey?E({kind:"folder",parentPath:t}):E({kind:"file",parentPath:t})}}}},[t,h,x,v,l,a,u]);return 0===t.length?(0,n.jsxs)(B,{children:[(0,n.jsx)(W,{asChild:!0,children:(0,n.jsx)("div",{className:"px-4 py-6 text-center text-sm",style:{color:"var(--color-text-muted)"},onContextMenu:J,children:"No files in workspace"})}),(0,n.jsx)(eC,{target:M,onAction:q}),R&&(0,n.jsx)(eg,{kind:R.kind,parentPath:R.parentPath,onSubmit:ee,onCancel:()=>E(null)})]}):(0,n.jsxs)(G.Mp,{sensors:O,collisionDetection:G.fp,onDragStart:z,onDragOver:U,onDragEnd:H,onDragCancel:V,children:[(0,n.jsxs)(B,{children:[(0,n.jsx)(W,{asChild:!0,children:(0,n.jsxs)("div",{ref:D,className:"py-1 outline-none flex flex-col min-h-full",tabIndex:0,role:"tree",onKeyDown:er,onContextMenu:J,children:[null!=i&&c&&(0,n.jsxs)("div",{role:"treeitem",tabIndex:-1,onClick:c,className:"w-full flex items-center gap-2 py-1.5 px-2 rounded-xl text-left text-sm transition-all duration-100 cursor-pointer select-none",style:{paddingLeft:"14px",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)("span",{className:"flex-shrink-0 flex items-center",style:{opacity:.55},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)("span",{className:"truncate flex-1",children:"Back"})]}),t.map(e=>(0,n.jsx)(ey,{node:e,depth:0,activePath:r,selectedPath:x,onSelect:l,onNodeSelect:f,expandedPaths:h,onToggleExpand:P,renamingPath:v,onStartRename:g,onCommitRename:$,onCancelRename:Y,onContextMenu:K,compact:s,dragOverPath:y,workspaceRoot:u},e.path)),(0,n.jsx)(eb,{isDragging:!!j})]})}),(0,n.jsx)(eC,{target:M,onAction:q})]}),(0,n.jsx)(G.Hd,{dropAnimation:null,style:{pointerEvents:"none"},children:j?(0,n.jsx)(ej,{node:j}):null}),I&&(0,n.jsx)(ev,{message:'Are you sure you want to delete "'.concat(I.split("/").pop(),'"? This action cannot be undone.'),onConfirm:X,onCancel:()=>_(null)}),R&&(0,n.jsx)(eg,{kind:R.kind,parentPath:R.parentPath,onSubmit:ee,onCancel:()=>E(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 eC(e){let{target:t,onAction:r}=e,o=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},{action:"newTable",label:"New Table",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"},{action:"newTable",label:"New Table"},{separator:!0},{action:"paste",label:"Paste",shortcut:"⌘V",disabled:!0}]}(t),l="empty"!==t.kind&&t.isSystem;return(0,n.jsxs)(O,{className:"min-w-[200px]",children:[l&&(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)($,{}),(0,n.jsx)("span",{children:"System file (locked)"})]}),o.map((e,t)=>"separator"in e&&e.separator?(0,n.jsx)(U,{},"sep-".concat(t)):(0,n.jsxs)(z,{variant:e.danger?"destructive":"default",disabled:e.disabled,onSelect:()=>r(e.action),children:[e.icon,(0,n.jsx)("span",{className:"flex-1",children:e.label}),e.disabled&&l&&(0,n.jsx)($,{}),e.shortcut&&(0,n.jsx)(H,{children:e.shortcut})]},e.action))]})}function eS(e){let{tab:t}=e,r=function(e){var t;let r=null!=(t=e.path)?t:"";return"object"===e.kind&&("people"===r||"~crm/people"===r)?"people":"object"===e.kind&&("company"===r||"companies"===r||"~crm/companies"===r)?"company":"crm-person"===e.kind?"people":"crm-company"===e.kind?"company":"crm-inbox"===e.kind?"inbox":"crm-calendar"===e.kind?"calendar":"cloud"===e.kind?"cloud":"skills"===e.kind?"skills":"integrations"===e.kind?"integrations":"cron-dashboard"===e.kind||"cron-job"===e.kind?"cron":"app"===e.kind||r.includes(".dench.app")?"app":"object"===e.kind?"object":"directory"===e.kind||"browse"===e.kind?"folder":"file"}(t),o={width:12,height:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0};switch(r){case"people":return(0,n.jsxs)("svg",{...o,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"})]});case"company":return(0,n.jsxs)("svg",{...o,children:[(0,n.jsx)("path",{d:"M3 21h18"}),(0,n.jsx)("path",{d:"M5 21V7l8-4v18"}),(0,n.jsx)("path",{d:"M19 21V11l-6-4"})]});case"inbox":return(0,n.jsxs)("svg",{...o,children:[(0,n.jsx)("polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12"}),(0,n.jsx)("path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11Z"})]});case"calendar":return(0,n.jsxs)("svg",{...o,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"})]});case"cloud":return(0,n.jsx)("svg",{...o,children:(0,n.jsx)("path",{d:"M17.5 19a4.5 4.5 0 1 0-1.97-8.55A6 6 0 1 0 6 18h11.5Z"})});case"skills":return(0,n.jsx)("svg",{...o,children:(0,n.jsx)("path",{d:"m12 3 1.9 5.84H20l-4.95 3.6L16.95 18 12 14.4 7.05 18l1.9-5.56L4 8.84h6.1Z"})});case"integrations":return(0,n.jsxs)("svg",{...o,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"})]});case"cron":return(0,n.jsxs)("svg",{...o,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("polyline",{points:"12 6 12 12 16 14"})]});case"app":return(0,n.jsxs)("svg",{...o,children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M9 9h6v6H9z"})]});case"object":return(0,n.jsxs)("svg",{...o,children:[(0,n.jsx)("path",{d:"M3 3h18v4H3z"}),(0,n.jsx)("path",{d:"M3 11h18v4H3z"}),(0,n.jsx)("path",{d:"M3 19h18v2H3z"})]});case"folder":return(0,n.jsx)("svg",{...o,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"})});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)("polyline",{points:"14 2 14 8 20 8"})]})}}let eM=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"]);var eT=r(69176),eL=r(87131),eI=r(22856),e_=r(3087),eR=r(86233),eE=r(79919),eD=r(34872),eA=r(8466),eF=r(83879),eP=r(14273),eB=r(54602),eW=r(95107),eO=r(95573),ez=r(75643),eU=r(97199),eH=r(52454),eV=r(47697),eK=r(45679),eJ=r(47325),eq=r(68996),eG=r(77704);function e$(e){var t,l,a,s,i,c;let{mode:d,initialHtml:u,filePath:p,onSave:h,onDirty:m,compact:x}=e,[f,v]=(0,o.useState)(!1),[g,y]=(0,o.useState)("idle"),[b,j]=(0,o.useState)(!1),k=(0,o.useRef)(null),w=(0,o.useRef)(null),N=null!=(s=p.split("/").pop())?s:p,C="txt"===d,S=(0,eT.hG)({extensions:[eI.A.configure({codeBlock:{HTMLAttributes:{class:"code-block"}}}),eO.A,eK.A,eJ.A,eU.xJ,eH.A,eV.Ay.configure({multicolor:!0}),ez.A.configure({types:["heading","paragraph"]}),e_.Ay.configure({inline:!1,allowBase64:!0,HTMLAttributes:{class:"editor-image"}}),eR.Ay.configure({openOnClick:!1,autolink:!0,HTMLAttributes:{class:"editor-link",rel:"noopener"}}),eE.XI.configure({resizable:!1}),eD.A,eA.A,eF.h,eP.A,eB.A.configure({nested:!0}),eW.A.configure({placeholder:C?"Start typing...":"Start writing your document..."}),eq.A],content:u,immediatelyRender:!1,onUpdate:()=>{j(!0),y("idle"),null==m||m()}}),M=(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}},[]),T=(0,o.useCallback)(async e=>{if(S)for(let t of e){let e=await M(t);e&&S.chain().focus().setImage({src:e,alt:t.name}).run()}},[S,M]);(0,o.useEffect)(()=>{if(!S)return;let e=S.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(),T(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(),T(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)}},[S,T]);let L=(0,o.useCallback)(async()=>{if(S&&!f){v(!0),y("idle");try{if(C){let e=S.getText();if(!(await fetch((0,Z.nC)(p),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:p,content:e})})).ok)throw Error("Save failed")}else{let e=S.getHTML(),{default:t}=await Promise.all([r.e(30515),r.e(1078),r.e(65360),r.e(85814),r.e(23999)]).then(r.bind(r,91e3)),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",p),!(await fetch("/api/workspace/write-binary",{method:"POST",body:o})).ok)throw Error("Save failed")}y("saved"),j(!1),null==h||h(),k.current&&clearTimeout(k.current),k.current=setTimeout(()=>y("idle"),2e3)}catch(e){y("error")}finally{v(!1)}}},[S,p,f,C,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]),!S)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 I=null!=(i=null==(t=S.storage.characterCount)?void 0:t.words())?i:0,_=null!=(c=null==(l=S.storage.characterCount)?void 0:l.characters())?c:0;return(0,n.jsxs)("div",{className:"rich-doc-editor ".concat(x?"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)(tc,{mode:d}),(0,n.jsx)("span",{className:"rich-doc-filename",children:N}),b&&(0,n.jsx)("span",{className:"editor-save-indicator editor-save-unsaved",children:"Unsaved changes"}),"saved"===g&&!b&&(0,n.jsx)("span",{className:"editor-save-indicator editor-save-saved",children:"Saved"}),"error"===g&&(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:f||!b,className:"editor-save-button",children:f?"Saving...":"Save"})]})]}),!C&&(0,n.jsx)(eY,{editor:S,onUploadImages:T,imageInputRef:w}),C&&!x&&(0,n.jsxs)("div",{className:"editor-toolbar rich-doc-toolbar-minimal",children:[(0,n.jsxs)(eG.$Q,{children:[(0,n.jsx)(eG.IB,{active:!1,onClick:()=>S.chain().focus().undo().run(),title:"Undo",disabled:!S.can().undo(),children:(0,n.jsx)(e1,{})}),(0,n.jsx)(eG.IB,{active:!1,onClick:()=>S.chain().focus().redo().run(),title:"Redo",disabled:!S.can().redo(),children:(0,n.jsx)(e2,{})})]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("span",{className:"rich-doc-txt-hint",children:"Plain text — formatting not preserved on save"})]}),!C&&(0,n.jsx)(eL.m,{editor:S,children:(0,n.jsxs)("div",{className:"bubble-menu",children:[(0,n.jsx)(eG.zM,{active:S.isActive("bold"),onClick:()=>S.chain().focus().toggleBold().run(),title:"Bold",children:(0,n.jsx)("strong",{children:"B"})}),(0,n.jsx)(eG.zM,{active:S.isActive("italic"),onClick:()=>S.chain().focus().toggleItalic().run(),title:"Italic",children:(0,n.jsx)("em",{children:"I"})}),(0,n.jsx)(eG.zM,{active:S.isActive("underline"),onClick:()=>S.chain().focus().toggleUnderline().run(),title:"Underline",children:(0,n.jsx)("span",{style:{textDecoration:"underline"},children:"U"})}),(0,n.jsx)(eG.zM,{active:S.isActive("strike"),onClick:()=>S.chain().focus().toggleStrike().run(),title:"Strikethrough",children:(0,n.jsx)("s",{children:"S"})}),(0,n.jsx)(eG.zM,{active:S.isActive("code"),onClick:()=>S.chain().focus().toggleCode().run(),title:"Inline code",children:"<>"}),(0,n.jsx)(eG.zM,{active:S.isActive("link"),onClick:()=>{if(S.isActive("link"))S.chain().focus().unsetLink().run();else{let e=window.prompt("URL:");e&&S.chain().focus().setLink({href:e}).run()}},title:"Link",children:(0,n.jsx)(tn,{size:14})})]})}),(0,n.jsx)("div",{className:"rich-doc-scroll",children:(0,n.jsx)("div",{className:"rich-doc-page ".concat(C?"rich-doc-page--txt":""),children:(0,n.jsx)(eT.$Z,{editor:S})})}),!x&&(0,n.jsxs)("div",{className:"rich-doc-statusbar",children:[(0,n.jsxs)("span",{children:[I.toLocaleString()," word",1!==I?"s":""]}),(0,n.jsx)("span",{className:"rich-doc-statusbar-sep"}),(0,n.jsxs)("span",{children:[_.toLocaleString()," character",1!==_?"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:w,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&&T(r),e.target.value=""}})]})}function eY(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),p=(0,o.useRef)(null);return(0,o.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&i(!1),p.current&&!p.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)(eG.$Q,{children:[(0,n.jsx)(eG.IB,{active:!1,onClick:()=>r.chain().focus().undo().run(),title:"Undo",disabled:!r.can().undo(),children:(0,n.jsx)(e1,{})}),(0,n.jsx)(eG.IB,{active:!1,onClick:()=>r.chain().focus().redo().run(),title:"Redo",disabled:!r.can().redo(),children:(0,n.jsx)(e2,{})})]}),(0,n.jsx)(eG.x_,{}),(0,n.jsx)(eG.$Q,{children:(0,n.jsx)(eQ,{editor:r})}),(0,n.jsx)(eG.x_,{}),(0,n.jsxs)(eG.$Q,{children:[(0,n.jsx)(eG.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)(eG.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)(eG.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)(eG.IB,{active:r.isActive("strike"),onClick:()=>r.chain().focus().toggleStrike().run(),title:"Strikethrough",children:(0,n.jsx)("s",{children:"S"})}),(0,n.jsx)(eG.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)(eG.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)(eG.x_,{}),(0,n.jsxs)(eG.$Q,{children:[(0,n.jsxs)("div",{className:"relative",ref:u,children:[(0,n.jsx)(eG.IB,{active:s,onClick:()=>{i(!s),d(!1)},title:"Text color",children:(0,n.jsx)(ts,{color:null!=(t=r.getAttributes("textStyle").color)?t:"currentColor"})}),s&&(0,n.jsx)(e0,{onSelect:e=>{e?r.chain().focus().setColor(e).run():r.chain().focus().unsetColor().run(),i(!1)}})]}),(0,n.jsxs)("div",{className:"relative",ref:p,children:[(0,n.jsx)(eG.IB,{active:c,onClick:()=>{d(!c),i(!1)},title:"Highlight color",children:(0,n.jsx)(ti,{})}),c&&(0,n.jsx)(e0,{onSelect:e=>{e?r.chain().focus().toggleHighlight({color:e}).run():r.chain().focus().unsetHighlight().run(),d(!1)}})]})]}),(0,n.jsx)(eG.x_,{}),(0,n.jsxs)(eG.$Q,{children:[(0,n.jsx)(eG.IB,{active:r.isActive({textAlign:"left"}),onClick:()=>r.chain().focus().setTextAlign("left").run(),title:"Align left",children:(0,n.jsx)(e4,{})}),(0,n.jsx)(eG.IB,{active:r.isActive({textAlign:"center"}),onClick:()=>r.chain().focus().setTextAlign("center").run(),title:"Align center",children:(0,n.jsx)(e5,{})}),(0,n.jsx)(eG.IB,{active:r.isActive({textAlign:"right"}),onClick:()=>r.chain().focus().setTextAlign("right").run(),title:"Align right",children:(0,n.jsx)(e3,{})}),(0,n.jsx)(eG.IB,{active:r.isActive({textAlign:"justify"}),onClick:()=>r.chain().focus().setTextAlign("justify").run(),title:"Justify",children:(0,n.jsx)(e6,{})})]}),(0,n.jsx)(eG.x_,{}),(0,n.jsxs)(eG.$Q,{children:[(0,n.jsx)(eG.IB,{active:r.isActive("bulletList"),onClick:()=>r.chain().focus().toggleBulletList().run(),title:"Bullet list",children:(0,n.jsx)(e8,{})}),(0,n.jsx)(eG.IB,{active:r.isActive("orderedList"),onClick:()=>r.chain().focus().toggleOrderedList().run(),title:"Ordered list",children:(0,n.jsx)(e7,{})}),(0,n.jsx)(eG.IB,{active:r.isActive("taskList"),onClick:()=>r.chain().focus().toggleTaskList().run(),title:"Task list",children:(0,n.jsx)(e9,{})})]}),(0,n.jsx)(eG.x_,{}),(0,n.jsxs)(eG.$Q,{children:[(0,n.jsx)(eG.IB,{active:r.isActive("blockquote"),onClick:()=>r.chain().focus().toggleBlockquote().run(),title:"Blockquote",children:(0,n.jsx)(te,{})}),(0,n.jsx)(eG.IB,{active:r.isActive("codeBlock"),onClick:()=>r.chain().focus().toggleCodeBlock().run(),title:"Code block",children:(0,n.jsx)(tt,{})}),(0,n.jsx)(eG.IB,{active:!1,onClick:()=>r.chain().focus().setHorizontalRule().run(),title:"Horizontal rule",children:(0,n.jsx)(tr,{})})]}),(0,n.jsx)(eG.x_,{}),(0,n.jsxs)(eG.$Q,{children:[(0,n.jsx)(eG.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)(tn,{})}),(0,n.jsx)(eG.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)(to,{})}),(0,n.jsx)(eG.IB,{active:!1,onClick:()=>r.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),title:"Insert table",children:(0,n.jsx)(tl,{})})]})]})}let eZ=[{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 eQ(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=eZ.find(e=>e.level>0&&r.isActive("heading",{level:e.level})))?t:eZ[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)(ta,{})]}),l&&(0,n.jsx)("div",{className:"rich-doc-style-menu",children:eZ.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 eX=[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 e0(e){let{onSelect:t}=e;return(0,n.jsx)("div",{className:"rich-doc-color-palette",children:eX.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 e1(){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 e2(){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 e4(){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 e5(){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 e3(){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 e6(){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 e8(){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 e7(){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 e9(){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 te(){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 tt(){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 tr(){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 tn(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 to(){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 tl(){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 ta(){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 ts(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 ti(){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 tc(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"})]})}let td=new Set(["xlsx","xls","xlsb","xlsm","xltx","xltm","ods","fods","csv","tsv","numbers"]);function tu(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)(tp,{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)(th,{line:e}):e||" "})]},t))})})})]})}function tp(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 th(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)(tm,{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 tm(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]})}let tx=new Set(["jpg","jpeg","png","gif","webp","svg","bmp","avif","heic","heif","ico","tiff","tif"]),tf=new Set(["mp4","webm","mov","avi","mkv"]),tv=new Set(["mp3","wav","ogg","m4a","aac","flac"]),tg=new Set(["pdf"]);function ty(){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 tb(){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 tj(){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 tk(){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 tw(e){switch(e){case"image":return"#60a5fa";case"video":return"#c084fc";case"audio":return"#f59e0b";case"pdf":return"#ef4444"}}function tN(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)(tL,{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(tw(o),"18"),color:tw(o),border:"1px solid ".concat(tw(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)(tb,{})}),(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)(ty,{})})]})]}),(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)(tC,{url:t,filename:r}),"video"===o&&(0,n.jsx)(tS,{url:t}),"audio"===o&&(0,n.jsx)(tM,{url:t,filename:r}),"pdf"===o&&(0,n.jsx)(tT,{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 tC(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)(tk,{})}),(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)(tj,{})})]}),(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 tS(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 tM(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 tT(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 tL(e){let{mediaType:t}=e,r=tw(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 tI(e,t){switch(t.type){case"loading":{let r=e.order.includes(t.id)?e.order:[...e.order,t.id],n=e.entries[t.id];return{order:t_(r),entries:{...e.entries,[t.id]:{generation:t.generation,content:null==n?void 0:n.content}}}}case"set":{let r=e.entries[t.id];if(r&&r.generation!==t.generation)return e;return{order:t_(e.order.includes(t.id)?e.order.filter(e=>e!==t.id).concat(t.id):[...e.order,t.id]),entries:{...e.entries,[t.id]:{generation:t.generation,content:t.content}}}}case"drop":{if(!(t.id in e.entries))return e;let{[t.id]:r,...n}=e.entries;return{order:e.order.filter(e=>e!==t.id),entries:n}}case"clear":if(0===e.order.length)return e;return{order:[],entries:{}}}}function t_(e){return e.length<=20?e:e.slice(e.length-20)}let tR={order:[],entries:{}};function tE(e){switch(e){case"directory":case"browse":case"cron-dashboard":case"cron-job":case"skills":case"integrations":case"cloud":case"crm-inbox":case"crm-calendar":case"crm-person":case"crm-company":return!0;default:return!1}}async function tD(e,t){switch(e.kind){case"object":return tA(e,t);case"document":return tF(e,t);case"database":return{kind:"database",dbPath:e.path,filename:e.title};case"report":return{kind:"report",reportPath:e.path,filename:e.title};case"app":return tB(e,t);case"file":return tP(e,t);default:return{kind:"none"}}}async function tA(e,t){var r;let n=null!=(r=e.path.split("/").pop())?r:e.path,o=async()=>{let e=await fetch("/api/workspace/objects/".concat(encodeURIComponent(n)),{signal:t});return e.ok?{status:"ok",data:await e.json()}:"DUCKDB_NOT_INSTALLED"===(await e.json().catch(()=>({}))).code?{status:"duckdb-missing"}:404===e.status||e.status>=500?{status:"retryable"}:{status:"fatal"}},l=await o();if("retryable"===l.status&&(await tW(150,t),l=await o()),"duckdb-missing"===l.status)return{kind:"duckdb-missing"};if("ok"!==l.status)return{kind:"none"};let a=l.data;if(0===a.fields.length&&a.entries.length>0){await tW(200,t);let e=await o();if("duckdb-missing"===e.status)return{kind:"duckdb-missing"};"ok"===e.status&&(a=e.data)}return{kind:"object",data:a}}async function tF(e,t){let r=await fetch((0,Z.kb)(e.path),{signal:t});return r.ok?{kind:"document",data:await r.json(),title:e.title.replace(/\.md$/,"")}:{kind:"none"}}async function tP(e,t){var n,o,l,a;let s=e.title,i=e.path;if(function(e){var t,r;let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return td.has(n)}(s))return{kind:"spreadsheet",url:(0,Z.oj)(i),filename:s,filePath:i};if(function(e){var t,r;let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return"docx"===n||"doc"===n}(s)){let e=await fetch((0,Z.oj)(i),{signal:t});if(!e.ok)return{kind:"none"};let n=await e.arrayBuffer();if(t.aborted)return{kind:"none"};let o=await Promise.all([r.e(65360),r.e(14995)]).then(r.t.bind(r,14995,19)),l=await o.convertToHtml({arrayBuffer:n});return t.aborted?{kind:"none"}:{kind:"richDocument",html:l.value,filePath:i,mode:"docx"}}if((null==(l=s.split(".").pop())?void 0:l.toLowerCase())==="txt"){let e=await fetch((0,Z.kb)(i),{signal:t});return e.ok?{kind:"richDocument",html:(a=(await e.json()).content).trim()?a.split("\n").map(e=>"<p>".concat(e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")||"<br>","</p>")).join(""):"<p></p>",filePath:i,mode:"txt"}:{kind:"none"}}let c=null!=(o=null==(n=s.split(".").pop())?void 0:n.toLowerCase())?o:"";if("html"===c||"htm"===c)return{kind:"html",rawUrl:(0,Z.oj)(i),contentUrl:(0,Z.kb)(i),filename:s};let d=function(e){var t,r;let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return tx.has(n)?"image":tf.has(n)?"video":tv.has(n)?"audio":tg.has(n)?"pdf":null}(s);if(d)return{kind:"media",url:(0,Z.oj)(i),mediaType:d,filename:s,filePath:i};let u=await fetch((0,Z.kb)(i),{signal:t});if(!u.ok)return{kind:"none"};let p=await u.json();return!function(e){var t,r;let n=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"";return eM.has(n)}(s)?{kind:"file",data:p,filename:s}:{kind:"code",data:p,filename:s,filePath:i}}async function tB(e,t){let r=await fetch("/api/apps?app=".concat(encodeURIComponent(e.path),"&file=.dench.yaml&meta=1"),{signal:t}),n={name:e.title};if(r.ok)try{n=await r.json()}catch(e){}return{kind:"app",appPath:e.path,manifest:n,filename:e.title}}function tW(e,t){return new Promise((r,n)=>{if(t.aborted)return void n(new DOMException("Aborted","AbortError"));let o=setTimeout(r,e);t.addEventListener("abort",()=>{clearTimeout(o),n(new DOMException("Aborted","AbortError"))},{once:!0})})}function tO(e){var t;let{tabsState:r,activeContentTab:l,fileTreeCollapsed:a,enhancedTree:s,effectiveParentDir:i,browseDir:c,workspaceRoot:d,fileSearchFn:u,entryModal:p,tree:h,cronJobs:m,onTreeNodeSelect:x,onTreeRefresh:f,onTreeNavigateUp:v,onTreeExternalDrop:g,onTreeFileSearchSelect:y,onTreeGoHome:b,onSetFileTreeCollapsed:j,onSetRightPanelCollapsed:k,onActivateContent:w,onCloseContent:N,onCloseOtherContent:C,onCloseContentToRight:S,onCloseAllContent:M,onDuckDBMissing:T,onRefreshActiveChange:L,renderContent:I,renderEntryDetail:_,renderPlaceholder:R}=e,{content:E,refreshActive:D}=function(e,t){let[r,n]=(0,o.useReducer)(tI,tR),l=(0,o.useRef)(new Map),a=(0,o.useRef)(t.onDuckDBMissing);(0,o.useEffect)(()=>{a.current=t.onDuckDBMissing},[t.onDuckDBMissing]);let s=(0,o.useCallback)((e,t)=>{var r;let o=(null!=(r=l.current.get(e.id))?r:0)+1;l.current.set(e.id,o),n({type:"loading",id:e.id,generation:o}),(async()=>{try{let l=await tD(e,t);if(t.aborted)return;if("duckdb-missing"===l.kind){var r;null==(r=a.current)||r.call(a)}n({type:"set",id:e.id,content:l,generation:o})}catch(r){if(t.aborted||(null==r?void 0:r.name)==="AbortError")return;n({type:"set",id:e.id,content:{kind:"none"},generation:o})}})()},[]);(0,o.useEffect)(()=>{var t;if(!e||tE(e.kind)||(null==(t=r.entries[e.id])?void 0:t.content))return;let n=new AbortController;return s(e,n.signal),()=>n.abort()},[null==e?void 0:e.id,null==e?void 0:e.kind,s]);let i=(0,o.useMemo)(()=>{var n;if(!e)return{kind:"none"};if(tE(e.kind))return function(e,t){var r,n,o,l,a,s,i,c,d,u;switch(e.kind){case"directory":{let r=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.tree,e.path);if(r)return{kind:"directory",node:r};return{kind:"directory",node:{name:e.title,path:e.path,type:"folder"}}}case"browse":{let t=null!=(n=null==(r=e.meta)?void 0:r.browsePath)?n:e.path;return{kind:"directory",node:{name:e.title,path:t,type:"folder"}}}case"cron-dashboard":return{kind:"cron-dashboard"};case"cron-job":{let r=null!=(l=null==(o=e.meta)?void 0:o.cronJobId)?l:e.path.replace(/^~cron\//,""),n=t.cronJobs.find(e=>e.id===r);if(n)return{kind:"cron-job",jobId:r,job:n};return{kind:"cron-dashboard"}}case"skills":return{kind:"skill-store"};case"integrations":return{kind:"integrations"};case"cloud":return{kind:"cloud"};case"crm-inbox":return{kind:"crm-inbox"};case"crm-calendar":return{kind:"crm-calendar"};case"crm-person":return{kind:"crm-person",entryId:null!=(i=null==(a=e.meta)?void 0:a.entryId)?i:"",profileTab:null==(s=e.meta)?void 0:s.profileTab};case"crm-company":return{kind:"crm-company",entryId:null!=(u=null==(c=e.meta)?void 0:c.entryId)?u:"",profileTab:null==(d=e.meta)?void 0:d.profileTab};default:return{kind:"none"}}}(e,{tree:t.tree,cronJobs:t.cronJobs});let o=r.entries[e.id];return o&&null!=(n=o.content)?n:{kind:"loading"}},[e,r,t.tree,t.cronJobs]),c=(0,o.useCallback)(()=>{!e||tE(e.kind)||s(e,new AbortController().signal)},[e,s]);return{content:i,refreshActive:c,dropFromCache:(0,o.useCallback)(e=>{n({type:"drop",id:e})},[]),clearCache:(0,o.useCallback)(()=>{n({type:"clear"})},[])}}(l,{tree:h,cronJobs:m,onDuckDBMissing:T});(0,o.useEffect)(()=>{null==L||L(D)},[D,L]);let A=null!=(t=null==l?void 0:l.path)?t:null;return(0,n.jsxs)("div",{className:"flex h-full min-h-0 overflow-hidden",children:[!a&&(0,n.jsx)(tz,{enhancedTree:s,activePath:A,effectiveParentDir:i,browseDir:c,workspaceRoot:d,fileSearchFn:u,onTreeNodeSelect:x,onTreeRefresh:f,onTreeNavigateUp:v,onTreeExternalDrop:g,onTreeFileSearchSelect:y,onTreeGoHome:b,onCollapse:()=>j(!0)}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col min-h-0 min-w-0 overflow-hidden",children:[(0,n.jsx)(tU,{tabs:r.contentTabs,activeContentId:r.activeContentId,fileTreeCollapsed:a,onShowFileTree:()=>j(!1),onCollapseRightPanel:()=>k(!0),onActivate:w,onClose:N,onCloseOthers:C,onCloseToRight:S,onCloseAll:M}),p?(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:_(p)}):l&&"none"!==E.kind?(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:I(E,l)}):(0,n.jsx)("div",{className:"flex-1 min-w-0 flex items-center justify-center",children:R()})]})]})}function tz(e){let{enhancedTree:t,activePath:r,effectiveParentDir:o,browseDir:l,workspaceRoot:a,fileSearchFn:s,onTreeNodeSelect:i,onTreeRefresh:c,onTreeNavigateUp:d,onTreeExternalDrop:u,onTreeFileSearchSelect:p,onTreeGoHome:h,onCollapse:m}=e;return(0,n.jsxs)("div",{className:"flex flex-col min-h-0 shrink-0 border-r overflow-hidden",style:{width:240,minWidth:240,borderColor:"var(--color-border)"},children:[p&&(0,n.jsxs)("div",{className:"px-2 pt-2 pb-1 shrink-0 flex items-center gap-1",children:[(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(A,{onSelect:p,searchFn:s})}),(0,n.jsx)("button",{type:"button",onClick:m,className:"p-1 rounded-md cursor-pointer shrink-0",style:{color:"var(--color-text-muted)"},title:"Hide files (⌘E)",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","aria-hidden":!0,children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),l&&(0,n.jsxs)("div",{className:"px-3 py-2 border-b flex items-center gap-2 shrink-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("span",{className:"shrink-0",style:{color:"var(--color-text-muted)"},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:"M6 14l1.45-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2"})})}),(0,n.jsx)("span",{className:"text-[12px] font-medium truncate flex-1 min-w-0",style:{color:"var(--color-text)"},title:l,children:l.split("/").pop()||l}),h&&(0,n.jsx)("button",{type:"button",onClick:h,className:"p-1 rounded-md shrink-0 transition-colors cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Return to workspace",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 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.jsx)("div",{className:"flex-1 overflow-y-auto px-1 py-2",children:(0,n.jsx)(eN,{tree:t,activePath:r,onSelect:i,onRefresh:c,parentDir:o,onNavigateUp:d,browseDir:l,workspaceRoot:a,onExternalDrop:u})})]})}function tU(e){let{tabs:t,activeContentId:r,fileTreeCollapsed:l,onShowFileTree:a,onCollapseRightPanel:s,onActivate:i,onClose:c,onCloseOthers:d,onCloseToRight:u,onCloseAll:p}=e,h=(0,o.useCallback)((e,t)=>{e.stopPropagation(),c(t)},[c]);return(0,n.jsxs)("div",{className:"flex items-center h-10 shrink-0 border-b min-w-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsxs)("div",{className:"no-scrollbar flex-1 flex items-center gap-1 px-2 min-w-0 h-full overflow-x-auto",children:[l&&(0,n.jsxs)("button",{type:"button",onClick:a,className:"flex items-center gap-1.5 px-2 py-1 rounded-md cursor-pointer shrink-0 text-[12px] font-medium",style:{color:"var(--color-text-muted)"},title:"Show files (⌘E)",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","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M4 4h5l2 2h9a1 1 0 0 1 1 1v11a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z"})}),"Files"]}),t.map((e,o)=>{let l=e.id===r,a=o<t.length-1,s=t.length>1,m=e.title.length>24?e.title.slice(0,22)+"…":e.title;return(0,n.jsxs)(B,{children:[(0,n.jsx)(W,{asChild:!0,children:(0,n.jsxs)("div",{className:"flex items-center rounded-md shrink-0",style:{background:l?"var(--color-surface-hover)":"transparent"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>i(e.id),className:"flex items-center gap-1.5 pl-2 pr-1 py-1 text-[12px] font-medium transition-colors cursor-pointer",style:{color:l?"var(--color-text)":"var(--color-text-muted)",fontStyle:e.preview?"italic":"normal"},title:e.title,children:[(0,n.jsx)("span",{className:"shrink-0",style:{opacity:l?1:.8},children:(0,n.jsx)(eS,{tab:e})}),(0,n.jsx)("span",{children:m})]}),(0,n.jsx)("button",{type:"button",onClick:t=>h(t,e.id),className:"p-0.5 rounded-md mr-0.5 cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Close tab",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-border)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(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:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]})}),(0,n.jsxs)(O,{children:[(0,n.jsx)(z,{onSelect:()=>c(e.id),children:"Close"}),(0,n.jsx)(z,{onSelect:()=>d(e.id),disabled:!s,children:"Close other tabs"}),(0,n.jsx)(z,{onSelect:()=>u(e.id),disabled:!a,children:"Close tabs to the right"}),(0,n.jsx)(U,{}),(0,n.jsx)(z,{onSelect:p,children:"Close all tabs"})]})]},e.id)})]}),(0,n.jsx)("button",{type:"button",onClick:s,className:"p-1.5 mr-1 rounded-md cursor-pointer shrink-0",style:{color:"var(--color-text-muted)"},title:"Hide right panel (⌘⇧B)",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","aria-hidden":!0,children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M15 3v18"})]})})]})}var tH=r(50890),tV=r(76552),tK=r(42282),tJ=r(24285),tq=r(98832),tG=r(30520);function t$(e){let{src:t,className:r}=e;return(0,n.jsx)("img",{src:t,alt:"","aria-hidden":"true",className:null!=r?r:"w-4 h-4 rounded-[4px] shrink-0"})}function tY(e,t,r){return(0,tq.IL)(e.getValue(t),r).passed}let tZ=new Set(["__rownum","select","actions","__add_column"]);function tQ(e){return e instanceof HTMLElement&&!!e.closest("input, textarea, select, button, a, [contenteditable='true'], [role='button']")}function tX(e,t,r){if(!e||0===r||0===t.length)return null;let n=t.indexOf(e.anchor.columnId),o=t.indexOf(e.focus.columnId);if(n<0||o<0)return null;let l=Math.max(0,Math.min(e.anchor.rowIndex,e.focus.rowIndex)),a=Math.min(r-1,Math.max(e.anchor.rowIndex,e.focus.rowIndex));return{rowStart:l,rowEnd:a,colStart:Math.min(n,o),colEnd:Math.max(n,o)}}function t0(e){let{id:t,children:r,style:o,className:l}=e,{attributes:a,listeners:s,setNodeRef:i,transform:c,transition:d,isDragging:u}=(0,tK.gl)({id:t}),p={...o,transform:tJ.Ks.Translate.toString(c),transition:d,opacity:u?.5:1};return(0,n.jsx)("th",{ref:i,style:p,className:l,...a,children:r(s)})}function t1(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 t2(e){var t;let{columns:r,data:l,loading:a=!1,searchPlaceholder:s="Search...",enableGlobalFilter:i=!0,enableSorting:c=!0,enableRowSelection:d=!1,rowSelection:u,onRowSelectionChange:p,enableCellSelection:m=!1,cellSelection:x,onCellSelectionChange:f,bulkActions:v,enableColumnReordering:g=!1,onColumnReorder:y,initialColumnVisibility:b,onColumnVisibilityChanged:j,initialColumnSizing:k,onColumnSizingChange:w,pageSize:N=100,onRefresh:C,onAdd:S,addButtonLabel:M="+ Add",onRowClick:T,getFirstDataColumnFaviconUrl:L,rowActions:I,rowActionsHeader:_,toolbarExtra:R,title:E,titleIcon:D,stickyFirstColumn:A=!0,activeRowId:F,getRowId:P,serverPagination:B,onServerSearch:W,onSortChange:O,disableHeaderClickSort:z=!1,hideToolbar:U=!1,globalFilter:H,onGlobalFilterChange:V,stickyFirstColumnValue:K,onStickyFirstColumnChange:J}=e,[q,$]=(0,o.useState)([]),[Y,Z]=(0,o.useState)(""),Q=void 0!==H?H:Y,X=(0,o.useCallback)(e=>{let t="function"==typeof e?e(Q):e;V?V(t):Z(t)},[Q,V]),[ee,et]=(0,o.useState)([]),[er,en]=(0,o.useState)(null!=b?b:{}),[eo,el]=(0,o.useState)(null!=k?k:{});(0,o.useEffect)(()=>{en(null!=b?b:{})},[b]),(0,o.useEffect)(()=>{el(null!=k?k:{})},[k]);let[ea,es]=(0,o.useState)({}),[ei,ec]=(0,o.useState)(null),[ed,eu]=(0,o.useState)(A),ep=void 0!==K?K:ed,eh=(0,o.useCallback)(e=>{let t="function"==typeof e?e(ep):e;J?J(t):eu(t)},[ep,J]),[em,ex]=(0,o.useState)(!1),[ef,ev]=(0,o.useState)({pageIndex:0,pageSize:N}),eg=(0,o.useRef)(null),ey=void 0!==u?u:ea,eb=void 0!==x?x:ei,ej=(0,o.useCallback)(e=>{void 0===x&&ec(e),null==f||f(e)},[x,f]),ek=(0,o.useCallback)(e=>"id"in e&&"string"==typeof e.id?e.id:"accessorKey"in e&&"string"==typeof e.accessorKey?e.accessorKey:"",[]),ew=(0,o.useCallback)(e=>{let t=e.map(ek),r=[];return r.push("__rownum"),d&&r.push("select"),r.push(...t),I&&r.push("actions"),r},[ek,d,I]),[eN,eC]=(0,o.useState)(()=>ew(r)),eS=new Set(["__rownum","select","actions","__add_column"]);(0,o.useEffect)(()=>{eC(e=>{let t=ew(r),n=new Set(t),o=new Set(t.filter(e=>!eS.has(e))),l=e.filter(e=>!eS.has(e)&&o.has(e)),a=new Set(l);for(let e of o)a.has(e)||l.push(e);let s=[];return(n.has("__rownum")&&s.push("__rownum"),n.has("select")&&s.push("select"),s.push(...l),n.has("actions")&&s.push("actions"),n.has("__add_column")&&s.push("__add_column"),s.length===e.length&&s.every((t,r)=>t===e[r]))?e:s})},[r,ew]);let eM=(0,G.FR)((0,G.MS)(G.AN,{activationConstraint:{distance:5}})),eT=(0,o.useCallback)(e=>{let{active:t,over:r}=e;r&&t.id!==r.id&&eC(e=>{let n=e.indexOf(t.id),o=e.indexOf(r.id),l=(0,tK.be)(e,n,o);return null==y||y(l),l})},[y]),eL=(0,o.useRef)(!1),eI=(0,o.useRef)(null),e_=(0,o.useCallback)(e=>{let t=e.currentTarget.scrollLeft>0;t!==eL.current&&(eL.current=t,null==eI.current&&(eI.current=requestAnimationFrame(()=>{eI.current=null,ex(eL.current)})))},[]);(0,o.useEffect)(()=>()=>{null!=eI.current&&cancelAnimationFrame(eI.current)},[]);let eR=null==B?void 0:B.page,eE=null==B?void 0:B.pageSize,eD=(0,o.useMemo)(()=>({id:"__rownum",header:()=>(0,n.jsx)("span",{className:"text-[10px] tabular-nums opacity-50",style:{color:"var(--color-text-muted)"},children:"#"}),cell:e=>{let{row:t}=e,r=null!=eR&&null!=eE?(eR-1)*eE:0;return(0,n.jsx)("span",{className:"text-[11px] tabular-nums",style:{color:"var(--color-text-muted)",opacity:.55},children:r+t.index+1})},size:48,minSize:48,enableSorting:!1,enableHiding:!1,enableResizing:!1}),[eR,eE]),eA=(0,o.useMemo)(()=>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,minSize:40,enableSorting:!1,enableHiding:!1}:null,[d]),eF=(0,o.useRef)(I);eF.current=I;let eP=(0,o.useRef)(_);eP.current=_;let eB=!!I,eW=(0,o.useMemo)(()=>eB?{id:"actions",header:()=>{var e;return null!=(e=eP.current)?e:null},cell:e=>{var t,r;let{row:o}=e;return(0,n.jsx)(t8,{row:o.original,actions:null!=(r=null==(t=eF.current)?void 0:t.call(eF,o.original))?r:[]})},size:48,minSize:48,enableSorting:!1,enableHiding:!1,enableResizing:!1}:null,[eB]),eO=(0,o.useMemo)(()=>{let e=[];return e.push(eD),eA&&e.push(eA),e.push(...r),eW&&e.push(eW),e},[r,eA,eW,eD]),ez=(0,o.useMemo)(()=>B?{pageIndex:B.page-1,pageSize:B.pageSize}:void 0,[null==B?void 0:B.page,null==B?void 0:B.pageSize]),eU=(0,o.useRef)(null),eH=(0,tH.N4)({data:l,columns:eO,state:{sorting:q,globalFilter:Q,columnFilters:ee,columnVisibility:er,columnSizing:eo,rowSelection:ey,columnOrder:g?eN:void 0,pagination:null!=ez?ez:ef},onSortingChange:e=>{let t="function"==typeof e?e(q):e;$(t),null==O||O(t)},onGlobalFilterChange:X,onColumnFiltersChange:et,onColumnVisibilityChange:e=>{let t="function"==typeof e?e(er):e;en(t),null==j||j(t)},onColumnSizingChange:e=>{let t="function"==typeof e?e(eo):e;el(t),eU.current&&clearTimeout(eU.current),eU.current=setTimeout(()=>null==w?void 0:w(t),500)},onRowSelectionChange:e=>{p?p(e):es(e)},onPaginationChange:B?e=>{let t="function"==typeof e?e(ez):e;t.pageSize!==B.pageSize?B.onPageSizeChange(t.pageSize):t.pageIndex!==B.page-1&&B.onPageChange(t.pageIndex+1)}:ev,getCoreRowModel:(0,tV.HT)(),getSortedRowModel:c?(0,tV.h5)():void 0,getFilteredRowModel:B?void 0:(0,tV.hM)(),getPaginationRowModel:B?void 0:(0,tV.kW)(),...B?{manualPagination:!0,pageCount:Math.ceil(B.totalCount/B.pageSize)}:{},enableRowSelection:d,enableSorting:c,globalFilterFn:tY,columnResizeMode:"onChange",defaultColumn:{minSize:150}}),eV=Object.keys(ey).filter(e=>ey[e]).length,eK=eH.getVisibleFlatColumns().filter(e=>"__rownum"!==e.id&&"select"!==e.id&&"actions"!==e.id&&"__add_column"!==e.id),eJ=eH.getVisibleLeafColumns().map(e=>e.id).filter(e=>!tZ.has(e)),eq=eH.getRowModel().rows.length,eG=m&&eq>0&&eJ.length>0,e$=(0,o.useMemo)(()=>eN.filter(e=>!eS.has(e)),[eN]),eY=eH.getState().columnSizing,eZ=!!eH.getState().columnSizingInfo.isResizingColumn,eQ=(0,o.useMemo)(()=>{let e=eH.getFlatHeaders(),t={};for(let r of e)t["--header-".concat(r.id,"-size")]=r.getSize(),t["--col-".concat(r.column.id,"-size")]=r.column.getSize();return t},[eY,eZ,er,eN]);(0,o.useEffect)(()=>{eb&&(tX(eb,eJ,eq)||ej(null))},[eb,ej,eJ,eq]),(0,o.useEffect)(()=>{var e,t;eb&&(null==(t=eg.current)||null==(e=t.querySelector("[data-dt-cell-active='true']"))||e.scrollIntoView({block:"nearest",inline:"nearest"}))},[eb]);let eX=(0,o.useMemo)(()=>{let e=tX(eb,eJ,eq),t=new Map;if(!e)return t;let r=eJ.slice(e.colStart,e.colEnd+1);for(let n=e.rowStart;n<=e.rowEnd;n++)t.set(n,r);return t},[eb,eJ,eq]),e0=(0,o.useCallback)((e,t,r)=>{var n;if(!eG||0!==r.button||tQ(r.target))return;r.preventDefault(),r.stopPropagation(),null==(n=eg.current)||n.focus({preventScroll:!0});let o={rowIndex:e,columnId:t};ej(r.shiftKey&&eb?{anchor:eb.anchor,focus:o}:{anchor:o,focus:o})},[eG,eb,ej]),e1=(0,o.useCallback)(e=>{var t;if(!eG||tQ(e.target))return;if("Escape"===e.key&&eb){e.preventDefault(),ej(null);return}let r={ArrowUp:{row:-1,col:0},ArrowDown:{row:1,col:0},ArrowLeft:{row:0,col:-1},ArrowRight:{row:0,col:1}}[e.key];if(!r)return;e.preventDefault();let n=null!=(t=null==eb?void 0:eb.focus)?t:{rowIndex:0,columnId:eJ[0]},o=Math.max(0,eJ.indexOf(n.columnId)),l={rowIndex:Math.min(Math.max(n.rowIndex+r.row,0),eq-1),columnId:eJ[Math.min(Math.max(o+r.col,0),eJ.length-1)]};ej({anchor:e.shiftKey&&eb?eb.anchor:l,focus:l})},[eG,eb,ej,eJ,eq]);return(0,n.jsxs)("div",{className:"w-full h-full flex flex-col overflow-hidden",style:{overscrollBehavior:"contain"},children:[!U&&(0,n.jsxs)("div",{className:"flex items-center gap-3 px-3 py-2 shrink-0 flex-wrap backdrop-blur-md",style:{background:"var(--color-glass)",borderBottom:"1px solid var(--color-border)"},children:[E&&(0,n.jsxs)("div",{className:"flex items-center gap-2 mr-1",children:[D,(0,n.jsx)("span",{className:"text-xs font-semibold",style:{color:"var(--color-text)"},children:E})]}),i&&(0,n.jsxs)("div",{className:"flex min-w-[140px] max-w-[260px] flex-[1_1_180px] items-center gap-2 h-8 px-3 backdrop-blur-sm rounded-full focus-within:ring-2 focus-within:ring-(--color-accent)/30 transition-shadow shadow-[0_0_21px_0_rgba(0,0,0,0.05)]",style:{border:"1px solid var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",style:{color:"var(--color-text-muted)",opacity:.5},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:Q,onChange:e=>{X(e.target.value),null==W||W(e.target.value)},placeholder:s,className:"w-full h-full text-xs bg-transparent outline-none border-0 p-0",style:{color:"var(--color-text)"}}),Q&&(0,n.jsx)("button",{type:"button",onClick:()=>{X(""),null==W||W("")},className:"shrink-0 h-5 w-5 rounded-full flex items-center justify-center cursor-pointer transition-colors",style:{color:"var(--color-text-muted)"},children:(0,n.jsxs)("svg",{width:"11",height:"11",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"})]})})]}),eV>0&&v&&(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:[eV," selected"]}),v]}),(0,n.jsxs)("div",{className:"ml-auto flex min-w-0 max-w-full flex-[1_1_220px] flex-wrap items-center justify-end gap-2",children:[R,(0,n.jsxs)(tG.rI,{children:[(0,n.jsxs)(tG.ty,{className:"h-8 px-3 flex items-center gap-1.5 rounded-full text-xs cursor-pointer transition-colors backdrop-blur-sm shadow-[0_0_21px_0_rgba(0,0,0,0.05)] outline-none focus:outline-none",style:{color:"var(--color-text-muted)",border:"1px solid var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",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"]}),(0,n.jsxs)(tG.SQ,{align:"end",sideOffset:6,children:[(0,n.jsx)(tG.hO,{checked:ep,onSelect:()=>eh(e=>!e),children:"Freeze first column"}),(0,n.jsx)(tG.mB,{}),0===eK.length?(0,n.jsx)("div",{className:"px-2 py-1.5 text-xs opacity-50",children:"No toggleable columns"}):eH.getAllLeafColumns().filter(e=>"__rownum"!==e.id&&"select"!==e.id&&"actions"!==e.id&&"__add_column"!==e.id&&e.getCanHide()).map(e=>{var t,r;return(0,n.jsx)(tG.hO,{checked:e.getIsVisible(),onSelect:()=>e.toggleVisibility(!e.getIsVisible()),children:"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)})]})]}),C&&(0,n.jsx)("button",{type:"button",onClick:C,className:"h-8 w-8 rounded-full flex items-center justify-center cursor-pointer transition-colors backdrop-blur-sm shadow-[0_0_21px_0_rgba(0,0,0,0.05)]",style:{border:"1px solid var(--color-border)",background:"var(--color-surface)",color:"var(--color-text-muted)"},children:(0,n.jsxs)("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:"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 21h5v-5"})]})}),S&&(0,n.jsx)("button",{type:"button",onClick:S,className:"h-8 px-3 flex items-center gap-1.5 rounded-full text-xs font-medium cursor-pointer transition-colors shadow-[0_0_21px_0_rgba(0,0,0,0.05)]",style:{background:"var(--color-accent)",color:"#fff"},children:M})]})]}),(0,n.jsx)("div",{ref:eg,className:"overflow-auto flex-1 min-h-0 max-h-full relative",onScroll:e_,onKeyDown:e1,tabIndex:eG?0:void 0,style:{overscrollBehavior:"contain"},children:a?(0,n.jsx)(t7,{columnCount:eO.length}):(0,n.jsx)(G.Mp,{sensors:eM,collisionDetection:G.fp,onDragEnd:eT,children:(0,n.jsxs)("table",{className:"w-full caption-bottom text-sm",style:{...eQ,tableLayout:"fixed",minWidth:eH.getTotalSize()},children:[(0,n.jsx)("thead",{className:"[&_tr]:border-b sticky top-0 z-30",style:{background:"var(--color-surface)"},children:eH.getHeaderGroups().map(e=>(0,n.jsx)("tr",{style:{borderColor:"var(--color-border)"},className:"border-b-2 backdrop-blur-sm",children:(0,n.jsx)(tK.gB,{items:e$,strategy:tK.m$,children:e.headers.map((t,r)=>{let o=1+ +!!d,l="__rownum"===t.id,a=ep&&r===o,s="select"===t.id,i="actions"===t.id,c="__add_column"===t.id,u=i||c,p=t.column.getCanSort(),m=t.column.getIsSorted(),x=r===e.headers.length-1,f={background:"var(--color-surface)",position:"sticky",top:0,zIndex:u?32:a||s?31:30,...a?{left:40*!!d,boxShadow:em?"4px 0 12px -2px rgba(0,0,0,0.15), 2px 0 4px -1px rgba(0,0,0,0.08)":"none"}:{},...s?{left:0,position:"sticky",zIndex:31,width:40}:{},...u?{right:0,position:"sticky",zIndex:32}:{},width:"calc(var(--header-".concat(t.id,"-size) * 1px)")},v=t.isPlaceholder?null:(0,tH.Kv)(t.column.columnDef.header,t.getContext()),y=(0,h.cn)("h-11 text-left align-middle font-medium text-[12px] whitespace-nowrap p-0 group select-none relative box-border",l&&"text-right",!x&&"border-r",a&&em&&"border-r-2!"),b=(0,h.cn)("flex items-center gap-1.5 h-full transition-colors",l?"px-3 justify-end":"px-4",p&&"cursor-pointer hover:bg-[var(--color-surface-hover)]",m&&"bg-[var(--color-surface-hover)]"),j=!s&&!c&&!l&&t.column.getCanResize()?(0,n.jsx)("div",{"data-resize-handle":!0,onMouseDown:t.getResizeHandler(),onTouchStart:t.getResizeHandler(),onDoubleClick:()=>t.column.resetSize(),onClick:e=>e.stopPropagation(),className:(0,h.cn)("dt-resize-handle",t.column.getIsResizing()&&"dt-resize-active")}):null;return!g||s||i||c||l?(0,n.jsxs)("th",{style:{...f,borderColor:"var(--color-border)"},className:y,children:[(0,n.jsxs)("span",{className:b,onClick:p&&!z?t.column.getToggleSortingHandler():void 0,style:{color:"var(--color-text-muted)"},children:[v,p&&(0,n.jsx)(t1,{direction:m})]}),j,a&&em&&(0,n.jsx)("div",{className:"absolute top-0 right-0 bottom-0 w-4 translate-x-full pointer-events-none bg-linear-to-r from-black/4 to-transparent z-100"})]},t.id):(0,n.jsx)(t0,{id:t.id,style:f,className:y,children:e=>(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:b,onClick:p&&!z?t.column.getToggleSortingHandler():void 0,style:{color:"var(--color-text-muted)",cursor:"grab"},...e,children:[v,p&&(0,n.jsx)(t1,{direction:m})]}),j,a&&em&&(0,n.jsx)("div",{className:"absolute top-0 right-0 bottom-0 w-4 translate-x-full pointer-events-none bg-linear-to-r from-black/4 to-transparent z-100"})]})},t.id)})})},e.id))}),0===l.length?(0,n.jsx)(t3,{columnCount:eH.getVisibleLeafColumns().length,isFiltered:!!Q}):(0,n.jsx)(t5,{table:eH,activeRowId:F,getRowId:P,enableRowSelection:d,stickyFirstColumn:ep,isScrolled:em,onRowClick:T,getFirstDataColumnFaviconUrl:L,selectedColumnsByRow:eX,activeCell:null!=(t=null==eb?void 0:eb.focus)?t:null,onCellMouseDown:e0})]})})}),!a&&l.length>0&&(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-1 text-[11px] shrink-0 backdrop-blur-xl",style:{borderTop:"1px solid var(--color-border)",color:"var(--color-text-muted)",background:"var(--color-glass)"},children:[(0,n.jsxs)("span",{className:"tabular-nums",children:[B?"".concat((B.page-1)*B.pageSize+1,"–").concat(Math.min(B.page*B.pageSize,B.totalCount)," / ").concat(B.totalCount):"".concat(eH.getRowModel().rows.length," / ").concat(l.length),eV>0&&" \xb7 ".concat(eV," selected")]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("select",{value:B?B.pageSize:ef.pageSize,onChange:e=>{let t=Number(e.target.value);B?B.onPageSizeChange(t):ev(e=>({...e,pageSize:t,pageIndex:0}))},className:"h-6 px-1.5 py-0 rounded-md text-[11px] outline-none transition-colors cursor-pointer",style:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)"},title:"Rows per page",children:[20,50,100,250,500].map(e=>(0,n.jsxs)("option",{value:e,children:[e,"/page"]},e))}),(0,n.jsxs)("span",{className:"tabular-nums min-w-[48px] text-center",children:[B?B.page:ef.pageIndex+1,"/",eH.getPageCount()]}),(0,n.jsx)("div",{className:"flex gap-0.5",children:B?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t6,{onClick:()=>B.onPageChange(1),disabled:B.page<=1,label:"\xab"}),(0,n.jsx)(t6,{onClick:()=>B.onPageChange(B.page-1),disabled:B.page<=1,label:"‹"}),(0,n.jsx)(t6,{onClick:()=>B.onPageChange(B.page+1),disabled:B.page>=Math.ceil(B.totalCount/B.pageSize),label:"›"}),(0,n.jsx)(t6,{onClick:()=>B.onPageChange(Math.ceil(B.totalCount/B.pageSize)),disabled:B.page>=Math.ceil(B.totalCount/B.pageSize),label:"\xbb"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t6,{onClick:()=>ev(e=>({...e,pageIndex:0})),disabled:!eH.getCanPreviousPage(),label:"\xab"}),(0,n.jsx)(t6,{onClick:()=>eH.previousPage(),disabled:!eH.getCanPreviousPage(),label:"‹"}),(0,n.jsx)(t6,{onClick:()=>eH.nextPage(),disabled:!eH.getCanNextPage(),label:"›"}),(0,n.jsx)(t6,{onClick:()=>ev(e=>({...e,pageIndex:eH.getPageCount()-1})),disabled:!eH.getCanNextPage(),label:"\xbb"})]})})]})]})]})}let t4=o.memo(function(e){let{row:t,rowIdx:r,isSelected:l,isActive:a,enableRowSelection:s,stickyFirstColumn:i,isScrolled:c,onRowClick:d,firstColumnFaviconUrl:u,selectedCellColumnIds:p,activeCellColumnId:m,onCellMouseDown:x}=e,f=t.getVisibleCells(),v=1+ +!!s,g=r%2==0?"var(--color-surface)":"var(--color-bg)",y=a||l?"var(--color-accent-light)":g,b=(0,o.useMemo)(()=>new Set(p?p.split("|"):[]),[p]),j=(0,o.useCallback)(()=>{null==d||d(t.original,r)},[d,t.original,r]),k=(0,o.useCallback)(e=>{l||a||(e.currentTarget.style.background="var(--color-surface-hover)")},[l,a]),w=(0,o.useCallback)(e=>{l||a||(e.currentTarget.style.background=g)},[l,a,g]);return(0,n.jsx)("tr",{"data-state":l?"selected":a?"active":void 0,className:(0,h.cn)("border-b transition-colors duration-100 group/row",d&&"cursor-pointer",l&&"data-[state=selected]:bg-(--color-accent-light)"),style:{borderColor:a?"var(--color-accent)":"var(--color-border)",background:y},onClick:j,onMouseEnter:k,onMouseLeave:w,children:f.map((e,o)=>{let l="__rownum"===e.column.id,a=o===v,d=i&&a,p="select"===e.column.id,g="actions"===e.column.id,j="__add_column"===e.column.id,k=!l&&!p&&!g&&!j,w=o===f.length-1,N=a&&!p?u:void 0,C=k&&b.has(e.column.id),S=k&&m===e.column.id,M=d&&c?"4px 0 12px -2px rgba(0,0,0,0.12), 2px 0 4px -1px rgba(0,0,0,0.06)":"",T=S?"inset 0 0 0 2px var(--color-accent)":C?"inset 0 0 0 1px color-mix(in srgb, var(--color-accent) 55%, transparent)":"",L={borderColor:"var(--color-border)",...C?{background:"color-mix(in srgb, var(--color-accent) 10%, var(--color-surface))"}:{},...M||T?{boxShadow:[M,T].filter(Boolean).join(", ")}:{},...d?{position:"sticky",left:40*!!s,zIndex:2,background:C?"color-mix(in srgb, var(--color-accent) 10%, var(--color-surface))":y}:{},...p?{position:"sticky",left:0,zIndex:2,background:y,width:40}:{},...g||j?{position:"sticky",right:0,zIndex:2,background:y}:{}};return(0,n.jsxs)("td",{"data-dt-cell-active":S?"true":void 0,"data-row-index":k?r:void 0,"data-column-id":k?e.column.id:void 0,className:(0,h.cn)("align-middle whitespace-nowrap text-[13px] border-b transition-colors box-border",l?"px-3 py-3 text-right":p?"px-3 py-3":"px-4 py-3",!w&&"border-r",d&&c&&"border-r-2!",k&&"cursor-cell select-none"),style:L,"aria-selected":C||void 0,onMouseDown:n=>{if(l&&s&&!tQ(n.target)){n.preventDefault(),n.stopPropagation(),t.toggleSelected(!t.getIsSelected());return}k&&(null==x||x(r,e.column.id,n))},onClick:e=>{(l||k)&&e.stopPropagation()},children:[(0,n.jsx)("div",{className:"overflow-hidden",children:N?(0,n.jsxs)("div",{className:"flex min-w-0 items-center gap-2",children:[(0,n.jsx)("span",{className:"pointer-events-none shrink-0",children:(0,n.jsx)(t$,{src:N})}),(0,n.jsx)("div",{className:"min-w-0 flex-1 overflow-hidden",children:(0,tH.Kv)(e.column.columnDef.cell,e.getContext())})]}):(0,tH.Kv)(e.column.columnDef.cell,e.getContext())}),d&&c&&(0,n.jsx)("div",{className:"absolute top-0 right-0 bottom-0 w-4 translate-x-full pointer-events-none bg-linear-to-r from-black/4 to-transparent z-100"})]},e.id)})})},(e,t)=>e.row.original===t.row.original&&e.rowIdx===t.rowIdx&&e.isSelected===t.isSelected&&e.isActive===t.isActive&&e.enableRowSelection===t.enableRowSelection&&e.stickyFirstColumn===t.stickyFirstColumn&&e.isScrolled===t.isScrolled&&e.onRowClick===t.onRowClick&&e.firstColumnFaviconUrl===t.firstColumnFaviconUrl&&e.selectedCellColumnIds===t.selectedCellColumnIds&&e.activeCellColumnId===t.activeCellColumnId&&e.onCellMouseDown===t.onCellMouseDown&&e.cellLayoutKey===t.cellLayoutKey),t5=o.memo(function(e){let{table:t,activeRowId:r,getRowId:o,enableRowSelection:l,stickyFirstColumn:a,isScrolled:s,onRowClick:i,getFirstDataColumnFaviconUrl:c,selectedColumnsByRow:d,activeCell:u,onCellMouseDown:p}=e,h=t.getVisibleLeafColumns().map(e=>e.id).join("|");return(0,n.jsx)("tbody",{className:"[&_tr:last-child]:border-0",children:t.getRowModel().rows.map((e,m)=>{var x,f,v;let g=e.getIsSelected(),y=null!=r&&null!=o&&o(e.original)===r,b=null!=(f=null==c?void 0:c(e,t))?f:void 0,j=null!=(v=null==(x=d.get(m))?void 0:x.join("|"))?v:"";return(0,n.jsx)(t4,{row:e,rowIdx:m,isSelected:g,isActive:y,enableRowSelection:l,stickyFirstColumn:a,isScrolled:s,onRowClick:i,firstColumnFaviconUrl:b,selectedCellColumnIds:j,activeCellColumnId:(null==u?void 0:u.rowIndex)===m?u.columnId:null,onCellMouseDown:p,cellLayoutKey:h},e.id)})})},(e,t)=>!!t.table.getState().columnSizingInfo.isResizingColumn&&e.table.options.data===t.table.options.data);function t3(e){let{columnCount:t,isFiltered:r}=e,o=Math.max(t,1);return(0,n.jsx)("tbody",{children:(0,n.jsx)("tr",{children:(0,n.jsx)("td",{colSpan:o,className:"p-0 border-0",children:(0,n.jsxs)("div",{className:"flex flex-col items-center gap-4 py-24 px-12",style:{position:"sticky",left:0,display:"inline-flex"},children:[(0,n.jsx)("div",{className:"rounded-full p-4 mb-2 backdrop-blur-sm",style:{background:"var(--color-glass)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-sm)"},children:(0,n.jsxs)("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",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.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("h3",{className:"text-base font-semibold mb-1",style:{color:"var(--color-text)"},children:"No results found"}),(0,n.jsx)("p",{className:"text-sm max-w-xs",style:{color:"var(--color-text-muted)"},children:r?"Try adjusting your search or filter criteria.":"No data available yet. Create your first entry to get started."})]})]})})})})}function t6(e){let{onClick:t,disabled:r,label:o}=e;return(0,n.jsx)("button",{type:"button",onClick:t,disabled:r,className:"h-6 w-6 rounded-md flex items-center justify-center text-[11px] disabled:opacity-30 cursor-pointer transition-colors",style:{color:"var(--color-text-muted)",border:"1px solid var(--color-border)",background:"var(--color-surface)"},dangerouslySetInnerHTML:{__html:o}})}function t8(e){let{row:t,actions:r}=e;return(0,n.jsxs)(tG.rI,{children:[(0,n.jsx)(tG.ty,{className:"p-1 rounded-md cursor-pointer",style:{color:"var(--color-text-muted)"},onClick:e=>e.stopPropagation(),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"})]})}),(0,n.jsx)(tG.SQ,{align:"end",sideOffset:4,children:r.map((e,r)=>(0,n.jsxs)(tG._2,{variant:"destructive"===e.variant?"destructive":"default",onSelect:()=>{var r;return null==(r=e.onClick)?void 0:r.call(e,t)},children:[e.icon,e.label]},r))})]})}function t7(e){let{columnCount:t}=e,r=["w-full","w-3/4","w-5/6","w-2/3"];return(0,n.jsxs)("div",{className:"w-full",children:[(0,n.jsx)("div",{className:"flex gap-0 border-b-2",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:Array.from({length:Math.min(t,6)}).map((e,r)=>(0,n.jsx)("div",{className:"flex-1 h-11 px-4 flex items-center",style:{borderRight:r<Math.min(t,6)-1?"1px solid var(--color-border)":"none"},children:(0,n.jsx)("div",{className:"h-3 w-16 rounded animate-pulse",style:{background:"var(--color-surface-hover)",animationDelay:"".concat(50*r,"ms"),animationDuration:"1.5s"}})},r))}),Array.from({length:15}).map((e,o)=>(0,n.jsx)("div",{className:"flex gap-0 border-b",style:{borderColor:"var(--color-border)"},children:Array.from({length:Math.min(t,6)}).map((e,l)=>(0,n.jsx)("div",{className:"flex-1 px-3 py-2.5 flex items-center",style:{borderRight:l<Math.min(t,6)-1?"1px solid var(--color-border)":"none"},children:(0,n.jsx)("div",{className:(0,h.cn)("h-3.5 rounded animate-pulse",r[(o+l)%r.length]),style:{background:"var(--color-surface-hover)",animationDelay:"".concat(50*o+30*l,"ms"),animationDuration:"1.5s"}})},l))},o))]})}function t9(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 re(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),[p,h]=(0,o.useState)(""),[m,x]=(0,o.useState)([]),[f,v]=(0,o.useState)(!1),[g,y]=(0,o.useState)(()=>t9(r)),b=(0,o.useRef)(null),j=(0,o.useRef)(null),k=(0,o.useRef)(null);(0,o.useEffect)(()=>{y(t9(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();x(null!=(r=e.options)?r:[])}}catch(e){}finally{v(!1)}},[t]);(0,o.useEffect)(()=>{d&&w(p)},[d]),(0,o.useEffect)(()=>{if(d)return k.current&&clearTimeout(k.current),k.current=setTimeout(()=>w(p),250),()=>{k.current&&clearTimeout(k.current)}},[p]),(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=m.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((0,M.A3)(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:p,onChange:e=>h(e.target.value),placeholder:"Search ".concat((0,M.PV)(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===m.length?(0,n.jsx)("div",{className:"px-3 py-4 text-center text-xs",style:{color:"var(--color-text-muted)"},children:p?"No matches found":"No entries"}):m.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 rt=r(68840);let rr=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,rn=/^https?:\/\/\S+$/i,ro=/^\+?[0-9().\-\s]{7,}$/,rl=/^\d{4}-\d{2}-\d{2}$/,ra=/^\d{4}-\d{2}-\d{2}(?:[T\s]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}(?::?\d{2})?)?)?$/,rs=/^\d{1,2}\/\d{1,2}\/\d{2,4}$/,ri=/^([$\u20ac\u00a3\u00a5])\s*(-?\d[\d,]*(?:\.\d+)?)$/,rc=/^-?\d[\d,]*(?:\.\d+)?$/,rd=new Set(["jpg","jpeg","png","gif","webp","svg","bmp","avif","heic","heif","ico","tiff","tif"]),ru=new Set(["mp4","webm","mov","avi","mkv"]),rp=new Set(["mp3","wav","ogg","m4a","aac","flac"]),rh=new Set(["pdf"]),rm=new Set([...rd,...ru,...rp,...rh,"txt","md","json","yaml","yml","csv","sql","doc","docx","xls","xlsx","ppt","pptx","zip","tar","gz"]);function rx(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 rf(e){let t=rx(e);if(t){if(rd.has(t))return"image";if(ru.has(t))return"video";if(rp.has(t))return"audio";if(rh.has(t))return"pdf"}}function rv(e){return e.startsWith("/")||e.startsWith("~/")||/^[A-Za-z]:[\\/]/.test(e)}function rg(e){let t=(0,rt.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("../")||rv(t))return!0;let r=t.includes("/")||t.includes("\\"),n=rx(t);return r?n.length>0&&n.length<=8:rm.has(n)}(n)?null:n}let ry=/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)*\.[a-z]{2,}(?:\/[^\s]*)?$/i;function rb(e){let t=e.trim();if(!t)return null;if(t.startsWith("www."))return"https://".concat(t);if(rn.test(t))try{let e=new URL(t);if("http:"!==e.protocol&&"https:"!==e.protocol)return null;return e.toString()}catch(e){return null}if(ry.test(t))try{return new URL("http://".concat(t)).toString()}catch(e){}return null}function rj(e){try{let t=new URL(e);if("http:"!==t.protocol&&"https:"!==t.protocol)return;let r=t.hostname.trim();if(!r)return;return"https://www.google.com/s2/favicons?domain=".concat(encodeURIComponent(r),"&sz=32")}catch(e){return}}function rk(e){let t=e.trim();if(!ro.test(t)||t.replace(/\D/g,"").length<7)return null;let r=t.replace(/[^\d+]/g,"");return r?"tel:".concat(r):null}function rw(e){let t=e.replace(/,/g,"").trim();if(!t)return null;let r=Number(t);return Number.isFinite(r)?r:null}function rN(e){return new Intl.NumberFormat(void 0,{maximumFractionDigits:6}).format(e)}function rC(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(rN(t))}function rS(e){let t=function(e){let t,r=e.trim();if(rl.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(!(ra.test(r)||rs.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 rM(e){return e.startsWith("http://")||e.startsWith("https://")?e:rv(e)?"/api/workspace/browse-file?path=".concat(encodeURIComponent(e),"&raw=true"):"/api/workspace/raw-file?path=".concat(encodeURIComponent(e))}let rT=new Map;function rL(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();return r.length<=256?function(e,t){let r=rT.get(e);if(void 0!==r)return rT.delete(e),rT.set(e,r),r;let n=t();if(rT.size>=4096){let e=rT.keys().next().value;void 0!==e&&rT.delete(e)}return rT.set(e,n),n}("".concat(n,"\0").concat(r),()=>rI(r,n)):rI(r,n)}function rI(e,t){let r=function(e,t){if("email"===t&&rr.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=rk(e);if(t)return{kind:"link",raw:e,text:e.trim(),linkType:"phone",href:t}}if("url"===t){let t=rb(e);if(t)return{kind:"link",raw:e,text:e.trim(),linkType:"url",href:t,mediaType:rf(t),embedUrl:t,faviconUrl:rj(t)}}if("date"===t){let t=rS(e);if(t)return{kind:"date",raw:e,text:t.text,isoDate:t.iso}}if("number"===t){let t=e.trim().match(ri);if(t){var r,n;let o=rw(null!=(r=t[2])?r:"");if(null!=o)return{kind:"currency",raw:e,text:rC(null!=(n=t[1])?n:"$",o),numericValue:o}}let o=rw(e);if(null!=o)return{kind:"number",raw:e,text:rN(o),numericValue:o}}if("file"===t){let t=rg(e);if(t)return{kind:"link",raw:e,text:t,linkType:"file",href:(0,rt.bJ)(t),filePath:t,mediaType:rf(t),embedUrl:rM(t)}}return null}(e,t);return r||("richtext"===t||"relation"===t||"enum"===t||"user"===t?{kind:"text",raw:e,text:e}:function(e){let t=e.trim(),r=rg(t);if(r)return{kind:"link",raw:e,text:r,linkType:"file",href:(0,rt.bJ)(r),filePath:r,mediaType:rf(r),embedUrl:rM(r)};if(rr.test(t))return{kind:"link",raw:e,text:t,linkType:"email",href:"mailto:".concat(t)};let n=rb(t);if(n)return{kind:"link",raw:e,text:t,linkType:"url",href:n,mediaType:rf(n),embedUrl:n,faviconUrl:rj(n)};let o=rk(t);if(o)return{kind:"link",raw:e,text:t,linkType:"phone",href:o};let l=rS(t);if(l)return{kind:"date",raw:e,text:l.text,isoDate:l.iso};let a=t.match(ri);if(a){var s,i;let t=rw(null!=(s=a[2])?s:"");if(null!=t)return{kind:"currency",raw:e,text:rC(null!=(i=a[1])?i:"$",t),numericValue:t}}if(rc.test(t)){let r=rw(t);if(null!=r)return{kind:"number",raw:e,text:rN(r),numericValue:r}}return{kind:"text",raw:e,text:e}}(e))}function r_(e){let{href:t,openInNewTab:r=!0,title:o="Open link",className:l}=e;return(0,n.jsx)("a",{href:t,...r?{target:"_blank",rel:"noopener noreferrer"}:{},title:o,"aria-label":o,onPointerDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),className:null!=l?l:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-md hover:bg-black/5",children:(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:"M7 7h10v10"}),(0,n.jsx)("path",{d:"M7 17 17 7"})]})})}var rR=r(17763);let rE=new Map,rD=new Map;function rA(e){let t=rD.get(e);if(t)for(let e of t)e()}async function rF(e){if(!rE.has(e)){rE.set(e,"loading"),rA(e);try{let t=await fetch("/api/workspace/link-preview?url=".concat(encodeURIComponent(e)));if(!t.ok)throw Error("fetch failed");let r=await t.json();rE.set(e,r)}catch(t){rE.set(e,"error")}rA(e)}}function rP(e){let[,t]=(0,o.useState)(0);if((0,o.useEffect)(()=>{if(e){var r;let n;return r=()=>t(e=>e+1),(n=rD.get(e))||(n=new Set,rD.set(e,n)),n.add(r),()=>{n.delete(r),0===n.size&&rD.delete(e)}}},[e]),!e)return{state:"idle",data:void 0};let r=rE.get(e);return r?"loading"===r?{state:"loading",data:void 0}:"error"===r?{state:"error",data:void 0}:{state:"ready",data:r}:{state:"idle",data:void 0}}function rB(e){let[t,r]=(0,o.useState)(!1),n=(0,o.useRef)(null),l=(0,o.useRef)(null),a=(0,o.useRef)(null),s=(0,o.useCallback)(()=>{n.current&&(clearTimeout(n.current),n.current=null),l.current&&(clearTimeout(l.current),l.current=null)},[]),i=(0,o.useCallback)(()=>{e&&(l.current&&(clearTimeout(l.current),l.current=null),n.current=setTimeout(()=>{rF(e),r(!0)},200))},[e]),c=(0,o.useCallback)(()=>{n.current&&(clearTimeout(n.current),n.current=null),l.current=setTimeout(()=>r(!1),200)},[]),d=(0,o.useCallback)(()=>{l.current&&(clearTimeout(l.current),l.current=null)},[]),u=(0,o.useCallback)(()=>{l.current=setTimeout(()=>r(!1),200)},[]);return(0,o.useEffect)(()=>s,[s]),{open:t,triggerRef:a,triggerProps:{ref:a,onMouseEnter:i,onMouseLeave:c,onFocus:i,onBlur:c},cardProps:{onMouseEnter:d,onMouseLeave:u}}}function rW(e){let{data:t,loading:r}=e;if(r||!t)return(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-3",children:[(0,n.jsx)("div",{className:"w-4 h-4 rounded-full border-2 border-t-transparent animate-spin",style:{borderColor:"var(--color-border)",borderTopColor:"transparent"}}),(0,n.jsx)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Loading preview..."})]});let o=!!t.imageUrl;return t.title||t.description||o?(0,n.jsxs)(n.Fragment,{children:[o&&(0,n.jsx)("div",{className:"w-full h-[140px] overflow-hidden bg-black/5 dark:bg-white/5",children:(0,n.jsx)("img",{src:t.imageUrl,alt:"",className:"w-full h-full object-cover",onError:e=>{e.currentTarget.parentElement.style.display="none"}})}),(0,n.jsxs)("div",{className:"px-3 py-2.5 space-y-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[t.faviconUrl&&(0,n.jsx)("img",{src:t.faviconUrl,alt:"",className:"w-3.5 h-3.5 rounded-[3px] shrink-0",onError:e=>{e.currentTarget.style.display="none"}}),(0,n.jsx)("span",{className:"text-[10px] font-medium truncate",style:{color:"var(--color-text-muted)"},children:t.siteName||t.domain})]}),t.title&&(0,n.jsx)("p",{className:"text-xs font-semibold leading-snug line-clamp-2",style:{color:"var(--color-text)"},children:t.title}),t.description&&(0,n.jsx)("p",{className:"text-[11px] leading-relaxed line-clamp-3",style:{color:"var(--color-text-muted)"},children:t.description})]})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[t.faviconUrl&&(0,n.jsx)("img",{src:t.faviconUrl,alt:"",className:"w-4 h-4 rounded-[3px] shrink-0"}),(0,n.jsx)("span",{className:"text-xs font-medium truncate",style:{color:"var(--color-text)"},children:t.domain})]})}function rO(e){let{open:t,triggerRef:r,data:l,loading:a,cardProps:s}=e,i=(0,o.useRef)(null),[c,d]=(0,o.useState)(null);return((0,o.useEffect)(()=>{if(!t||!r.current)return void d(null);let e=r.current.getBoundingClientRect(),n=window.innerHeight-e.bottom>248?"below":"above",o="below"===n?e.bottom+8:e.top-240-8,l=e.left+e.width/2-160;l=Math.max(8,Math.min(l,window.innerWidth-320-8)),d({top:o=Math.max(8,o),left:l,placement:n})},[t,r,l]),t&&c)?(0,rR.createPortal)((0,n.jsx)("div",{ref:i,role:"tooltip",...s,className:"fixed z-[99999] w-[320px] rounded-xl overflow-hidden animate-in fade-in-0 zoom-in-95 duration-150",style:{top:c.top,left:c.left,background:"var(--color-surface)",border:"1px solid var(--color-border)",boxShadow:"0 8px 30px rgba(0,0,0,0.16), 0 2px 8px rgba(0,0,0,0.08)",transformOrigin:"below"===c.placement?"top center":"bottom center"},children:(0,n.jsx)(rW,{data:l,loading:a})}),document.body):null}function rz(e){let{href:t,text:r,linkType:o,faviconUrl:l,showFavicon:a=!1,layout:s="inline",className:i,children:c}=e,d="url"===o,u=d?t:void 0,{open:p,triggerRef:h,triggerProps:m,cardProps:x}=rB(u),{state:f,data:v}=rP(u),g=a&&"url"===o&&l,y=g?(0,n.jsxs)("span",{className:"flex min-w-0 items-center gap-1.5 ".concat("inline"===s?"max-w-full":"w-full"),children:[(0,n.jsx)(t$,{src:l}),(0,n.jsx)("span",{className:"min-w-0 truncate",children:r})]}):r,b=(()=>{let e=null!=i?i:"";return g?"block"===s?"block underline underline-offset-2 ".concat(e).trim():"inline-flex min-w-0 max-w-full items-center gap-1.5 align-middle underline underline-offset-2 ".concat(e).trim():"underline underline-offset-2 ".concat(e).trim()})();return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("a",{...d?m:{},ref:d?h:void 0,href:t,..."url"===o||"file"===o?{target:"_blank",rel:"noopener noreferrer"}:{},className:b,style:{color:"var(--color-accent)"},onClick:e=>e.stopPropagation(),children:null!=c?c:y}),d&&(0,n.jsx)(rO,{open:p,triggerRef:h,data:v,loading:"loading"===f,cardProps:x})]})}function rU(e){let{href:t,children:r,className:o,style:l,...a}=e,{open:s,triggerRef:i,triggerProps:c,cardProps:d}=rB(t),{state:u,data:p}=rP(t);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{...a,...c,ref:i,className:o,style:l,children:r}),(0,n.jsx)(rO,{open:s,triggerRef:i,data:p,loading:"loading"===u,cardProps:d})]})}function rH(){return(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.5},children:"--"})}function rV(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 rK(e){let{text:t,fieldType:r,showUrlFavicon:o=!1,linkInteractionMode:l="inline",isTableMode:a=!1}=e,s=t.trim();if(!s)return(0,n.jsx)(n.Fragment,{children:t});let i=r&&"text"!==r&&"richtext"!==r?r:void 0,c=rL(s,i);if("link"===c.kind&&c.href){var d;if(!i&&"file"===c.linkType&&s.includes(" "))return(0,n.jsx)(n.Fragment,{children:c.text});let e="url"===c.linkType||"file"===c.linkType,t=o&&"url"===c.linkType&&!!c.faviconUrl;if("button"===l){let r=(0,n.jsxs)("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1.5 align-middle",style:{color:"var(--color-accent)"},children:[t&&(0,n.jsx)(t$,{src:c.faviconUrl}),(0,n.jsx)("span",{className:a?"min-w-0 truncate":"min-w-0 break-all",children:c.text}),(0,n.jsx)(r_,{href:c.href,openInNewTab:e,className:"inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-sm hover:bg-black/5"})]});return"url"===c.linkType?(0,n.jsx)(rU,{href:c.href,children:r}):r}return(0,n.jsx)(rz,{href:c.href,text:c.text,linkType:null!=(d=c.linkType)?d:"url",faviconUrl:c.faviconUrl,showFavicon:t})}return"number"===c.kind||"currency"===c.kind?(0,n.jsx)("span",{className:"tabular-nums",children:c.text}):(0,n.jsx)(n.Fragment,{children:c.text})}function rJ(e){let{value:t,fieldType:r,mode:l="table",className:a,showUrlFavicon:s=!1,linkInteractionMode:i="inline"}=e,c=rL(t,r),d="table"===l;if("empty"===c.kind)return(0,n.jsx)(rH,{});let u=c.text.replace(/\\r\\n/g,"\n").replace(/\\n/g,"\n").replace(/\\r/g,"\n");if(u.includes("\n")){let e=u.split("\n"),t=null!=a?a:d?"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)(rK,{text:e,fieldType:r,showUrlFavicon:s,linkInteractionMode:i,isTableMode:d})]},t))})}let p=null!=a?a:d?"truncate block max-w-[300px]":"break-words";if("link"===c.kind&&c.href){var h;let e="url"===c.linkType||"file"===c.linkType,t=!d&&!!c.embedUrl&&!!c.mediaType,r=s&&"url"===c.linkType&&!!c.faviconUrl;if("button"===i){let o=(0,n.jsxs)("div",{className:d?"block max-w-[300px]":"w-full",children:[(0,n.jsxs)("span",{className:"flex w-full min-w-0 items-center gap-1.5",style:{color:"var(--color-accent)"},children:[r&&(0,n.jsx)(t$,{src:c.faviconUrl}),(0,n.jsx)("span",{className:d?"min-w-0 truncate":"min-w-0 break-all",children:c.text}),(0,n.jsx)(r_,{href:c.href,openInNewTab:e})]}),t&&(0,n.jsx)(rV,{mediaType:c.mediaType,url:c.embedUrl,label:c.text})]});return"url"===c.linkType?(0,n.jsx)(rU,{href:c.href,children:o}):o}return(0,n.jsxs)("div",{className:d?"block max-w-[300px]":"w-full",children:[(0,n.jsx)(rz,{href:c.href,text:c.text,linkType:null!=(h=c.linkType)?h:"url",faviconUrl:c.faviconUrl,showFavicon:r,layout:"block",className:d?"truncate":""}),t&&(0,n.jsx)(rV,{mediaType:c.mediaType,url:c.embedUrl,label:c.text})]})}return"number"===c.kind||"currency"===c.kind?(0,n.jsx)("span",{className:"tabular-nums ".concat(p),children:c.text}):(0,n.jsx)("span",{className:p,children:u})}function rq(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 rG={default:{bg:"rgba(148, 163, 184, 0.08)",border:"1px solid rgba(148, 163, 184, 0.2)",text:"var(--color-text)",hoverBg:"rgba(148, 163, 184, 0.15)"},primary:{bg:"rgba(59, 130, 246, 0.08)",border:"1px solid rgba(59, 130, 246, 0.25)",text:"#3b82f6",hoverBg:"rgba(59, 130, 246, 0.15)"},destructive:{bg:"rgba(220, 38, 38, 0.08)",border:"1px solid rgba(220, 38, 38, 0.2)",text:"var(--color-error)",hoverBg:"rgba(220, 38, 38, 0.15)"},success:{bg:"rgba(34, 197, 94, 0.08)",border:"1px solid rgba(34, 197, 94, 0.25)",text:"#22c55e",hoverBg:"rgba(34, 197, 94, 0.15)"},warning:{bg:"rgba(245, 158, 11, 0.08)",border:"1px solid rgba(245, 158, 11, 0.25)",text:"#f59e0b",hoverBg:"rgba(245, 158, 11, 0.15)"}};function r$(e){let{size:t=12}=e;return(0,n.jsx)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"animate-spin",children:(0,n.jsx)("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})})}function rY(e){let{size:t=12}=e;return(0,n.jsx)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function rZ(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.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function rQ(e){let{size:t=12}=e;return(0,n.jsx)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polygon",{points:"5 3 19 12 5 21 5 3"})})}function rX(e){var t,r,l,a,s,i;let c,d,{action:u,entryId:p,objectName:h,fieldId:m,compact:x=!1,state:f,onExecute:v,onRequestConfirm:g,onToast:y,disabled:b=!1}=e,[j,k]=(0,o.useState)({status:"idle"}),w=(0,o.useRef)(null),N=(0,o.useRef)(null),C=null!=f?f:j,{status:S}=C;(0,o.useEffect)(()=>()=>{w.current&&clearTimeout(w.current),N.current&&N.current.abort()},[]);let M=(0,o.useCallback)(async()=>{if(v)return void v(u,p);k({status:"loading"});let e=new AbortController;N.current=e;try{var t,r,n,o,l,a,s,i;let c=await fetch("/api/workspace/objects/".concat(encodeURIComponent(h),"/actions"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({actionId:u.id,fieldId:m,entryIds:[p]}),signal:e.signal});if(!c.ok){let e=null!=(r=(await c.json().catch(()=>({error:"Request failed"}))).error)?r:"Request failed";k({status:"error",error:e}),null==y||y(e,{type:"error"});return}let d=null==(t=c.body)?void 0:t.getReader();if(!d){k({status:"error",error:"No response stream"}),null==y||y("No response stream",{type:"error"});return}let x=new TextDecoder,f="";for(;;){let{done:e,value:t}=await d.read();if(e)break;let r=(f+=x.decode(t,{stream:!0})).split("\n");for(let e of(f=null!=(n=r.pop())?n:"",r))if(e.startsWith("data: "))try{let t=JSON.parse(e.slice(6));if("progress"===t.type)k({status:"loading",progress:{percent:t.percent,message:t.message}});else if("log"===t.type)null==y||y(null!=(o=t.message)?o:"",{type:"error"===t.level?"error":"info"});else if("completed"===t.type)if("success"===t.status)k({status:"success",result:t.result}),null==y||y(null!=(l=u.successLabel)?l:"".concat(u.label," completed"),{type:"success"}),w.current=setTimeout(()=>{k({status:"idle"})},null!=(a=u.autoResetMs)?a:3e3);else{let e=null!=(s=t.error)?s:"Action failed";k({status:"error",error:e}),null==y||y(e,{type:"error"}),w.current=setTimeout(()=>{k({status:"idle"})},null!=(i=u.autoResetMs)?i:5e3)}}catch(e){}}}catch(r){if(e.signal.aborted)return;let t=r instanceof Error?r.message:"Unknown error";k({status:"error",error:t}),null==y||y(t,{type:"error"})}},[u,p,h,m,v,y]),T=(0,o.useCallback)(e=>{if(e.stopPropagation(),"loading"!==S&&!b){if("error"===S)return void k({status:"idle"});u.confirmMessage&&g?g(u,p,M):M()}},[S,b,u,p,g,M]),L=null!=(l=rG[null!=(r=u.variant)?r:"default"])?l:rG.default,I=L.bg,_=L.border,R=L.text;switch(S){case"loading":c=null!=(a=u.loadingLabel)?a:"Running...",d=(0,n.jsx)(r$,{size:x?14:12});break;case"success":c=null!=(s=u.successLabel)?s:"Done!",d=(0,n.jsx)(rY,{size:x?14:12}),I="rgba(34, 197, 94, 0.1)",_="1px solid rgba(34, 197, 94, 0.3)",R="#22c55e";break;case"error":c=null!=(i=u.errorLabel)?i:"Failed",d=(0,n.jsx)(rZ,{size:x?14:12}),I="rgba(220, 38, 38, 0.1)",_="1px solid rgba(220, 38, 38, 0.3)",R="var(--color-error)";break;default:c=u.label,d=(0,n.jsx)(rQ,{size:x?14:12})}let E=null==(t=C.progress)?void 0:t.percent;return(0,n.jsxs)("button",{type:"button",onClick:T,disabled:"loading"===S||b,className:"relative flex items-center gap-1.5 rounded-lg text-xs font-medium transition-all duration-200 overflow-hidden select-none",style:{padding:x?"4px 6px":"5px 10px",background:I,border:_,color:R,opacity:b?.5:1,cursor:"loading"===S||b?"not-allowed":"pointer"},title:"error"===S?C.error:u.label,onMouseEnter:e=>{"loading"===S||b||(e.currentTarget.style.background=L.hoverBg)},onMouseLeave:e=>{e.currentTarget.style.background=I},children:[null!=E&&"loading"===S&&(0,n.jsx)("div",{className:"absolute inset-0 opacity-15 transition-all duration-300",style:{background:R,width:"".concat(E,"%")}}),(0,n.jsxs)("span",{className:"relative z-10 flex items-center gap-1.5",children:[d,!x&&(0,n.jsx)("span",{className:"whitespace-nowrap",children:c})]})]})}function r0(e){let{open:t,title:r,message:l,confirmLabel:a="Confirm",cancelLabel:s="Cancel",variant:i="default",onConfirm:c,onCancel:d,loading:u=!1}=e,p=(0,o.useRef)(null);(0,o.useEffect)(()=>{t&&setTimeout(()=>{var e;return null==(e=p.current)?void 0:e.focus()},50)},[t]);let h=(0,o.useCallback)(e=>{"Escape"===e.key&&(e.stopPropagation(),d())},[d]);if(!t)return null;let m="destructive"===i;return(0,n.jsxs)("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center",onKeyDown:h,children:[(0,n.jsx)("div",{className:"absolute inset-0 backdrop-blur-sm animate-in fade-in duration-150",style:{background:"rgba(0, 0, 0, 0.4)"},onClick:d}),(0,n.jsxs)("div",{className:"relative w-full max-w-sm mx-4 rounded-xl p-6 shadow-2xl animate-in zoom-in-95 fade-in duration-200",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-start gap-3 mb-4",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-10 h-10 rounded-full flex items-center justify-center",style:{background:m?"rgba(220, 38, 38, 0.1)":"rgba(59, 130, 246, 0.1)"},children:m?(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"#dc2626",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),(0,n.jsx)("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}):(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"#3b82f6",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("h3",{className:"text-sm font-semibold mb-1",style:{color:"var(--color-text)"},children:r}),(0,n.jsx)("p",{className:"text-sm leading-relaxed",style:{color:"var(--color-text-muted)"},children:l})]})]}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:d,disabled:u,className:"px-4 py-2 rounded-lg text-sm font-medium transition-colors",style:{background:"transparent",border:"1px solid var(--color-border)",color:"var(--color-text-muted)"},children:s}),(0,n.jsxs)("button",{ref:p,type:"button",onClick:c,disabled:u,className:"px-4 py-2 rounded-lg text-sm font-medium transition-colors flex items-center gap-2",style:{background:m?"#dc2626":"var(--color-accent)",border:"none",color:"#fff",opacity:u?.7:1},children:[u&&(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"animate-spin",children:(0,n.jsx)("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),a]})]})]})]})}let r1={default:"var(--color-text)",primary:"#3b82f6",destructive:"var(--color-error)",success:"#22c55e",warning:"#f59e0b"};function r2(e){var t,r;let{action:o,fieldId:l,runState:a,onClick:s}=e,i=null!=(r=r1[null!=(t=o.variant)?t:"default"])?r:r1.default,c=(null==a?void 0:a.status)==="running",d=(null==a?void 0:a.status)==="done",u=o.label,p=(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)("polygon",{points:"5 3 19 12 5 21 5 3"})}),h=null,m=i,x="color-mix(in srgb, ".concat(i," 8%, transparent)"),f="1px solid color-mix(in srgb, ".concat(i," 20%, transparent)");return c&&a?(u="".concat(o.label),p=(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"animate-spin",children:(0,n.jsx)("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),h=(0,n.jsxs)("span",{className:"text-[10px] font-mono opacity-70 tabular-nums",children:[a.succeeded+a.failed,"/",a.total]})):d&&a&&(0===a.failed?(p=(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#22c55e",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),m="#22c55e",x="rgba(34, 197, 94, 0.1)",f="1px solid rgba(34, 197, 94, 0.3)",u="".concat(a.succeeded," done")):(p=(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#dc2626",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),(0,n.jsx)("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]}),m="#dc2626",x="rgba(220, 38, 38, 0.1)",f="1px solid rgba(220, 38, 38, 0.3)",u="".concat(a.succeeded," ok, ").concat(a.failed," failed"))),(0,n.jsxs)("button",{type:"button",onClick:s,disabled:c,className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-xs font-medium transition-all hover:opacity-80",style:{background:x,border:f,color:m,opacity:c?.8:1,cursor:c?"not-allowed":"pointer"},children:[p,(0,n.jsx)("span",{className:"whitespace-nowrap",children:u}),h]},"".concat(l,"_").concat(o.id))}function r4(e){let{selectedCount:t,actions:r,onDeselectAll:o,onBulkAction:l,onBulkDelete:a,bulkRunStates:s,onBulkEnrich:i,enrichBusy:c}=e;return 0===t?null:(0,n.jsxs)("div",{className:"fixed bottom-6 left-1/2 -translate-x-1/2 z-[100] flex items-center gap-3 px-4 py-2.5 rounded-xl shadow-2xl animate-in slide-in-from-bottom-4 fade-in duration-300",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",backdropFilter:"blur(16px)",minWidth:320},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 pr-3",style:{borderRight:"1px solid var(--color-border)"},children:[(0,n.jsx)("span",{className:"flex items-center justify-center w-6 h-6 rounded-md text-xs font-bold",style:{background:"var(--color-accent)",color:"#fff"},children:t}),(0,n.jsx)("span",{className:"text-xs font-medium whitespace-nowrap",style:{color:"var(--color-text-muted)"},children:"selected"}),(0,n.jsx)("button",{type:"button",onClick:o,className:"text-[11px] underline underline-offset-2 transition-opacity hover:opacity-70",style:{color:"var(--color-text-muted)"},children:"Clear"})]}),r.length>0&&(0,n.jsx)("div",{className:"flex items-center gap-1.5",children:r.map(e=>{let{action:t,fieldId:r}=e;return(0,n.jsx)(r2,{action:t,fieldId:r,runState:null==s?void 0:s.get(t.id),onClick:()=>l(t,r)},"".concat(r,"_").concat(t.id))})}),(0,n.jsxs)("div",{className:"ml-auto pl-3 flex items-center gap-1.5",style:{borderLeft:r.length>0?"1px solid var(--color-border)":"none"},children:[i&&(0,n.jsxs)("button",{type:"button",onClick:i,disabled:c,className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-xs font-medium transition-all hover:opacity-80",style:{background:"color-mix(in srgb, var(--color-accent) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--color-accent) 22%, transparent)",color:"var(--color-accent)",opacity:c?.7:1,cursor:c?"not-allowed":"pointer"},title:c?"Enrichment already in progress":"Enrich the ".concat(t," selected ").concat(1===t?"row":"rows"),children:[c?(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"animate-spin",children:(0,n.jsx)("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}):(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 2L13.5 8.5L20 10L13.5 11.5L12 18L10.5 11.5L4 10L10.5 8.5L12 2Z"}),(0,n.jsx)("path",{d:"M19 19L19.5 20.5L21 21L19.5 21.5L19 23L18.5 21.5L17 21L18.5 20.5L19 19Z"})]}),"Enrich"]}),(0,n.jsxs)("button",{type:"button",onClick:a,className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-xs font-medium transition-all hover:opacity-80",style:{background:"rgba(220, 38, 38, 0.08)",border:"1px solid rgba(220, 38, 38, 0.2)",color:"var(--color-error)"},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"]})]})]})}let r5=(0,o.createContext)(()=>{});function r3(){return(0,o.useContext)(r5)}let r6={success:{bg:"rgba(34, 197, 94, 0.08)",border:"1px solid rgba(34, 197, 94, 0.25)",color:"#22c55e",icon:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#22c55e",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})})},error:{bg:"rgba(220, 38, 38, 0.08)",border:"1px solid rgba(220, 38, 38, 0.25)",color:"#dc2626",icon:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#dc2626",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),(0,n.jsx)("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})},info:{bg:"rgba(59, 130, 246, 0.08)",border:"1px solid rgba(59, 130, 246, 0.2)",color:"#3b82f6",icon:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#3b82f6",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}};function r8(e){let{children:t}=e,[r,l]=(0,o.useState)([]),a=(0,o.useRef)(0),s=(0,o.useRef)(new Map),i=(0,o.useCallback)(e=>{l(t=>t.map(t=>t.id===e?{...t,dismissing:!0}:t)),setTimeout(()=>{l(t=>t.filter(t=>t.id!==e))},200);let t=s.current.get(e);t&&(clearTimeout(t),s.current.delete(e))},[]),c=(0,o.useCallback)((e,t)=>{var r,n;let o=null!=(r=null==t?void 0:t.type)?r:"info",c=null!=(n=null==t?void 0:t.duration)?n:"error"===o?6e3:4e3,d=++a.current;l(t=>{let r=[...t,{id:d,message:e,type:o,duration:c}];return r.length>5?r.slice(-5):r});let u=setTimeout(()=>{i(d),s.current.delete(d)},c);s.current.set(d,u)},[i]);return(0,n.jsxs)(r5.Provider,{value:c,children:[t,r.length>0&&(0,n.jsx)("div",{className:"fixed bottom-4 right-4 z-[9998] flex flex-col-reverse gap-2 pointer-events-none",style:{maxWidth:380},children:r.map(e=>{let t=r6[e.type];return(0,n.jsxs)("div",{className:"pointer-events-auto flex items-start gap-2.5 px-3.5 py-2.5 rounded-lg shadow-lg transition-all duration-200 ".concat(e.dismissing?"opacity-0 translate-x-4":"opacity-100 translate-x-0"),style:{background:"var(--color-surface)",border:t.border,backdropFilter:"blur(12px)"},children:[(0,n.jsx)("span",{className:"flex-shrink-0 mt-0.5",children:t.icon}),(0,n.jsx)("p",{className:"text-xs leading-relaxed flex-1 min-w-0 break-words",style:{color:"var(--color-text)"},children:e.message}),(0,n.jsx)("button",{type:"button",onClick:()=>i(e.id),className:"flex-shrink-0 p-0.5 rounded hover:opacity-60 transition-opacity",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.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},e.id)})})]})}let r7=["people","company"],r9=/people|person|contact|lead|prospect/i,ne=/company|companies|organization|account|business/i,nt=[{label:"Full Name",key:"person.name",fieldType:"text",apolloPath:"person.name",requiredFields:["fullName"],extractionFallbacks:["fullName","person.fullName"]},{label:"Email",key:"person.email",fieldType:"email",apolloPath:"person.email",requiredFields:["email"],extractionFallbacks:["email"]},{label:"Headline",key:"person.headline",fieldType:"text",apolloPath:"person.headline",requiredFields:["headline"],extractionFallbacks:["headline"]},{label:"LinkedIn URL",key:"person.linkedin_url",fieldType:"url",apolloPath:"person.linkedin_url",requiredFields:["linkedinID"],extractionFallbacks:["linkedin_url","URLs.linkedin","person.URLs.linkedin"]},{label:"Twitter URL",key:"person.twitter_url",fieldType:"url",apolloPath:"person.twitter_url",requiredFields:["URLs"],extractionFallbacks:["twitter_url","URLs.twitter","person.URLs.twitter"]},{label:"Phone",key:"person.phone",fieldType:"phone",apolloPath:"person.contact.phone_numbers.0.sanitized_number",requiredFields:["phone"],extractionFallbacks:["phone","person.phone"]},{label:"Title",key:"person.title",fieldType:"text",apolloPath:"person.title",requiredFields:[],extractionFallbacks:["title"]},{label:"Location",key:"person.location",fieldType:"text",apolloPath:"__computed.location",requiredFields:["location"],extractionFallbacks:["location","person.location"]}],nr=[{label:"Company Name",key:"organization.name",fieldType:"text",apolloPath:"organization.name",requiredFields:["name"],extractionFallbacks:["name"]},{label:"Website URL",key:"organization.website_url",fieldType:"url",apolloPath:"organization.website_url",requiredFields:["website"],extractionFallbacks:["website","organization.website"]},{label:"Industry",key:"organization.industry",fieldType:"text",apolloPath:"organization.industry",requiredFields:["industryList"],extractionFallbacks:["industryList.0","organization.industryList.0"]},{label:"LinkedIn URL",key:"organization.linkedin_url",fieldType:"url",apolloPath:"organization.linkedin_url",requiredFields:["linkedinID"],extractionFallbacks:["URLs.linkedin","organization.URLs.linkedin"]},{label:"Total Funding",key:"organization.total_funding_printed",fieldType:"text",apolloPath:"organization.total_funding_printed",requiredFields:["totalFunding"],extractionFallbacks:["totalFunding","organization.totalFunding"]},{label:"Founded Year",key:"organization.founded_year",fieldType:"number",apolloPath:"organization.founded_year",requiredFields:["founded"],extractionFallbacks:["founded","organization.founded"]}];function nn(e,t){return t.filter(t=>"people"===e?"email"===t.type||/^e[-_]?mail/i.test(t.name)||/linkedin/i.test(t.name):/domain|website/i.test(t.name)||/linkedin/i.test(t.name)||/^url$/i.test(t.name)&&"url"===t.type)}function no(e){if(!e)return null;try{var t;let r=JSON.parse(e);if((null==r||null==(t=r.enrichment)?void 0:t.category)&&r.enrichment.key)return r}catch(e){}return null}let nl=[{value:"text",label:"Text"},{value:"number",label:"Number"},{value:"email",label:"Email"},{value:"phone",label:"Phone"},{value:"date",label:"Date"},{value:"boolean",label:"Checkbox"},{value:"enum",label:"Select"},{value:"tags",label:"Tags"},{value:"url",label:"URL"},{value:"richtext",label:"Rich Text"}];function na(e){var t;let r=nl.find(t=>t.value===e);return null!=(t=null==r?void 0:r.label)?t:e.charAt(0).toUpperCase()+e.slice(1)}function ns(e){let{type:t,size:r=14,className:o}=e,l={width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:o};switch(t){case"text":return(0,n.jsxs)("svg",{...l,children:[(0,n.jsx)("path",{d:"M4 7V4h16v3"}),(0,n.jsx)("path",{d:"M9 20h6"}),(0,n.jsx)("path",{d:"M12 4v16"})]});case"number":return(0,n.jsxs)("svg",{...l,children:[(0,n.jsx)("path",{d:"M4 9h16"}),(0,n.jsx)("path",{d:"M4 15h16"}),(0,n.jsx)("path",{d:"M10 3 8 21"}),(0,n.jsx)("path",{d:"M16 3 14 21"})]});case"email":return(0,n.jsxs)("svg",{...l,children:[(0,n.jsx)("rect",{width:"20",height:"16",x:"2",y:"4",rx:"2"}),(0,n.jsx)("path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"})]});case"phone":return(0,n.jsx)("svg",{...l,children:(0,n.jsx)("path",{d:"M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"})});case"date":return(0,n.jsxs)("svg",{...l,children:[(0,n.jsx)("path",{d:"M8 2v4"}),(0,n.jsx)("path",{d:"M16 2v4"}),(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"4",rx:"2"}),(0,n.jsx)("path",{d:"M3 10h18"})]});case"boolean":return(0,n.jsxs)("svg",{...l,children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"m9 12 2 2 4-4"})]});case"enum":return(0,n.jsxs)("svg",{...l,children:[(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"m8 10 4 4 4-4"})]});case"tags":return(0,n.jsxs)("svg",{...l,children:[(0,n.jsx)("path",{d:"M12 2H2v10l9.29 9.29c.94.94 2.48.94 3.42 0l6.58-6.58c.94-.94.94-2.48 0-3.42L12 2Z"}),(0,n.jsx)("path",{d:"M7 7h.01"})]});case"url":return(0,n.jsxs)("svg",{...l,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"}),(0,n.jsx)("path",{d:"M2 12h20"})]});case"richtext":return(0,n.jsxs)("svg",{...l,children:[(0,n.jsx)("path",{d:"M17 6H3"}),(0,n.jsx)("path",{d:"M21 12H3"}),(0,n.jsx)("path",{d:"M15.1 18H3"})]});case"relation":return(0,n.jsxs)("svg",{...l,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"})]});case"user":return(0,n.jsxs)("svg",{...l,children:[(0,n.jsx)("path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"}),(0,n.jsx)("circle",{cx:"12",cy:"7",r:"4"})]});case"action":return(0,n.jsx)("svg",{...l,children:(0,n.jsx)("path",{d:"M13 2 3 14h9l-1 8 10-12h-9l1-8z"})});case"file":return(0,n.jsxs)("svg",{...l,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"})]});default:return(0,n.jsxs)("svg",{...l,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"})]})}}function ni(e){var t;let{field:r,sortDirection:o,onSort:l,onHide:a,onRename:s,onDelete:i,canMoveLeft:c,canMoveRight:d,onMoveLeft:u,onMoveRight:p,onReEnrich:h,onOptionsUpdate:m,open:x,onOpenChange:f}=e,v=(()=>{if(!r.default_value)return!1;try{var e;let t=JSON.parse(r.default_value);return!!(null==t||null==(e=t.enrichment)?void 0:e.key)}catch(e){return!1}})();return(0,n.jsxs)(tG.rI,{...void 0!==x?{open:x,onOpenChange:f}:{},children:[(0,n.jsx)(tG.ty,{className:"col-header-menu-trigger shrink-0 p-0.5 rounded opacity-0 group-hover:opacity-60 aria-expanded:opacity-100 hover:!opacity-100 transition-opacity ml-auto",style:{color:"var(--color-text-muted)"},onClick:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),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)("path",{d:"m6 9 6 6 6-6"})})}),(0,n.jsxs)(tG.SQ,{align:"start",sideOffset:6,className:"enum"===r.type?"min-w-[260px]":"min-w-[180px]",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1.5 text-xs normal-case tracking-normal",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)(ns,{type:r.type,size:14,className:"shrink-0"}),(0,n.jsx)("span",{className:"font-medium",children:na(r.type)}),v&&(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--color-warning, #f59e0b)"},children:(0,n.jsx)("path",{d:"M13 2 3 14h9l-1 8 10-12h-9l1-8z"})})]}),(0,n.jsx)(tG.mB,{}),(0,n.jsxs)(tG._2,{onSelect:s,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:"M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"})}),"Rename"]}),"enum"===r.type&&m&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(tG.mB,{}),(0,n.jsx)(nc,{values:null!=(t=r.enum_values)?t:[],onSave:m})]}),v&&h&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(tG.mB,{}),(0,n.jsxs)(tG._2,{onSelect:()=>h("empty"),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:"M13 2 3 14h9l-1 8 10-12h-9l1-8z"})}),"Enrich empty rows"]}),(0,n.jsxs)(tG._2,{onSelect:()=>h("all"),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:"M13 2 3 14h9l-1 8 10-12h-9l1-8z"})}),"Enrich all rows"]}),(0,n.jsxs)(tG._2,{onSelect:()=>h(50),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:"M13 2 3 14h9l-1 8 10-12h-9l1-8z"})}),"Enrich top 50"]})]}),(0,n.jsx)(tG.mB,{}),(0,n.jsxs)(tG._2,{onSelect:()=>l(!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",children:(0,n.jsx)("path",{d:"m5 12 7-7 7 7"})}),"Sort ascending","asc"===o&&(0,n.jsx)("span",{className:"ml-auto text-[10px] font-medium",style:{color:"var(--color-accent)"},children:"On"})]}),(0,n.jsxs)(tG._2,{onSelect:()=>l(!0),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:"m19 12-7 7-7-7"})}),"Sort descending","desc"===o&&(0,n.jsx)("span",{className:"ml-auto text-[10px] font-medium",style:{color:"var(--color-accent)"},children:"On"})]}),(0,n.jsx)(tG.mB,{}),(0,n.jsxs)(tG._2,{onSelect:a,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:"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"})]}),"Hide column"]}),(c||d)&&(0,n.jsx)(tG.mB,{}),c&&(0,n.jsxs)(tG._2,{onSelect:u,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 19-7-7 7-7"}),(0,n.jsx)("path",{d:"M19 12H5"})]}),"Move left"]}),d&&(0,n.jsxs)(tG._2,{onSelect:p,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:"M5 12h14"}),(0,n.jsx)("path",{d:"m12 5 7 7-7 7"})]}),"Move right"]}),(0,n.jsx)(tG.mB,{}),(0,n.jsxs)(tG._2,{variant:"destructive",onSelect:i,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 column"]})]})]})}function nc(e){let{values:t,onSave:r}=e,[l,a]=(0,o.useState)(t),[s,i]=(0,o.useState)(""),[c,d]=(0,o.useState)(!1),[u,p]=(0,o.useState)(null),h=(0,o.useRef)(!1),m=(0,o.useRef)(t);(0,o.useEffect)(()=>{a(t),m.current=t,p(null)},[t]);let x=(0,o.useCallback)(async e=>{if(h.current)return!1;let t=function(e){let t=new Set,r=[];for(let n of e){let e=n.trim();if(!e)continue;let o=e.toLocaleLowerCase();if(t.has(o))return{ok:!1,error:"Options must be unique"};t.add(o),r.push(e)}return{ok:!0,values:r}}(e);if(!t.ok)return p(t.error),!1;let n=m.current;if(t.values.length===n.length&&t.values.every((e,t)=>e===n[t]))return a(t.values),p(null),!0;h.current=!0,d(!0),p(null);try{return await r(t.values),a(t.values),m.current=t.values,!0}catch(e){return p(e instanceof Error?e.message:"Failed to save options"),!1}finally{h.current=!1,d(!1)}},[r]),f=(0,o.useCallback)(async()=>{let e=s.trim();e&&await x([...l,e])&&i("")},[s,l,x]),v=(0,o.useCallback)(async(e,t)=>{var r;let n=null!=(r=m.current[e])?r:"";if(t.trim()===n)return;let o=[...l];o[e]=t,await x(o)},[l,x]),g=(0,o.useCallback)(e=>{x(l.filter((t,r)=>r!==e))},[l,x]);return(0,n.jsxs)("div",{className:"px-2.5 py-2",onClick:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"mb-1.5 flex items-center justify-between gap-2",children:[(0,n.jsx)("span",{className:"text-[10px] font-medium uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:"Options"}),c&&(0,n.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:"Saving..."})]}),(0,n.jsxs)("div",{className:"space-y-1",children:[0===l.length&&(0,n.jsx)("div",{className:"px-2 py-1.5 text-xs rounded-lg",style:{color:"var(--color-text-muted)",background:"var(--color-surface)"},children:"No options yet"}),l.map((e,t)=>(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("input",{value:e,disabled:c,onChange:e=>{let r=[...l];r[t]=e.target.value,a(r)},onBlur:e=>void v(t,e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),v(t,e.currentTarget.value))},className:"min-w-0 flex-1 rounded-full px-2 py-1 text-xs outline-none",style:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)"},"aria-label":"Edit option ".concat(e)}),(0,n.jsx)("button",{type:"button",disabled:c,onMouseDown:e=>e.preventDefault(),onClick:()=>void v(t,e),className:"flex h-7 w-7 items-center justify-center rounded-full transition-colors disabled:opacity-40 hover:opacity-70",style:{color:"var(--color-text-muted)"},"aria-label":"Save option ".concat(e),children:(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M20 6 9 17l-5-5"})})}),(0,n.jsx)("button",{type:"button",disabled:c,onClick:()=>g(t),className:"flex h-7 w-7 items-center justify-center rounded-full transition-colors disabled:opacity-40 hover:opacity-70",style:{color:"var(--color-text-muted)"},"aria-label":"Remove option ".concat(e),children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]},"".concat(e,":").concat(t)))]}),(0,n.jsxs)("div",{className:"mt-1.5 flex items-center gap-1",children:[(0,n.jsx)("input",{value:s,disabled:c,onChange:e=>i(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),f())},placeholder:"Add option...",className:"min-w-0 flex-1 rounded-full px-2 py-1 text-xs outline-none",style:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)"}}),(0,n.jsx)("button",{type:"button",disabled:c||!s.trim(),onClick:()=>void f(),className:"flex h-7 w-7 items-center justify-center rounded-full text-xs font-medium transition-colors disabled:opacity-40",style:{background:"var(--color-accent)",color:"white"},"aria-label":"Add option",children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 5v14"}),(0,n.jsx)("path",{d:"M5 12h14"})]})})]}),u&&(0,n.jsx)("p",{className:"mt-1.5 px-1 text-[11px]",style:{color:"var(--color-error)"},children:u})]})}function nd(e){let{currentName:t,onSave:r,onCancel:l}=e,[a,s]=(0,o.useState)(t),i=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e=i.current;e&&(e.focus(),e.select())},[]);let c=(0,o.useCallback)(()=>{let e=a.trim();e&&e!==t?r(e):l()},[a,t,r,l]);return(0,n.jsx)("input",{ref:i,type:"text",value:a,onChange:e=>s(e.target.value),onBlur:c,onKeyDown:e=>{e.stopPropagation(),"Enter"===e.key&&(e.preventDefault(),c()),"Escape"===e.key&&(e.preventDefault(),l())},onClick:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),className:"w-full text-xs font-medium outline-none bg-transparent normal-case tracking-normal rounded px-1.5 py-0.5 -mx-1.5",style:{color:"var(--color-text)",background:"var(--color-bg)",boxShadow:"inset 0 0 0 2px var(--color-accent)"}})}let nu=[{value:"all",label:"Enrich all",buttonLabel:"all"},{value:"empty",label:"Enrich empty",buttonLabel:"empty"},{value:10,label:"Enrich top 10",buttonLabel:"top 10"}];function np(e){var t,r,l,a,s;let{objectName:i,onCreated:c,fields:d,enrichmentAvailable:u,onEnrichmentStart:p}=e,[h,m]=(0,o.useState)(!1),[x,f]=(0,o.useState)("text"),[v,g]=(0,o.useState)(""),[y,b]=(0,o.useState)(!1),[j,k]=(0,o.useState)(null),[w,N]=(0,o.useState)(null),[C,S]=(0,o.useState)(""),[M,T]=(0,o.useState)("all"),[L,I]=(0,o.useState)(!1),[_,R]=(0,o.useState)(null);(0,o.useEffect)(()=>{let e=!1;return fetch("/api/workspace/enrichment-status").then(e=>e.json()).then(t=>{e||R(!0===t.available)}).catch(()=>{e||R(!1)}),()=>{e=!0}},[]);let E=null!=(r=null!=_?_:u)&&r,D=(0,o.useRef)(d);D.current=d;let A=(0,o.useRef)(p);A.current=p;let F=(0,o.useRef)(null),P=(0,o.useRef)(null),[B,W]=(0,o.useState)({top:0,left:0}),O=(0,o.useMemo)(()=>{let e=null!=d?d:[];return(function(e,t){let r=r9.test(e)?"people":ne.test(e)?"company":null;if(r)return[r];let n=r7.filter(e=>nn(e,t).length>0);return n.length>0?n:r7})(i,e).map(t=>{var r;let n=nn(t,e),o=function(e,t){let r=nn(e,t);if("people"===e){let e=r.find(e=>"email"===e.type||/^e[-_]?mail/i.test(e.name));if(e)return e;let t=r.find(e=>/linkedin/i.test(e.name));if(t)return t}else{let e=r.find(e=>/website|domain|^url$/i.test(e.name));if(e)return e;let t=r.find(e=>/linkedin/i.test(e.name));if(t)return t}return null}(t,e);return{category:t,label:"people"===t?"People enrichment":"Company enrichment",columns:("people"===t?nt:nr).map(e=>({...e,category:t})),inputFields:n,defaultInputField:null!=(r=null==o?void 0:o.name)?r:""}})},[d,i]);(0,o.useEffect)(()=>{let e=w?O.find(e=>e.category===w.category):O.find(e=>e.defaultInputField);if(!e){C&&S("");return}e.inputFields.some(e=>e.name===C)||e.defaultInputField===C||S(e.defaultInputField)},[O,C,w]);let z=(0,o.useCallback)(()=>{var e;let t=null==(e=F.current)?void 0:e.getBoundingClientRect();if(t){let e=t.left;e+280>window.innerWidth-16&&(e=Math.max(16,t.right-280)),W({top:t.bottom+6,left:e})}m(!0),f("text"),g(""),k(null),N(null),T("all"),I(!1)},[]),U=(0,o.useCallback)(()=>{m(!1),k(null),N(null),I(!1)},[]);(0,o.useEffect)(()=>{if(!h)return;let e=e=>{P.current&&!P.current.contains(e.target)&&F.current&&!F.current.contains(e.target)&&U()},t=e=>{"Escape"===e.key&&U()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[h,U]);let H=(0,o.useCallback)(async()=>{let e={name:function(e,t){let r=new Set((null!=t?t:[]).map(e=>e.name.toLocaleLowerCase()));if(!r.has(e.toLocaleLowerCase()))return e;let n=2;for(;r.has("".concat(e," ").concat(n).toLocaleLowerCase());)n++;return"".concat(e," ").concat(n)}(na(x),D.current),type:x};if("enum"===x){let t=v.split(",").map(e=>e.trim()).filter(Boolean);if(0===t.length)return void k("Add at least one option");e.enum_values=t}b(!0),k(null);try{let r=await fetch("/api/workspace/objects/".concat(encodeURIComponent(i),"/fields"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!r.ok){var t;let e=await r.json().catch(()=>({error:"Failed"}));k(null!=(t=e.error)?t:"Failed to create field");return}U(),c()}catch(e){k("Network error")}finally{b(!1)}},[x,v,i,U,c]),V=(0,o.useCallback)(async()=>{if(w&&C){b(!0),k(null);try{var e,t,r,n,o;let l=(o=w.category,{enrichment:{category:o,key:w.key,apolloPath:w.apolloPath,inputFieldName:C}}),a=null==(e=D.current)?void 0:e.find(e=>e.name.toLowerCase()===w.label.toLowerCase());if(a){let e=await fetch("/api/workspace/objects/".concat(encodeURIComponent(i),"/fields/").concat(encodeURIComponent(a.id)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({default_value:JSON.stringify(l)})});if(!e.ok){let t=await e.json().catch(()=>({error:"Failed"}));k(null!=(r=t.error)?r:"Failed to mark existing field as enrichment");return}U(),c(),null==(t=A.current)||t.call(A,{fieldId:a.id,fieldName:a.name,apolloPath:w.apolloPath,category:w.category,inputFieldName:C,scope:M});return}let s={name:w.label,type:"number"===w.fieldType?"number":"email"===w.fieldType?"email":"url"===w.fieldType?"url":"text",default_value:JSON.stringify(l)},d=await fetch("/api/workspace/objects/".concat(encodeURIComponent(i),"/fields"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!d.ok){let e=await d.json().catch(()=>({error:"Failed"}));k(null!=(n=e.error)?n:"Failed to create enrichment field");return}let u=await d.json();U(),c(),A.current&&u.fieldId&&A.current({fieldId:u.fieldId,fieldName:w.label,apolloPath:w.apolloPath,category:w.category,inputFieldName:C,scope:M})}catch(e){k("Network error")}finally{b(!1)}}},[w,C,M,i,U,c]),K=E&&O.some(e=>e.columns.length>0),J=w?O.find(e=>e.category===w.category):null,q=null!=(l=null==J?void 0:J.inputFields)?l:[],G=!!w&&(null==(t=D.current)?void 0:t.some(e=>e.name.toLowerCase()===w.label.toLowerCase()))===!0;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{ref:F,type:"button",onClick:e=>{e.stopPropagation(),h?U():z()},onPointerDown:e=>e.stopPropagation(),className:"flex items-center justify-center w-full h-full transition-colors",style:{color:h?"var(--color-accent)":"var(--color-text-muted)",opacity:h?1:.4},title:"Add column",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"})]})}),h&&"undefined"!=typeof document&&(0,rR.createPortal)((0,n.jsx)("div",{ref:P,className:"fixed z-[10000] w-[280px] rounded-2xl overflow-hidden animate-in fade-in-0 zoom-in-95 slide-in-from-top-2",style:{top:B.top,left:B.left,background:"var(--color-bg)",border:"1px solid var(--color-border)",boxShadow:"0 8px 32px rgba(0,0,0,0.16), 0 0 1px rgba(0,0,0,0.1)",maxHeight:"min(500px, calc(100vh - 64px))",display:"flex",flexDirection:"column"},onClick:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),children:w?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"p-3 pb-2 flex items-center gap-2",style:{borderBottom:"1px solid var(--color-border)"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>N(null),className:"p-0.5 rounded hover:opacity-70",style:{color:"var(--color-text-muted)"},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 19-7-7 7-7"}),(0,n.jsx)("path",{d:"M19 12H5"})]})}),(0,n.jsx)("span",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:w.label})]}),(0,n.jsxs)("div",{className:"p-3 space-y-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-[10px] font-medium uppercase tracking-wider mb-1 block",style:{color:"var(--color-text-muted)"},children:"Input column"}),(0,n.jsxs)("select",{value:C,onChange:e=>S(e.target.value),className:"w-full px-2.5 py-1.5 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 input column..."}),q.map(e=>(0,n.jsx)("option",{value:e.name,children:e.name},e.id))]})]}),G&&(0,n.jsxs)("div",{className:"flex items-center gap-1.5 text-xs px-1",style:{color:"var(--color-accent)"},children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M20 6 9 17l-5-5"})}),"Existing “",w.label,"” column will be enriched"]}),j&&(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-error)"},children:j})]}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-3 py-2.5 mt-auto",style:{borderTop:"1px solid var(--color-border)"},children:[(0,n.jsx)("button",{type:"button",onClick:U,className:"px-3 py-1.5 text-xs rounded-lg transition-colors hover:opacity-70",style:{color:"var(--color-text-muted)"},children:"Cancel"}),(0,n.jsxs)("div",{className:"relative inline-flex rounded-lg overflow-visible",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>void V(),disabled:y||!C,className:"px-3 py-1.5 text-xs font-medium rounded-l-lg transition-colors disabled:opacity-40 flex items-center gap-1.5",style:{background:"var(--color-accent)",color:"white"},children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M13 2 3 14h9l-1 8 10-12h-9l1-8z"})}),y?"Enriching...":"".concat(G?"Enrich":"Create & Enrich"," ").concat(null!=(s=null==(a=nu.find(e=>e.value===M))?void 0:a.buttonLabel)?s:"all")]}),(0,n.jsx)("button",{type:"button","aria-label":"Choose enrichment scope","aria-expanded":L,onClick:()=>I(e=>!e),disabled:y||!C,className:"px-2 py-1.5 text-xs font-medium rounded-r-lg transition-colors disabled:opacity-40",style:{background:"var(--color-accent)",color:"white",borderLeft:"1px solid rgba(255,255,255,0.24)"},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)("path",{d:"m6 9 6 6 6-6"})})}),L&&(0,n.jsx)("div",{className:"absolute right-0 bottom-full mb-1 w-36 rounded-xl p-1 text-xs",style:{background:"var(--color-bg)",color:"var(--color-text)",border:"1px solid var(--color-border)",boxShadow:"0 8px 24px rgba(0,0,0,0.16)"},children:nu.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>{T(e.value),I(!1)},className:"w-full flex items-center justify-between px-2 py-1.5 rounded-lg text-left hover:opacity-80",style:{background:M===e.value?"var(--color-surface-hover)":"transparent"},children:[(0,n.jsx)("span",{children:e.label}),M===e.value&&(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M20 6 9 17l-5-5"})})]},String(e.value)))})]})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsx)("div",{className:"text-[10px] font-medium uppercase tracking-wider px-1 mb-1.5",style:{color:"var(--color-text-muted)"},children:"Type"}),(0,n.jsx)("div",{className:"grid grid-cols-2 gap-0.5",children:nl.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>f(e.value),className:"flex items-center gap-2 px-2.5 py-1.5 rounded-xl text-xs transition-all text-left",style:{color:x===e.value?"var(--color-accent)":"var(--color-text)",background:x===e.value?"var(--color-accent-light, rgba(99,102,241,0.08))":"transparent",fontWeight:x===e.value?600:400},children:[(0,n.jsx)(ns,{type:e.value,size:14,className:"shrink-0"}),e.label]},e.value))})]}),K&&(0,n.jsxs)("div",{className:"p-2 pt-0",children:[(0,n.jsx)("div",{className:"mb-1.5",style:{borderTop:"1px solid var(--color-border)"}}),(0,n.jsxs)("div",{className:"text-[10px] font-medium uppercase tracking-wider px-1 mb-1.5 flex items-center gap-1",style:{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",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M13 2 3 14h9l-1 8 10-12h-9l1-8z"})}),"Enrichment"]}),(0,n.jsx)("div",{className:"space-y-2",children:O.map(e=>(0,n.jsxs)("div",{children:[O.length>1&&(0,n.jsx)("div",{className:"text-[10px] font-medium uppercase tracking-wider px-1 mb-1",style:{color:"var(--color-text-muted)"},children:e.label}),(0,n.jsx)("div",{className:"grid grid-cols-2 gap-0.5",children:e.columns.map(t=>(0,n.jsxs)("button",{type:"button",onClick:()=>{N(t),S(e.defaultInputField),I(!1)},className:"flex items-center gap-2 px-2.5 py-1.5 rounded-xl text-xs transition-all text-left hover:opacity-80",style:{color:"var(--color-text)",background:"transparent"},children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--color-warning, #f59e0b)"},children:(0,n.jsx)("path",{d:"M13 2 3 14h9l-1 8 10-12h-9l1-8z"})}),t.label]},"".concat(t.category,":").concat(t.key)))})]},e.category))})]})]}),"enum"===x&&(0,n.jsx)("div",{className:"px-3 pb-2",children:(0,n.jsx)("input",{type:"text",value:v,onChange:e=>g(e.target.value),onKeyDown:e=>{e.stopPropagation(),"Enter"===e.key&&H()},placeholder:"Options (comma-separated)",className:"w-full px-2.5 py-1.5 text-sm rounded-lg outline-none",style:{background:"var(--color-surface)",color:"var(--color-text)",border:"1px solid var(--color-border)"}})}),j&&(0,n.jsx)("div",{className:"px-3 pb-2",children:(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-error)"},children:j})}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-3 py-2.5",style:{borderTop:"1px solid var(--color-border)"},children:[(0,n.jsx)("button",{type:"button",onClick:U,className:"px-3 py-1.5 text-xs rounded-lg transition-colors hover:opacity-70",style:{color:"var(--color-text-muted)"},children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>void H(),disabled:y||"enum"===x&&0===v.split(",").map(e=>e.trim()).filter(Boolean).length,className:"px-3 py-1.5 text-xs font-medium rounded-lg transition-colors disabled:opacity-40",style:{background:"var(--color-accent)",color:"white"},children:y?"Creating...":"Create"})]})]})}),document.body)]})}function nh(e){let{label:t,faviconUrl:r,onClick:o,maxLabelWidth:l=200}=e,a=!!o;return(0,n.jsxs)(a?"button":"span",{type:a?"button":void 0,onClick:o,title:a?"Open ".concat(t):t,className:"inline-flex items-center gap-1.5 max-w-full text-left ".concat(a?"cursor-pointer hover:underline focus:outline-hidden focus-visible:underline":""),style:{color:a?"var(--color-accent)":"var(--color-text)",background:"transparent",border:"none",padding:0,font:"inherit"},children:[(0,n.jsx)(nm,{faviconUrl:r,label:t}),(0,n.jsx)("span",{className:"truncate",style:{maxWidth:l},children:t})]})}function nm(e){var t;let{faviconUrl:r,label:l}=e,[a,s]=(0,o.useState)(!1),i=(null!=(t=null==l?void 0:l.trim().charAt(0))?t:"?").toUpperCase(),c=!!r&&!a;return(0,n.jsx)("span",{"aria-hidden":"true",className:"inline-flex items-center justify-center shrink-0 rounded-[3px] overflow-hidden",style:{width:16,height:16,background:c?"transparent":"var(--color-surface-hover)",border:c?"none":"1px solid var(--color-border)",color:"var(--color-text-muted)",fontSize:9,fontWeight:600,lineHeight:1},children:c?(0,n.jsx)("img",{src:r,alt:"",width:16,height:16,decoding:"async",loading:"lazy",onError:()=>s(!0),style:{width:16,height:16,objectFit:"contain"}}):i})}let nx=["created_at","Created","createdAt","created"],nf=["updated_at","Updated","updatedAt","updated"];function nv(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 ng(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 ny(e,t){for(let r of t){let t=e[r];if(null!=t&&""!==t)return t}}function nb(e){let t=e.entry_id;return null==t?"":String("object"==typeof t?JSON.stringify(t):t)}function nj(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 nk(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 nw(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 nN(e){let{value:t,field:r,fieldLabels:o,fieldFaviconUrls:l,onNavigateObject:a,onNavigateEntry:s}=e,i=null==t?[]:function(e){if(!e)return[];let t=e.trim();if(!t||"null"===t||"undefined"===t)return[];if(t.startsWith("["))try{let e=JSON.parse(t);if(Array.isArray(e))return e.map(String).filter(e=>e&&"null"!==e&&"undefined"!==e)}catch(e){}return[t]}(String(t));if(0===i.length)return(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.5},children:"--"});let c=!!r.related_object_name&&!!(s||a);return(0,n.jsx)("span",{className:"flex items-center gap-x-3 gap-y-1 flex-wrap",children:i.map(e=>{var t;let i=null!=(t=null==o?void 0:o[e])?t:e,d=c?t=>{if(t.stopPropagation(),s)return void s(r.related_object_name,e,r.related_object_id);null==a||a(r.related_object_name)}:void 0;return(0,n.jsx)(nh,{label:i,faviconUrl:null==l?void 0:l[e],onClick:d,maxLabelWidth:180},e)})})}function nC(e){let{tag:t}=e,r=rL(t),o="link"===r.kind&&r.href,l="url"===r.linkType&&!!r.faviconUrl,a="url"===r.linkType||"file"===r.linkType,s={background:"rgba(148, 163, 184, 0.12)",border:"1px solid var(--color-border)"};if(o){let e=(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-xs font-medium max-w-[200px]",style:{...s,color:"var(--color-accent)"},children:[l&&(0,n.jsx)(t$,{src:r.faviconUrl,className:"w-3.5 h-3.5 rounded-[3px] shrink-0"}),(0,n.jsx)("span",{className:"min-w-0 truncate",children:r.text}),(0,n.jsx)(r_,{href:r.href,openInNewTab:a,className:"inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-sm hover:bg-black/5"})]});return"url"===r.linkType?(0,n.jsx)(rU,{href:r.href,children:e}):e}return(0,n.jsx)("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium",style:{...s,color:"var(--color-text-muted)"},children:t})}function nS(e){let{value:t}=e,r=rq(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)(nC,{tag:e},e)),r.length>5&&(0,n.jsxs)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:["+",r.length-5]})]})}function nM(e){let{value:t,onChange:r,autoFocus:l}=e,a=rq(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 nT(e){let{links:t,sourceObjectName:r,sourceObjectId:o,onNavigateObject:l,onNavigateEntry:a}=e;if(!t||0===t.length)return(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.5},children:"--"});let s=t.slice(0,5),i=t.length-s.length;return(0,n.jsxs)("span",{className:"flex items-center gap-1 flex-wrap",children:[s.map(e=>(0,n.jsx)("span",{onClick:t=>{if(a||l){if(t.stopPropagation(),a)return void a(r,e.id,o);null==l||l(r)}},className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-xs font-medium ".concat(a||l?"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)),i>0&&(0,n.jsxs)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:["+",i]})]})}let nL=o.memo(function(e){let{value:t,entryId:r,fieldName:l,objectName:a,field:s,members:i,fieldRelationLabels:c,fieldRelationFaviconUrls:d,onNavigateObject:u,onNavigateEntry:p,onLocalValueChange:h,onSaved:m,showUrlFavicon:x=!1}=e,[f,v]=(0,o.useState)(!1),[g,y]=(0,o.useState)(nv(t)),b=(0,o.useRef)(null),j=(0,o.useRef)(null);(0,o.useEffect)(()=>{f||y(nv(t))},[t,f]),(0,o.useEffect)(()=>{f&&b.current&&b.current.focus()},[f]);let k=!["user"].includes(s.type),w="relation"===s.type&&!!s.related_object_name,N="tags"===s.type,C=(0,o.useCallback)(async e=>{null==h||h(r,l,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==m||m()}catch(e){}},[a,r,l,h,m]),S=e=>{y(e),j.current&&clearTimeout(j.current),j.current=setTimeout(()=>C(e),500)},M=()=>{j.current&&(clearTimeout(j.current),C(g)),v(!1)},T=e=>{"Enter"===e.key&&M(),"Escape"===e.key&&(v(!1),y(nv(t)))};if(!k)return"user"===s.type?(0,n.jsx)(nw,{value:t,members:i}):(0,n.jsx)("span",{className:"truncate block max-w-[300px]",children:nv(t)});if(f){let e;return w?(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)(re,{relatedObjectName:s.related_object_name,value:nv(t),multiple:"many_to_many"===s.relationship_type,onChange:e=>{C(e),v(!1)},variant:"inline",autoFocus:!0})}):N?(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)(nM,{value:nv(t),onChange:e=>{C(e)},autoFocus:!0})}):(e="enum"===s.type&&s.enum_values?(0,n.jsxs)("select",{ref:b,value:g,onChange:e=>{S(e.target.value),v(!1)},onBlur:M,onKeyDown:T,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:b,value:g,onChange:e=>{S(e.target.value),v(!1)},onBlur:M,onKeyDown:T,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:b,type:ng(s.type),value:g,onChange:e=>S(e.target.value),onBlur:M,onKeyDown:T,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 w?(0,n.jsx)("div",{onDoubleClick:()=>v(!0),className:"cursor-cell min-h-[1.5em]",title:"Double-click to edit",children:(0,n.jsx)(nN,{value:t,field:s,fieldLabels:c,fieldFaviconUrls:d,onNavigateObject:u,onNavigateEntry:p})}):N?(0,n.jsx)("div",{onDoubleClick:()=>v(!0),className:"cursor-cell min-h-[1.5em]",title:"Double-click to edit",children:(0,n.jsx)(nS,{value:t})}):(0,n.jsx)("div",{onDoubleClick:()=>v(!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)(nj,{value:nv(t),enumValues:s.enum_values,enumColors:s.enum_colors}):"boolean"===s.type?(0,n.jsx)(nk,{value:t}):(0,n.jsx)(rJ,{value:t,fieldType:s.type,mode:"table",showUrlFavicon:x,linkInteractionMode:"button"})})}),nI=o.memo(function(e){let{value:t,entryId:r,onEntryClick:l}=e,a=null==t||""===t?"--":nv(t),s="--"===a,i=(0,o.useCallback)(e=>{e.stopPropagation(),r&&!s&&l&&l(r)},[r,s,l]),c=(0,o.useCallback)(e=>{e.stopPropagation(),r&&l&&l(r)},[r,l]),d=!!r&&!!l;return(0,n.jsxs)("span",{className:"relative block w-full",children:[(0,n.jsx)("span",{className:"font-semibold truncate block ".concat(s||!l?"":"cursor-pointer hover:underline"),style:{color:s?"var(--color-text-muted)":"var(--color-accent)",opacity:s?.5:1,maxWidth:d?"calc(100% - 60px)":"100%"},onClick:i,children:a}),d&&(0,n.jsxs)("button",{type:"button",onClick:c,title:"Open","aria-label":"Open entry",className:"pointer-events-none absolute right-0 top-1/2 -translate-y-1/2 inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md text-[10px] font-medium cursor-pointer opacity-0 group-hover/row:pointer-events-auto group-hover/row:opacity-100 focus-visible:pointer-events-auto focus-visible:opacity-100 transition-opacity duration-100 outline-none focus-visible:ring-1",style:{background:"var(--color-bg)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-sm)"},children:["Open",(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"M7 7h10v10"}),(0,n.jsx)("path",{d:"M7 17 17 7"})]})]})]})});function n_(e){if(!e)return[];try{let t=JSON.parse(e);if(t&&Array.isArray(t.actions))return t.actions}catch(e){}return[]}function nR(e){let{objectName:t,fields:r,entries:l,members:a,relationLabels:s,relationFaviconUrls:i,reverseRelations:c,onNavigateToObject:d,onNavigateToEntry:u,onEntryClick:p,onRefresh:h,activeEntryId:m,columnVisibility:x,onColumnVisibilityChanged:f,columnSizing:v,onColumnSizingChanged:g,serverPagination:y,onServerSearch:b,onServerSort:j,hideInternalToolbar:k,globalFilter:w,onGlobalFilterChange:N,onAddRequest:C,stickyFirstColumnValue:S,onStickyFirstColumnChange:T,onSelectionContextChange:L}=e,[I,_]=(0,o.useState)({}),[R,E]=(0,o.useState)(null),[D,A]=(0,o.useState)(!1),[F,P]=(0,o.useState)(l),[B,W]=(0,o.useState)(null),{executeBulkAction:O,bulkStates:z}=function(){let[e,t]=(0,o.useState)(new Map),[r,n]=(0,o.useState)(new Map),l=(0,o.useCallback)((t,r)=>{var n;return null!=(n=e.get("".concat(t,"_").concat(r)))?n:{status:"idle"}},[e]),a=(0,o.useCallback)((e,r,n)=>{t(t=>{let o=new Map(t);return o.set("".concat(e,"_").concat(r),n),o})},[]),s=(0,o.useCallback)(async(e,t,r,o,l)=>{var s,i,c,d,u,p,h;let m=o.length,x=0,f=0,v=m;for(let t of o)a(e.id,t,{status:"loading"});n(t=>{let r=new Map(t);return r.set(e.id,{status:"running",running:v,succeeded:x,failed:f,total:m}),r});try{let p=await fetch("/api/workspace/objects/".concat(encodeURIComponent(r),"/actions"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({actionId:e.id,fieldId:t,entryIds:o})});if(!p.ok){n(t=>{let r=new Map(t);return r.set(e.id,{status:"done",running:0,succeeded:0,failed:m,total:m}),r}),null==l||null==(i=l.onToast)||i.call(l,"".concat(e.label," failed to start"),{type:"error"});return}let h=null==(s=p.body)?void 0:s.getReader();if(!h)return;let g=new TextDecoder,y="";for(;;){let{done:t,value:r}=await h.read();if(t)break;let o=(y+=g.decode(r,{stream:!0})).split("\n");for(let t of(y=null!=(c=o.pop())?c:"",o))if(t.startsWith("data: "))try{let r=JSON.parse(t.slice(6));if("progress"===r.type&&r.entryId)a(e.id,r.entryId,{status:"loading",progress:{percent:r.percent,message:r.message}});else if("completed"===r.type&&r.entryId){v--,"success"===r.status?(x++,a(e.id,r.entryId,{status:"success",result:r.result})):(f++,a(e.id,r.entryId,{status:"error",error:r.error})),n(t=>{let r=new Map(t);return r.set(e.id,{status:v>0?"running":"done",running:v,succeeded:x,failed:f,total:m}),r});let t=null!=(u=null!=(d=null==l?void 0:l.autoResetMs)?d:e.autoResetMs)?u:3e3;setTimeout(()=>{a(e.id,r.entryId,{status:"idle"})},t)}}catch(e){}}}catch(e){}n(t=>{let r=new Map(t);return r.set(e.id,{status:"done",running:0,succeeded:x,failed:f,total:m}),r}),f>0?null==l||null==(p=l.onToast)||p.call(l,"".concat(e.label,": ").concat(x," succeeded, ").concat(f," failed"),{type:"error"}):x>0&&(null==l||null==(h=l.onToast)||h.call(l,"".concat(e.label,": ").concat(x," entries completed"),{type:"success"})),setTimeout(()=>{n(t=>{let r=new Map(t);return r.delete(e.id),r})},5e3)},[a]);return{getState:l,setState:a,executeBulkAction:s,bulkStates:r}}(),U=r3(),[H,V]=(0,o.useState)(null),[K,J]=(0,o.useState)(null),[q,G]=(0,o.useState)(null),[$,Y]=(0,o.useState)(new Set),Z=(0,o.useRef)(null),Q=(0,o.useCallback)(e=>{Z.current&&Z.current.abort();let r=new AbortController;Z.current=r,G({fieldId:e.fieldId,fieldName:e.fieldName,current:0,total:0,enriched:0,errors:0}),Y(new Set),(async()=>{try{let o=await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/enrich"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({fieldId:e.fieldId,apolloPath:e.apolloPath,category:e.category,inputFieldName:e.inputFieldName,scope:e.scope,...e.entryIds&&e.entryIds.length>0?{entryIds:e.entryIds}:{}}),signal:r.signal});if(!o.ok||!o.body)return void G(null);let l=o.body.getReader(),a=new TextDecoder,s="";for(;;){var n;let{value:t,done:r}=await l.read();if(r)break;let o=(s+=a.decode(t,{stream:!0})).split("\n");for(let t of(s=null!=(n=o.pop())?n:"",o))if(t.startsWith("data: "))try{let r=JSON.parse(t.slice(6));"progress"===r.type?(G(e=>e?{...e,current:r.current,total:r.total,enriched:e.enriched+1}:e),P(t=>t.map(t=>{var n;return String(null!=(n=t.entry_id)?n:"")!==r.entryId?t:{...t,[e.fieldName]:r.value}})),Y(e=>{let t=new Set(e);return t.add(r.entryId),t})):"error"===r.type?G(e=>e?{...e,current:r.current,total:r.total,errors:e.errors+1}:e):"done"===r.type&&(G(null),setTimeout(()=>Y(new Set),3e3),null==h||h())}catch(e){}}}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return;G(null)}})()},[t,h]),X=(0,o.useCallback)((e,t)=>{let n=r.find(t=>t.id===e);if(!n)return;let o=no(n.default_value);o&&Q({fieldId:e,fieldName:n.name,apolloPath:o.enrichment.apolloPath,category:o.enrichment.category,inputFieldName:o.enrichment.inputFieldName,scope:t})},[r,Q]),ee=(0,o.useMemo)(()=>r.filter(e=>"action"!==e.type),[r]),et=(0,o.useMemo)(()=>r.filter(e=>"action"===e.type),[r]),er=(0,o.useMemo)(()=>{let e=[];for(let t of et)for(let r of n_(t.default_value))e.push({action:r,fieldId:t.id});return e},[et]);(0,o.useEffect)(()=>{P(l)},[l]);let en=(0,o.useCallback)((e,t,r)=>{P(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}}))},[]),eo=(0,o.useMemo)(()=>c?c.filter(e=>Object.keys(e.entries).length>0):[],[c]),el=(0,o.useMemo)(()=>{let e={};for(let t of ee)e[t.id]=t.name;for(let t of(e.created_at="created_at",e.updated_at="updated_at",eo))e["rev_".concat(t.sourceObjectName,"_").concat(t.fieldName)]="".concat((0,M.PV)(t.sourceObjectName)," via ").concat(t.fieldName);for(let t of et)e["action_".concat(t.id)]=t.name;return e},[eo,et,ee]),ea=(0,o.useMemo)(()=>Object.entries(el).filter(e=>{let[t]=e;return(null==x?void 0:x[t])!==!1}).slice(0,20),[el,x]),es=(0,o.useCallback)((e,t,r)=>{if("created_at"===t)return nv(ny(e,nx));if("updated_at"===t)return nv(ny(e,nf));if(t.startsWith("rev_")){var n,o;let r=eo.find(e=>"rev_".concat(e.sourceObjectName,"_").concat(e.fieldName)===t),l=nv(e.entry_id);return null!=(o=null==r||null==(n=r.entries[l])?void 0:n.map(e=>e.label).join(", "))?o:""}return nv(e[r])},[eo]);(0,o.useEffect)(()=>{if(!L)return;let e=Object.keys(I).filter(e=>I[e]).map(Number).filter(e=>Number.isInteger(e)&&F[e]);if(e.length>0){let r=e.map(e=>{let t=F[e],r={};for(let[e,n]of ea)r[n]=es(t,e,n);return{rowIndex:e,entryId:nv(t.entry_id),values:r}});L({objectName:t,kind:"rows",rowCount:r.length,columnCount:ea.length,columns:ea.map(e=>{let[,t]=e;return t}),rows:r,updatedAt:Date.now()});return}if(!R)return void L(null);let r=ea.map(e=>{let[t]=e;return t}),n=r.indexOf(R.anchor.columnId),o=r.indexOf(R.focus.columnId);if(n<0||o<0)return void L(null);let l=Math.max(0,Math.min(R.anchor.rowIndex,R.focus.rowIndex)),a=Math.min(F.length-1,Math.max(R.anchor.rowIndex,R.focus.rowIndex)),s=Math.min(n,o),i=Math.max(n,o),c=ea.slice(s,i+1),d=[];for(let e=l;e<=a;e++){let t=F[e];if(t)for(let[r,n]of c)d.push({rowIndex:e,entryId:nv(t.entry_id),fieldName:n,value:es(t,r,n)})}L({objectName:t,kind:"cells",rowCount:a-l+1,columnCount:c.length,columns:c.map(e=>{let[,t]=e;return t}),cells:d,updatedAt:Date.now()})},[R,F,t,L,es,I,ea]),(0,o.useEffect)(()=>()=>null==L?void 0:L(null),[L]);let ei=(0,o.useMemo)(()=>{let e=ee.filter(e=>"url"===e.type),t=e.length>0?e:ee,r=new Map;for(let e of F){let n=e.entry_id;if(null==n)continue;let o=String("object"==typeof n?JSON.stringify(n):n);if(!o)continue;let l=function(e,t){for(let r of t){let t=e[r.name];if(null==t||""===t)continue;let n=rL(t,r.type);if("link"===n.kind&&"url"===n.linkType&&n.faviconUrl)return n.faviconUrl}}(e,t);l&&r.set(o,l)}return r},[F,ee]),ec=(0,o.useCallback)(e=>{let t=e.original.entry_id;if(null==t)return;let r=String("object"==typeof t?JSON.stringify(t):t);return ei.get(r)},[ei]),ed=(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]),eu=(0,o.useCallback)(async(e,r)=>{try{(await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/fields/").concat(encodeURIComponent(e)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r})})).ok&&(null==h||h())}catch(e){}V(null)},[t,h]),ep=(0,o.useCallback)(async(e,r)=>{let n=await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/fields/").concat(encodeURIComponent(e)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enum_values:r})});if(!n.ok){var o;throw Error(null!=(o=(await n.json().catch(()=>({}))).error)?o:"HTTP ".concat(n.status))}null==h||h()},[t,h]),eh=(0,o.useCallback)((e,r)=>{W({open:!0,title:'Delete "'.concat(r,'" column?'),message:"This will permanently remove this column and all its data from every entry. This cannot be undone.",variant:"destructive",confirmLabel:"Delete column",onConfirm:async()=>{W(null);try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/fields/").concat(encodeURIComponent(e)),{method:"DELETE"}),null==h||h()}catch(e){}}})},[t,h]),em=(0,o.useCallback)((e,t)=>{let r=ee.map(e=>e.id),n=r.indexOf(e);if("left"===t&&n>0){let e=[...r];[e[n],e[n-1]]=[e[n-1],e[n]],ed(e)}else if("right"===t&&n<r.length-1){let e=[...r];[e[n],e[n+1]]=[e[n+1],e[n]],ed(e)}},[ee,ed]),ex=(0,o.useMemo)(()=>{let e=ee.map((e,r)=>{let o="relation"===e.type?null==s?void 0:s[e.name]:void 0,l="relation"===e.type?null==i?void 0:i[e.name]:void 0;return{id:e.id,accessorKey:e.name,meta:{label:e.name,fieldName:e.name,fieldType:e.type},header:t=>{let{column:o}=t;if(H===e.id)return(0,n.jsx)(nd,{currentName:e.name,onSave:t=>void eu(e.id,t),onCancel:()=>V(null)});let l=(null==q?void 0:q.fieldId)===e.id;return(0,n.jsxs)("span",{className:"flex items-center gap-1.5 w-full",style:{color:"var(--color-text-muted)"},onClick:t=>{t.stopPropagation(),J(t=>t===e.id?null:e.id)},children:[(0,n.jsx)(ns,{type:e.type,size:12,className:"shrink-0 opacity-50"}),(0,n.jsx)("span",{className:"truncate",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 shrink-0",children:["(",(0,M.PV)(e.related_object_name),")"]}),l&&q&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-[10px] font-medium shrink-0 animate-pulse",style:{color:"var(--color-warning, #f59e0b)"},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:"M13 2 3 14h9l-1 8 10-12h-9l1-8z"})}),q.current,"/",q.total]}),(0,n.jsx)(ni,{field:e,sortDirection:o.getIsSorted(),onSort:e=>o.toggleSorting(e),onHide:()=>o.toggleVisibility(!1),onRename:()=>V(e.id),onDelete:()=>eh(e.id,e.name),onOptionsUpdate:t=>ep(e.id,t),canMoveLeft:r>0,canMoveRight:r<ee.length-1,onMoveLeft:()=>em(e.id,"left"),onMoveRight:()=>em(e.id,"right"),onReEnrich:t=>X(e.id,t),open:K===e.id,onOpenChange:t=>J(t?e.id:null)})]})},cell:s=>{let i=s.row.original.entry_id,c=String(null!=i&&"object"==typeof i?JSON.stringify(i):null!=i?i:""),m=$.has(c)&&(null==q?void 0:q.fieldId)===e.id;if(0===r&&p)return(0,n.jsx)(nI,{value:s.getValue(),entryId:c,onEntryClick:p});let x=(0,n.jsx)(nL,{value:s.getValue(),entryId:c,fieldName:e.name,objectName:t,field:e,members:a,fieldRelationLabels:o,fieldRelationFaviconUrls:l,onNavigateObject:d,onNavigateEntry:u,onLocalValueChange:en,onSaved:h,showUrlFavicon:0!==r});return m?(0,n.jsx)("div",{className:"enrich-fade-in enrich-glow -mx-3 -my-2 px-3 py-2",children:x}):x},size:"richtext"===e.type?300:"relation"===e.type||"tags"===e.type?220:200,enableSorting:!0}});for(let t of(e.push({id:"created_at",accessorFn:e=>ny(e,nx),meta:{label:"Created",fieldName:"created_at",fieldType:"date"},header:()=>(0,n.jsx)("span",{className:"flex items-center gap-1",style:{color:"var(--color-text-muted)"},children:"Created"}),cell:e=>(0,n.jsx)(rJ,{value:e.getValue(),fieldType:"date",mode:"table"}),size:190,enableSorting:!0}),e.push({id:"updated_at",accessorFn:e=>ny(e,nf),meta:{label:"Updated",fieldName:"updated_at",fieldType:"date"},header:()=>(0,n.jsx)("span",{className:"flex items-center gap-1",style:{color:"var(--color-text-muted)"},children:"Updated"}),cell:e=>(0,n.jsx)(rJ,{value:e.getValue(),fieldType:"date",mode:"table"}),size:190,enableSorting:!0}),eo))e.push({id:"rev_".concat(t.sourceObjectName,"_").concat(t.fieldName),meta:{label:"".concat((0,M.PV)(t.sourceObjectName)," (via ").concat(t.fieldName,")"),fieldType:"relation"},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",{children:(0,M.PV)(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)(nT,{links:a,sourceObjectName:t.sourceObjectName,sourceObjectId:t.sourceObjectId,onNavigateObject:d,onNavigateEntry:u})},enableSorting:!1,size:200});for(let r of et){let o=n_(r.default_value);0!==o.length&&e.push({id:"action_".concat(r.id),meta:{label:r.name,fieldName:r.name,fieldType:"action"},header:()=>(0,n.jsx)("span",{className:"flex items-center gap-1",style:{color:"var(--color-text-muted)"},children:r.name}),cell:e=>{let l=e.row.original.entry_id,a=String(null!=l&&"object"==typeof l?JSON.stringify(l):null!=l?l:"");return(0,n.jsx)("div",{className:"flex items-center gap-1",onClick:e=>e.stopPropagation(),children:o.map(e=>(0,n.jsx)(rX,{action:e,entryId:a,objectName:t,fieldId:r.id,compact:o.length>1,onToast:U,onRequestConfirm:(e,t,r)=>{var n;W({open:!0,title:e.label,message:null!=(n=e.confirmMessage)?n:'Run "'.concat(e.label,'" on this entry?'),variant:"destructive"===e.variant?"destructive":"default",confirmLabel:e.label,onConfirm:()=>{W(null),r()}})}},e.id))})},enableSorting:!1,enableHiding:!0,size:Math.max(100,100*o.length)})}return e},[ee,et,eo,t,a,s,i,d,u,p,h,en,U,H,eu,ep,eh,em,q,X,$,K]),ef=(0,o.useCallback)(()=>{C?C():A(!0)},[C]),ev=(0,o.useCallback)(()=>Object.keys(I).filter(e=>I[e]).map(e=>{var t;return nv(null==(t=F[Number(e)])?void 0:t.entry_id)}).filter(Boolean),[I,F]),eg=(0,o.useCallback)(async()=>{let e=ev();if(0!==e.length)try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/entries/bulk-delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({entryIds:e})}),_({}),null==h||h()}catch(e){}},[ev,t,h]),ey=(0,o.useCallback)(()=>{let e=ev().length;0!==e&&W({open:!0,title:"Delete ".concat(e," ").concat(1===e?"entry":"entries","?"),message:"This action cannot be undone. All selected entries will be permanently removed.",variant:"destructive",confirmLabel:"Delete",onConfirm:()=>{W(null),eg()}})},[ev,eg]),eb=(0,o.useMemo)(()=>{let e=[];for(let t of ee){let r=no(t.default_value);r&&e.push({fieldId:t.id,fieldName:t.name,apolloPath:r.enrichment.apolloPath,category:r.enrichment.category,inputFieldName:r.enrichment.inputFieldName})}return e},[ee]),ej=(0,o.useCallback)(async()=>{let e=ev();if(0!==e.length&&0!==eb.length)for(let t of eb)await new Promise(r=>{let n=()=>r();Q({fieldId:t.fieldId,fieldName:t.fieldName,apolloPath:t.apolloPath,category:t.category,inputFieldName:t.inputFieldName,scope:"all",entryIds:e});let o=()=>{var e;if((null==(e=Z.current)?void 0:e.signal.aborted)||null===ek.current)return void n();setTimeout(o,80)};setTimeout(o,80)})},[eb,ev,Q]),ek=(0,o.useRef)(q);(0,o.useEffect)(()=>{ek.current=q},[q]);let ew=(0,o.useCallback)(e=>{let r=e.entry_id,n=String(null!=r&&"object"==typeof r?JSON.stringify(r):null!=r?r:"");n&&W({open:!0,title:"Delete this entry?",message:"This action cannot be undone.",variant:"destructive",confirmLabel:"Delete",onConfirm:async()=>{W(null);try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/entries/").concat(encodeURIComponent(n)),{method:"DELETE"}),null==h||h()}catch(e){}}})},[t,h]),eN=(0,o.useCallback)((e,r)=>{let n=ev();if(0===n.length)return;let o=()=>void O(e,r,t,n,{autoResetMs:e.autoResetMs,onToast:U});e.confirmMessage?W({open:!0,title:"".concat(e.label," (").concat(n.length," entries)"),message:e.confirmMessage,variant:"destructive"===e.variant?"destructive":"default",confirmLabel:e.label,onConfirm:()=>{W(null),o()}}):o()},[ev,t,O,U]),eC=(0,o.useCallback)(e=>{let t=[];return p&&t.push({label:"View details",onClick:e=>{var t;let r=String(null!=(t=e.entry_id)?t:"");r&&p(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:ew,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},[p,ew]),eS=Object.keys(I).filter(e=>I[e]).length,eM=(0,o.useRef)(r);eM.current=r;let eT=(0,o.useRef)(Q);eT.current=Q;let eL=(0,o.useCallback)(()=>null==h?void 0:h(),[h]),eI=(0,o.useCallback)(e=>eT.current(e),[]),e_=(0,o.useMemo)(()=>(0,n.jsx)(np,{objectName:t,onCreated:eL,fields:eM.current,onEnrichmentStart:eI}),[t,eL,eI]),eR=(0,o.useRef)(ee);eR.current=ee;let eE=(0,o.useCallback)(e=>{j&&j(e.map(e=>{var t;let r=e.desc?"desc":"asc";if("created_at"===e.id||"updated_at"===e.id)return{field:e.id,direction:r};let n=eR.current.find(t=>t.id===e.id);return{field:null!=(t=null==n?void 0:n.name)?t:e.id,direction:r}}))},[j]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t2,{columns:ex,data:F,enableSorting:!0,enableGlobalFilter:!0,enableRowSelection:!0,enableCellSelection:!0,enableColumnReordering:!0,rowSelection:I,onRowSelectionChange:_,cellSelection:R,onCellSelectionChange:E,onColumnReorder:ed,searchPlaceholder:"Search ".concat((0,M.PV)(t),"..."),onRefresh:h,onAdd:ef,addButtonLabel:"+ Add",rowActions:eC,rowActionsHeader:e_,stickyFirstColumn:!0,stickyFirstColumnValue:S,onStickyFirstColumnChange:T,activeRowId:m,getRowId:nb,initialColumnVisibility:x,onColumnVisibilityChanged:f,initialColumnSizing:v,onColumnSizingChange:g,serverPagination:y,onServerSearch:b,onSortChange:j?eE:void 0,hideToolbar:k,globalFilter:w,onGlobalFilterChange:N,getFirstDataColumnFaviconUrl:ec,disableHeaderClickSort:!0}),(0,n.jsx)(r4,{selectedCount:eS,actions:er,onDeselectAll:()=>_({}),onBulkAction:eN,onBulkDelete:ey,bulkRunStates:z,onBulkEnrich:eb.length>0?ej:void 0,enrichBusy:null!==q}),B&&(0,n.jsx)(r0,{open:B.open,title:B.title,message:B.message,variant:B.variant,confirmLabel:B.confirmLabel,onConfirm:B.onConfirm,onCancel:()=>W(null)}),D&&(0,n.jsx)(nE,{objectName:t,fields:ee,members:a,onClose:()=>A(!1),onSaved:h})]})}function nE(e){let{objectName:t,fields:r,members:l,onClose:a,onSaved:s}=e,[i,c]=(0,o.useState)({}),[d,u]=(0,o.useState)(!1),p=(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}))},m=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:p,onClick:e=>{e.target===p.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-4 mb-4 mx-3 md:mt-12 md:mb-12 md:mx-0 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",style:{color:"var(--color-text)"},children:["Add ",(0,M.A3)(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(),m()},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,p="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:["(",(0,M.PV)(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)(nM,{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)(re,{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((0,M.A3)(e.related_object_name),"...")}):p?(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:ng(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 m(),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 nD(e,t){for(let r of[...t.filter(e=>"url"===e.type),...t.filter(e=>"url"!==e.type)]){let t=function(e,t){let r=rL(e,t);if("link"===r.kind&&"url"===r.linkType&&r.href&&r.faviconUrl)return{href:r.href,text:r.text,faviconUrl:r.faviconUrl}}(e[r.name],r.type);if(t)return t}}function nA(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 nF(e){let{entry:t,fields:r,members:o,relationLabels:l,onEntryClick:a,objectName:s,onToast:i}=e,c=nA(t.entry_id)||"",{attributes:d,listeners:u,setNodeRef:p,isDragging:h}=(0,G.PM)({id:c,data:{entry:t}});return(0,n.jsx)("div",{ref:p,...u,...d,onClick:e=>{!h&&a&&(e.stopPropagation(),a(c))},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(h?"var(--color-accent)":"var(--color-border)"),opacity:h?.4:1,transform:h?"scale(1.02)":void 0},children:(0,n.jsx)(nP,{entry:t,fields:r,members:o,relationLabels:l,objectName:s,onToast:i})})}function nP(e){let{entry:t,fields:r,members:o,relationLabels:l,objectName:a,onToast:s}=e,i=function(e,t){var r;let n=t.find(e=>e.name.toLowerCase().includes("name")||e.name.toLowerCase().includes("title"));return n?nA(e[n.name])||"Untitled":nA(e[null==(r=t[0])?void 0:r.name])||"Untitled"}(t,r),c=nD(t,r),d=r.filter(e=>"action"===e.type),u=r.filter(e=>"action"!==e.type).filter(e=>"richtext"!==e.type&&null!==t[e.name]&&void 0!==t[e.name]&&""!==t[e.name]).slice(0,4),p=r.find(e=>e.name.toLowerCase().includes("name")||e.name.toLowerCase().includes("title"));return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1.5 min-w-0",style:{color:"var(--color-text)"},children:[(null==c?void 0:c.faviconUrl)&&(0,n.jsx)(t$,{src:c.faviconUrl,className:"w-4 h-4 rounded-[4px] shrink-0"}),(0,n.jsx)("div",{className:"text-sm font-medium truncate min-w-0",children:i})]}),(0,n.jsx)("div",{className:"space-y-1",children:u.filter(e=>e!==p).slice(0,3).map(e=>{let r=t[e.name];if(!r)return null;let a=nA(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?rq(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)(nB,{value:nA(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=rL(e),r="link"===t.kind&&t.href,o="url"===t.linkType&&!!t.faviconUrl;return r?(0,n.jsxs)("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 gap-1 px-1.5 py-0 rounded text-[11px] font-medium hover:underline underline-offset-2 max-w-[220px]",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-accent)"},children:[o&&(0,n.jsx)(t$,{src:t.faviconUrl,className:"w-3 h-3 rounded-[2px] shrink-0"}),(0,n.jsx)("span",{className:"min-w-0 truncate",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)})}),a&&d.length>0&&(0,n.jsx)("div",{className:"flex items-center gap-1 mt-2 pt-1.5",style:{borderTop:"1px solid var(--color-border)"},onClick:e=>e.stopPropagation(),children:d.flatMap(e=>(function(e){if(!e)return[];try{let t=JSON.parse(e);if(t&&Array.isArray(t.actions))return t.actions}catch(e){}return[]})(e.default_value).map(r=>{var o;return(0,n.jsx)(rX,{action:r,entryId:String(null!=(o=t.entry_id)?o:""),objectName:a,fieldId:e.id,compact:!0,onToast:s},"".concat(e.id,"_").concat(r.id))}))})]})}function nB(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 nW(e){let{columnName:t,color:r,items:l,cardFields:a,members:s,relationLabels:i,onEntryClick:c,isOver:d,groupFieldId:u,objectName:p,onRefresh:h,onToast:m}=e,{setNodeRef:x}=(0,G.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||!u){v(!1),y(t);return}j(!0);try{(await fetch("/api/workspace/objects/".concat(encodeURIComponent(p),"/fields/").concat(encodeURIComponent(u),"/enum-rename"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldValue:t,newValue:e})})).ok?null==h||h():y(t)}catch(e){y(t)}finally{j(!1),v(!1)}},[g,t,u,p,h]);return(0,n.jsxs)("div",{ref:x,className:"flex-shrink-0 flex flex-col rounded-xl transition-colors duration-150",style:{width:"280px",background:d?"var(--color-surface)":"var(--color-bg)",border:"1px solid ".concat(d?"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:()=>{u&&(y(t),v(!0))},title:u?"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:d?"var(--color-accent)":"var(--color-border)",color:d?"var(--color-accent)":"var(--color-text-muted)"},children:d?"Drop here":"No entries"}):l.map((e,t)=>(0,n.jsx)(nF,{entry:e,fields:a,members:s,relationLabels:i,onEntryClick:c,objectName:p,onToast:m},nA(e.entry_id)||String(t)))})]})}function nO(e){var t;let{objectName:r,fields:l,entries:a,statuses:s,members:i,relationLabels:c,onEntryClick:d,onRefresh:u}=e,p=r3(),[h,m]=(0,o.useState)(null),[x,f]=(0,o.useState)(null),[v,g]=(0,o.useState)(a);(0,o.useEffect)(()=>{g(a)},[a]);let y=(0,G.FR)((0,G.MS)(G.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(s.length>0)return s.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(nA(r))}return Array.from(e).map(e=>({name:e,color:"#94a3b8"}))},[s,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?nA(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=>{m(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)},[]),T=(0,o.useCallback)(async e=>{m(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=nA(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==u||u():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,u]);return b?(0,n.jsxs)(G.Mp,{sensors:y,collisionDetection:G.y$,onDragStart:C,onDragOver:S,onDragEnd:T,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)(nW,{columnName:e.name,color:e.color,items:null!=(t=k[e.name])?t:[],cardFields:w,members:i,relationLabels:c,onEntryClick:d,isOver:x===e.name,groupFieldId:b.id,objectName:r,onRefresh:u,onToast:p},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)(nF,{entry:e,fields:w,members:i,relationLabels:c,onEntryClick:d,objectName:r,onToast:p},nA(e.entry_id)||String(t)))})]})]}),(0,n.jsx)(G.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)(nP,{entry:N,fields:w,members:i,objectName:r,relationLabels:c,onToast:p})}):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:(0,M.PV)(r)})]})})}var nz=r(70739),nU=r(30489),nH=r(75885),nV=r(65316),nK=r(1059),nJ=r(38804),nq=r(45609),nG=r(98540),n$=r(14716),nY=r(92423),nZ=r(3904),nQ=r(67977),nX=r(39682),n0=r(99509),n1=r(89748),n2=r(25277),n4=r(67697),n5=r(77894),n3=r(74575),n6=r(76149),n8=r(49054),n7=r(67034),n9=r(12904),oe=r(84373),ot=r(65440),or=r(75096);function on(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 oo(e){return(0,nU.GP)(e,"yyyy-MM-dd")}function ol(e){return e.toISOString()}function oa(e,t,r){switch(t){case"day":return 1===r?(0,nH.f)(e,1):(0,nV.e)(e,1);case"week":return 1===r?(0,nK.J)(e,1):(0,nJ.k)(e,1);case"month":return 1===r?(0,nq.P)(e,1):(0,nG.a)(e,1);case"year":return 1===r?(0,n$.e)(e,1):(0,nY.d)(e,1)}}function os(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.jsx)("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:(0,n.jsxs)("span",{className:"flex min-w-0 items-center gap-1",children:[!o&&(0,n.jsx)("span",{className:"opacity-70 shrink-0",children:(0,nU.GP)(r.date,"HH:mm")}),r.faviconUrl&&(0,n.jsx)(t$,{src:r.faviconUrl,className:"w-3 h-3 rounded-[2px] shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:r.title||"Untitled"})]})})}function oi(e){let{date:t,events:r,onEntryClick:l,onEntryDateChange:a}=e,[s,i]=(0,o.useState)(null),c=(0,o.useRef)(null),d=(0,nX.w)(t),u=(0,n0.p)(t),p=(0,nZ.k)(d,{weekStartsOn:1}),h=(0,nQ.$)(u,{weekStartsOn:1}),m=(0,n1.k)({start:p,end:h}),x=(0,o.useMemo)(()=>{let e=new Map;for(let t of r){let r=(0,nU.GP)(t.date,"yyyy-MM-dd");if(e.has(r)||e.set(r,[]),e.get(r).push(t),t.endDate&&!(0,n2.r)(t.date,t.endDate))for(let r of(0,n1.k)({start:(0,nH.f)(t.date,1),end:t.endDate})){let n=(0,nU.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,n2.r)(r.date,t))return;let n=(0,n4.o)((0,n5.o)(t),(0,n5.o)(r.date)),o=(0,n3.z)(r.date,n),l={entryId:r.id,newDate:oo(o)};r.endDate&&(l.newEndDate=oo((0,n3.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:m.map(e=>{var r;let o=(0,nU.GP)(e,"yyyy-MM-dd"),i=null!=(r=x.get(o))?r:[],c=(0,n6.t)(e,t),d=(0,n8.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,nU.GP)(e,"d")}),(0,n.jsxs)("div",{className:"flex flex-col gap-0.5",children:[i.slice(0,3).map(e=>(0,n.jsx)(os,{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 oc(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}),p=(0,n7.O)(r.date)/60*l,h=r.endDate?Math.max((0,n4.o)(r.endDate,r.date),15):30,m=h/60*l,[x,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,n9.q)(r.date)+(0,n7.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,n3.z)(r.date,t),n={entryId:r.id,newDate:ol(e)};r.endDate&&(n.newEndDate=ol((0,n3.z)(r.endDate,t))),s(n)}else if("resize"===c&&0!==t){var n;let e=(0,n3.z)(null!=(n=r.endDate)?n:(0,n3.z)(r.date,h),t);e>r.date&&s({entryId:r.id,newDate:ol(r.date),newEndDate:ol(e)})}d(null),f(0),g(0)},[c,s,r,l,h]),w=p+("move"===c?x:0),N=Math.max(m+("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:[(0,n.jsxs)("span",{className:"flex min-w-0 items-center gap-1",children:[r.faviconUrl&&(0,n.jsx)(t$,{src:r.faviconUrl,className:"w-3 h-3 rounded-[2px] shrink-0"}),(0,n.jsx)("span",{className:"truncate",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 od(e){let{date:t,events:r,onEntryClick:l,onEntryDateChange:a}=e,s=(0,nZ.k)(t,{weekStartsOn:1}),i=(0,n1.k)({start:s,end:(0,nH.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,nU.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,n8.c)(e)?"var(--color-accent)":"var(--color-text)"},children:[(0,n.jsx)("div",{children:(0,nU.GP)(e,"EEE")}),(0,n.jsx)("div",{className:"text-lg ".concat((0,n8.c)(e)?"font-bold":""),children:(0,nU.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,nU.GP)(new Date(2e3,0,1,e),"ha")},"label-".concat(e)),i.map(t=>{var r;let o=(0,nU.GP)(t,"yyyy-MM-dd"),s=(null!=(r=d.get(o))?r:[]).filter(t=>(0,n9.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)(oc,{event:e,hourHeight:60,onEntryClick:l,onEntryDateChange:a},e.id))},"".concat(o,"-").concat(e))})]}))]})})}function ou(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,n2.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,n9.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,nU.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)(oc,{event:e,hourHeight:60,onEntryClick:l,onEntryDateChange:a},e.id))},"cell-".concat(e))]})})})})}function op(e){let{date:t,events:r}=e,l=(0,oe.D)(t),a=(0,ot.Q)(t),s=(0,or.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,nX.w)(e),o=(0,n0.p)(e),l=(0,nZ.k)(r,{weekStartsOn:1}),a=(0,nQ.$)(o,{weekStartsOn:1}),s=(0,n1.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,nU.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,n6.t)(t,e),o=(0,n8.c)(t),l=c.some(e=>(0,n2.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,nU.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 oh(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 om(e){let{objectName:t,fields:r,entries:l,dateField:a,endDateField:s,mode:i,onModeChange:c,members:d,onEntryClick:u,onEntryDateChange:p}=e,[h,m]=(0,o.useState)(()=>new Date),x=(0,o.useMemo)(()=>(function(e,t,r,n){let o=[];for(let s of e){let e=on(s[r]);if(e)try{var l,a;let r,i=(0,nz.H)(e);if(Number.isNaN(i.getTime()))continue;if(n){let e=on(s[n]);if(e){let t=(0,nz.H)(e);Number.isNaN(t.getTime())||(r=t)}}o.push({id:on(null!=(a=s.entry_id)?a:s.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?on(e[n.name]):on(e.id)}(s,t),faviconUrl:null==(l=nD(s,t))?void 0:l.faviconUrl,date:i,endDate:r,entry:s,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=on(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}(s,t)})}catch(e){}}return o})(l,r,a,s),[l,r,a,s]),f=(0,o.useCallback)(()=>m(e=>oa(e,i,-1)),[i]),v=(0,o.useCallback)(()=>m(e=>oa(e,i,1)),[i]),g=(0,o.useCallback)(()=>m(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,nU.GP)(e,"EEEE, MMMM d, yyyy");case"week":{let t=(0,nZ.k)(e,{weekStartsOn:1}),r=(0,nQ.$)(e,{weekStartsOn:1});return"".concat((0,nU.GP)(t,"MMM d")," - ").concat((0,nU.GP)(r,"MMM d, yyyy"))}case"month":return(0,nU.GP)(e,"MMMM yyyy");case"year":return(0,nU.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)(oi,{date:h,events:x,onEntryClick:u,onEntryDateChange:p}),"week"===i&&(0,n.jsx)(od,{date:h,events:x,onEntryClick:u,onEntryDateChange:p}),"day"===i&&(0,n.jsx)(ou,{date:h,events:x,onEntryClick:u,onEntryDateChange:p}),"year"===i&&(0,n.jsx)(op,{date:h,events:x})]})]}):(0,n.jsx)(oh,{reason:"no-date-field"})}var ox=r(35933),of=r(22507),ov=r(88382),og=r(29788);let oy={day:{dayWidth:80,headerFormat:"MMM d"},week:{dayWidth:30,headerFormat:"MMM d"},month:{dayWidth:10,headerFormat:"MMM yyyy"},quarter:{dayWidth:4,headerFormat:"QQQ yyyy"}},ob=["#3b82f6","#22c55e","#f59e0b","#ef4444","#8b5cf6","#06b6d4","#ec4899","#14b8a6","#f97316","#6366f1"];function oj(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 ok(e){return(0,nU.GP)(e,"yyyy-MM-dd")}function ow(e){let{item:t,x:r,w:l,dayWidth:a,onEntryClick:s,onEntryDateChange:i}=e,[c,d]=(0,o.useState)(null),[u,p]=(0,o.useState)(0),[h,m]=(0,o.useState)(0),x=(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(),x.current=e.clientX,d(t),e.target.setPointerCapture(e.pointerId))},[f]),b=(0,o.useCallback)(e=>{if(!c)return;let t=v(e.clientX-x.current);"move"===c?p(t):"resize-left"===c?(p(t),m(-t)):m(t)},[c,v]),j=(0,o.useCallback)(e=>{if(!c||!i)return void d(null);let r=g(e.clientX-x.current);if(0===r&&"move"===c){d(null),p(0),m(0);return}let n=t.startDate,o=t.endDate;"move"===c?(n=(0,nH.f)(t.startDate,r),o=(0,nH.f)(t.endDate,r)):"resize-left"===c?(n=(0,nH.f)(t.startDate,r))>=o&&(n=(0,nH.f)(o,-1)):(o=(0,nH.f)(t.endDate,r))<=n&&(o=(0,nH.f)(n,1)),i({entryId:t.id,newStartDate:ok(n),newEndDate:ok(o)}),d(null),p(0),m(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,nU.GP)(t.startDate,"MMM d")," - ").concat((0,nU.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.jsxs)("span",{className:"px-2 flex min-w-0 items-center gap-1.5 flex-1",children:[t.faviconUrl&&k>84&&(0,n.jsx)(t$,{src:t.faviconUrl,className:"w-3 h-3 rounded-[2px] shrink-0"}),(0,n.jsx)("span",{className:"truncate",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 oN(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 oC(e){let{objectName:t,fields:r,entries:l,startDateField:a,endDateField:s,groupField:i,zoom:c,onZoomChange:d,members:u,onEntryClick:p,onEntryDateChange:h}=e,m=(0,o.useRef)(null),x=(0,o.useMemo)(()=>(function(e,t,r,n,o){let l=[];for(let i=0;i<e.length;i++){let c=e[i],d=oj(c[r]);if(d)try{var a,s;let e,r=(0,nz.H)(d);if(Number.isNaN(r.getTime()))continue;if(n){let t=oj(c[n]);if(t){let n=(0,nz.H)(t);e=Number.isNaN(n.getTime())?(0,nH.f)(r,1):n}else e=(0,nH.f)(r,1)}else e=(0,nH.f)(r,1);e<=r&&(e=(0,nH.f)(r,1)),l.push({id:oj(null!=(s=c.entry_id)?s:c.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?oj(e[n.name]):oj(e.id)}(c,t),faviconUrl:null==(a=nD(c,t))?void 0:a.faviconUrl,startDate:r,endDate:e,group:o?oj(c[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=oj(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 ob[r%ob.length]}(c,t,i),entry:c})}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,nG.a)(e,1),end:(0,nq.P)(e,2)}}let r=(0,ox.j)(e.map(e=>e.startDate)),n=(0,of.T)(e.map(e=>e.endDate)),o="day"===t?3:"week"===t?7:"month"===t?14:30;return{start:(0,nH.f)(r,-o),end:(0,nH.f)(n,o)}})(x,c),[x,c]),{dayWidth:g}=oy[c],y=((0,og.c)(v,f)+1)*g,b=(0,o.useMemo)(()=>(function(e,t,r){switch(r){case"day":return(0,n1.k)({start:e,end:t}).map(e=>({date:e,label:(0,nU.GP)(e,"MMM d")}));case"week":return(0,ov.Y)({start:e,end:t},{weekStartsOn:1}).map(e=>({date:e,label:(0,nU.GP)(e,"MMM d")}));case"month":return(0,or.i)({start:e,end:t}).map(e=>({date:e,label:(0,nU.GP)(e,"MMM yyyy")}));case"quarter":return(0,or.i)({start:e,end:t}).filter(e=>e.getMonth()%3==0).map(e=>({date:e,label:(0,nU.GP)(e,"QQQ yyyy")}))}})(f,v,c),[f,v,c]),j=(0,o.useMemo)(()=>{if(!i)return[{name:"",items:x}];let e=new Map;for(let t of x){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}})},[x,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,og.c)(e,f)*g,[f,g]);if((0,o.useEffect)(()=>{if(!m.current)return;let e=w(new Date);m.current.scrollLeft=Math.max(0,e-300)},[w]),!a)return(0,n.jsx)(oN,{reason:"no-fields"});if(0===x.length)return(0,n.jsx)(oN,{reason:"no-items"});let N=w((0,n5.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:[x.length," item",1!==x.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,o;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==p?void 0:p(e.item.id)),children:"group"===e.type?e.group:(0,n.jsxs)("span",{className:"flex min-w-0 items-center gap-1.5",children:[(null==(r=e.item)?void 0:r.faviconUrl)&&(0,n.jsx)(t$,{src:e.item.faviconUrl,className:"w-3.5 h-3.5 rounded-[3px] shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:(null==(o=e.item)?void 0:o.title)||"Untitled"})]})},t)})]}),(0,n.jsx)("div",{ref:m,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)(ow,{item:t,x:r,w:o,dayWidth:g,onEntryClick:p,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 oS(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 oM(e){var t;let{entry:r,fields:l,titleField:a,coverField:s,onEntryClick:i}=e,c=oS(null!=(t=r.entry_id)?t:r.id),d=function(e,t,r){var n;if(r){let t=oS(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?oS(e[o.name]):oS(e.id)}(r,l,a),u=nD(r,l),p=(0,o.useMemo)(()=>l.filter(e=>e.name!==a&&e.name!==s).slice(0,4),[l,a,s]),h=l.find(e=>{var t;return"enum"===e.type&&(null==(t=e.enum_values)?void 0:t.length)}),m=h?oS(r[h.name]):null,x=h&&m?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"}}(m,h):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.jsxs)("div",{className:"flex min-w-0 items-start gap-2",children:[(null==u?void 0:u.faviconUrl)&&(0,n.jsx)(t$,{src:u.faviconUrl,className:"w-4 h-4 rounded-[4px] shrink-0 mt-0.5"}),(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"})]}),x&&(0,n.jsx)("span",{className:"text-[10px] px-2 py-0.5 rounded-full flex-shrink-0 whitespace-nowrap",style:{backgroundColor:x.color,color:"#fff"},children:x.text})]}),(0,n.jsx)("div",{className:"flex flex-col gap-1.5",children:p.map(e=>{let t=r[e.name];if(null==t||""===oS(t))return null;let o="tags"===e.type?rq(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=rL(e),r="link"===t.kind&&t.href,o="url"===t.linkType&&!!t.faviconUrl;return r?(0,n.jsxs)("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 gap-1 px-1.5 py-0 rounded text-[11px] font-medium hover:underline underline-offset-2 max-w-[220px]",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-accent)"},children:[o&&(0,n.jsx)(t$,{src:t.faviconUrl,className:"w-3 h-3 rounded-[2px] shrink-0"}),(0,n.jsx)("span",{className:"min-w-0 truncate",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)(rJ,{value:t,fieldType:e.type,mode:"table",showUrlFavicon:!0})})]},e.id)})}),null!=r.created_at&&(0,n.jsx)("div",{className:"mt-3 text-[10px]",style:{color:"var(--color-text-muted)",opacity:.6},children:oS(r.created_at).slice(0,10)})]})}function oT(){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 oL(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)(oT,{}):(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)(oM,{entry:e,fields:r,titleField:l,coverField:a,onEntryClick:c},oS(null!=(t=e.entry_id)?t:e.id))})})}function oI(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 o_(e){var t,r;let{entry:l,fields:a,titleField:s,subtitleField:i,onEntryClick:c}=e,d=oI(null!=(t=l.entry_id)?t:l.id),u=function(e,t,r){var n;if(r){let t=oI(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?oI(e[o.name]):oI(e.id)}(l,a,s),p=nD(l,a),h=(0,o.useMemo)(()=>{if(i){let e=oI(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?oI(l[e.name]):void 0},[l,a,s,i]),m=a.find(e=>{var t;return"enum"===e.type&&(null==(t=e.enum_values)?void 0:t.length)}),x=m?oI(l[m.name]):null,f=m&&x?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"}}(x,m):null,v=a.find(e=>"tags"===e.type),g=v?rq(l[v.name]):[],y=a.find(e=>"date"===e.type),b=y?oI(l[y.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==f?void 0:f.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.jsxs)("div",{className:"flex min-w-0 items-center gap-2",children:[(null==p?void 0:p.faviconUrl)&&(0,n.jsx)(t$,{src:p.faviconUrl,className:"w-4 h-4 rounded-[4px] shrink-0"}),(0,n.jsx)("span",{className:"text-[13px] font-medium truncate group-hover:underline",style:{color:"var(--color-text)"},children:u||"Untitled"})]}),f&&(0,n.jsx)("span",{className:"text-[10px] px-2 py-0.5 rounded-full flex-shrink-0",style:{backgroundColor:f.color,color:"#fff"},children:f.text}),g.slice(0,3).map(e=>{let t=rL(e),r="link"===t.kind&&t.href,o="url"===t.linkType&&!!t.faviconUrl;return r?(0,n.jsxs)("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 gap-1 text-[10px] px-1.5 py-0.5 rounded-full flex-shrink-0 hover:underline underline-offset-2 max-w-[220px]",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-accent)",border:"1px solid var(--color-border)"},children:[o&&(0,n.jsx)(t$,{src:t.faviconUrl,className:"w-3 h-3 rounded-[2px] shrink-0"}),(0,n.jsx)("span",{className:"min-w-0 truncate",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)})]}),h&&(0,n.jsx)("div",{className:"text-[11px] whitespace-pre-line line-clamp-1 mt-0.5",style:{color:"var(--color-text-muted)"},children:h})]}),b&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0 tabular-nums",style:{color:"var(--color-text-muted)"},children:b.slice(0,10)})]})}function oR(){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 oE(e){let{objectName:t,fields:r,entries:o,titleField:l,subtitleField:a,members:s,onEntryClick:i}=e;return 0===o.length?(0,n.jsx)(oR,{}):(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)(o_,{entry:e,fields:r,titleField:l,subtitleField:a,onEntryClick:i},oI(null!=(t=e.entry_id)?t:e.id))})})}let oD=["table","kanban","calendar","timeline","gallery","list"];function oA(e){return"string"==typeof e&&oD.includes(e)}function oF(e,t,r){return(null==e?void 0:e.view_type)&&oA(e.view_type)?e.view_type:t&&oA(t)?t:r&&oA(r)?r:"table"}function oP(e,t,r){var n,o,l,a,s,i,c,d,u,p,h,m;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==(p=r.find(e=>"text"===e.type))?void 0:p.name;case"galleryCoverField":default:return;case"listSubtitleField":return null==(m=r.find(e=>"text"===e.type&&!/name|title/i.test(e.name)))?void 0:m.name}}let oB=[{value:"is_empty",label:"is empty"},{value:"is_not_empty",label:"is not empty"}],oW=[{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"},...oB],oO=[{value:"eq",label:"="},{value:"neq",label:"≠"},{value:"gt",label:">"},{value:"gte",label:"≥"},{value:"lt",label:"<"},{value:"lte",label:"≤"},{value:"between",label:"between"},...oB],oz=[{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"},...oB],oU=[{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"},...oB],oH=[{value:"is_true",label:"is true"},{value:"is_false",label:"is false"},...oB],oV=[{value:"has_any",label:"has any of"},{value:"has_none",label:"has none of"},{value:"has_all",label:"has all of"},...oB],oK=[{value:"contains",label:"contains"},{value:"not_contains",label:"does not contain"},...oB];function oJ(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 oq(e){return"conjunction"in e&&"rules"in e}function oG(e){return btoa(JSON.stringify(e))}function o$(){return{id:"root",conjunction:"and",rules:[]}}function oY(){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"})})}let oZ={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 oQ(e){let{value:t,onChange:r,collapsed:l=!1}=e,[a,s]=(0,o.useState)(!1),i=(0,o.useRef)(null);if((0,o.useEffect)(()=>{if(!a)return;let e=e=>{i.current&&!i.current.contains(e.target)&&s(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[a]),l){let e=oZ[t],o=e.icon;return(0,n.jsxs)("div",{ref:i,className:"relative inline-block flex-shrink-0",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>s(e=>!e),className:"flex items-center gap-1.5 px-2.5 py-1 text-[12px] rounded-md transition-colors cursor-pointer",style:{background:"var(--color-surface-hover)",color:"var(--color-text)",fontWeight:500},children:[(0,n.jsx)(o,{}),(0,n.jsx)("span",{children:e.label}),(0,n.jsx)(oY,{})]}),a&&(0,n.jsx)("div",{className:"absolute z-50 mt-1 left-0 rounded-lg shadow-lg border py-1 min-w-[140px]",style:{background:"var(--color-surface)",borderColor:"var(--color-border)"},children:oD.map(e=>{let o=oZ[e],l=o.icon,a=e===t;return(0,n.jsxs)("button",{type:"button",onClick:()=>{r(e),s(!1)},className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs transition-colors cursor-pointer text-left",style:{background:a?"var(--color-accent-light, rgba(99,102,241,0.1))":"transparent",color:a?"var(--color-accent)":"var(--color-text)",fontWeight:a?500:400},children:[(0,n.jsx)(l,{}),o.label]},e)})})]})}return(0,n.jsx)("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:oD.map(e=>{let o=oZ[e],l=o.icon,a=e===t;return(0,n.jsx)("button",{type:"button",onClick:()=>r(e),className:"flex items-center justify-center w-7 h-7 rounded-md transition-colors cursor-pointer",style:{background:a?"var(--color-surface-hover)":"transparent",color:a?"var(--color-text)":"var(--color-text-muted)"},title:o.label,"aria-label":o.label,children:(0,n.jsx)(l,{})},e)})})}function oX(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 o0(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 o1(e){let{settings:t,fields:r,onSettingsChange:o}=e;return(0,n.jsx)(oX,{label:"Group by field",value:t.kanbanField,onChange:e=>o({...t,kanbanField:e}),fields:r,filterType:"enum"})}function o2(e){var t;let{settings:r,fields:o,onSettingsChange:l}=e;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(oX,{label:"Date field",value:r.calendarDateField,onChange:e=>l({...r,calendarDateField:e}),fields:o,filterType:"date"}),(0,n.jsx)(oX,{label:"End date field (optional)",value:r.calendarEndDateField,onChange:e=>l({...r,calendarEndDateField:e}),fields:o,filterType:"date",allowEmpty:!0}),(0,n.jsx)(o0,{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 o4(e){var t;let{settings:r,fields:o,onSettingsChange:l}=e;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(oX,{label:"Start date field",value:r.timelineStartField,onChange:e=>l({...r,timelineStartField:e}),fields:o,filterType:"date"}),(0,n.jsx)(oX,{label:"End date field",value:r.timelineEndField,onChange:e=>l({...r,timelineEndField:e}),fields:o,filterType:"date",allowEmpty:!0}),(0,n.jsx)(oX,{label:"Group by (optional)",value:r.timelineGroupField,onChange:e=>l({...r,timelineGroupField:e}),fields:o,filterType:"enum",allowEmpty:!0}),(0,n.jsx)(o0,{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 o5(e){let{settings:t,fields:r,onSettingsChange:o}=e;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(oX,{label:"Title field",value:t.galleryTitleField,onChange:e=>o({...t,galleryTitleField:e}),fields:r,filterType:"text"}),(0,n.jsx)(oX,{label:"Cover field (optional)",value:t.galleryCoverField,onChange:e=>o({...t,galleryCoverField:e}),fields:r,allowEmpty:!0})]})}function o3(e){let{settings:t,fields:r,onSettingsChange:o}=e;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(oX,{label:"Title field",value:t.listTitleField,onChange:e=>o({...t,listTitleField:e}),fields:r,filterType:"text"}),(0,n.jsx)(oX,{label:"Subtitle field (optional)",value:t.listSubtitleField,onChange:e=>o({...t,listSubtitleField:e}),fields:r,filterType:["text","email","richtext"],allowEmpty:!0})]})}function o6(){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 o8(e){let{children:t}=e;return(0,n.jsx)("div",{className:"text-[10px] font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:t})}function o7(e){let{description:t}=e;return(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,n.jsx)(o8,{children:"About"}),(0,n.jsx)("p",{className:"text-[12px] leading-snug",style:{color:"var(--color-text)"},children:t})]})}function o9(e){let{displayField:t,candidates:r,onChange:o,updating:l}=e;return(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,n.jsx)(o8,{children:"Display field"}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("select",{value:null!=t?t:"",onChange:e=>o(e.target.value),disabled:l,className:"text-[12px] rounded-md border px-2 py-1.5 flex-1 outline-none cursor-pointer",style:{borderColor:"var(--color-border)",color:"var(--color-text)",background:"var(--color-surface)",opacity:l?.5:1},children:r.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 shrink-0",style:{borderColor:"var(--color-text-muted)"}})]})]})}function le(e){let{fields:t,columnVisibility:r,onColumnVisibilityChange:o,stickyFirstColumn:l,onStickyFirstColumnChange:a}=e;return(0,n.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,n.jsx)(o8,{children:"Columns"}),a&&(0,n.jsxs)("label",{className:"flex items-center gap-2 text-[12px] cursor-pointer",style:{color:"var(--color-text)"},children:[(0,n.jsx)("input",{type:"checkbox",checked:!!l,onChange:e=>a(e.target.checked),className:"cursor-pointer"}),"Freeze first column"]}),(0,n.jsx)("div",{className:"flex flex-col gap-1 max-h-48 overflow-y-auto rounded-md border p-1.5",style:{borderColor:"var(--color-border)"},children:0===t.length?(0,n.jsx)("div",{className:"text-[11px] px-1 py-0.5",style:{color:"var(--color-text-muted)"},children:"No columns"}):t.map(e=>{let t=!1!==r[e.id];return(0,n.jsxs)("label",{className:"flex items-center gap-2 text-[12px] cursor-pointer px-1 py-0.5 rounded hover:bg-[var(--color-surface-hover)]",style:{color:"var(--color-text)"},children:[(0,n.jsx)("input",{type:"checkbox",checked:t,onChange:()=>(e=>{let t=!1!==r[e];o({...r,[e]:!t})})(e.id),className:"cursor-pointer"}),(0,n.jsx)("span",{className:"truncate",children:e.name})]},e.id)})})]})}function lt(e){let{viewType:t,settings:r,fields:l,onSettingsChange:a,description:s,displayField:i,displayFieldCandidates:c,onDisplayFieldChange:d,updatingDisplayField:u,columnVisibility:p,onColumnVisibilityChange:h,stickyFirstColumn:m,onStickyFirstColumnChange:x}=e,[f,v]=(0,o.useState)(!1),g=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!f)return;let e=e=>{g.current&&!g.current.contains(e.target)&&v(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[f]);let y=!!(s&&s.trim()),b=!!(c&&c.length>0&&d),j=!!(h&&"table"===t);return y||b||j||"table"!==t?(0,n.jsxs)("div",{className:"relative",ref:g,children:[(0,n.jsx)("button",{type:"button",onClick:()=>v(!f),className:"flex items-center justify-center w-7 h-7 rounded-md hover:bg-[var(--color-surface-hover)] transition-colors cursor-pointer",style:{color:"var(--color-text-muted)"},title:"View settings","aria-label":"View settings",children:(0,n.jsx)(o6,{})}),f&&(0,n.jsxs)("div",{className:"absolute right-0 top-full mt-1 z-50 rounded-lg border shadow-lg p-3 min-w-[220px] sm:min-w-[260px] max-w-[calc(100vw-2rem)] 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:"Table Settings",kanban:"Board Settings",calendar:"Calendar Settings",timeline:"Timeline Settings",gallery:"Gallery Settings",list:"List Settings"}[t]}),y&&(0,n.jsx)(o7,{description:s}),b&&(0,n.jsx)(o9,{displayField:i,candidates:c,onChange:d,updating:!!u}),"kanban"===t&&(0,n.jsx)(o1,{settings:r,fields:l,onSettingsChange:a}),"calendar"===t&&(0,n.jsx)(o2,{settings:r,fields:l,onSettingsChange:a}),"timeline"===t&&(0,n.jsx)(o4,{settings:r,fields:l,onSettingsChange:a}),"gallery"===t&&(0,n.jsx)(o5,{settings:r,fields:l,onSettingsChange:a}),"list"===t&&(0,n.jsx)(o3,{settings:r,fields:l,onSettingsChange:a}),j&&(0,n.jsx)(le,{fields:l,columnVisibility:null!=p?p:{},onColumnVisibilityChange:h,stickyFirstColumn:m,onStickyFirstColumnChange:x})]})]}):null}let lr="denchclaw:icon-picker:recent",ln=["target","user","users","building","building-2","mail","calendar","phone","briefcase","handshake","rocket","star","heart","flag","bookmark","tag","folder","file-text","message-square","send","zap","sparkles","check-square","shield","key","link","globe","map-pin","dollar-sign","trending-up"].filter(e=>T.k.includes(e));function lo(){try{let e=window.localStorage.getItem(lr);if(!e)return[];let t=JSON.parse(e);if(!Array.isArray(t))return[];return t.filter(e=>"string"==typeof e&&T.k.includes(e)).slice(0,18)}catch(e){return[]}}function ll(e){let{value:t,onChange:r,title:l}=e,[a,s]=(0,o.useState)(!1),[i,c]=(0,o.useState)(""),[d,u]=(0,o.useState)([]),p=(0,o.useRef)(null),h=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!a)return;u(lo()),c("");let e=window.setTimeout(()=>{var e;return null==(e=h.current)?void 0:e.focus()},10);return()=>window.clearTimeout(e)},[a]),(0,o.useEffect)(()=>{if(!a)return;let e=e=>{p.current&&!p.current.contains(e.target)&&s(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[a]),(0,o.useEffect)(()=>{if(!a)return;let e=e=>{"Escape"===e.key&&(e.stopPropagation(),s(!1))};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[a]);let m=i.trim().toLowerCase(),x=(0,o.useMemo)(()=>{if(!m)return[];let e=[];for(let t of T.k)if(t.includes(m)&&(e.push(t),e.length>=200))break;return e},[m]),f=(0,o.useCallback)(e=>{r(e);try{let t=lo(),r=[e,...t.filter(t=>t!==e)].slice(0,18);window.localStorage.setItem(lr,JSON.stringify(r))}catch(e){}s(!1)},[r]),v=(0,o.useCallback)(()=>{r(null),s(!1)},[r]);return(0,n.jsxs)("div",{className:"relative",ref:p,children:[(0,n.jsx)("button",{type:"button",onClick:()=>s(e=>!e),className:"flex items-center justify-center w-7 h-7 rounded-md transition-colors cursor-pointer",style:{color:"var(--color-text-muted)",background:a?"var(--color-surface-hover)":"transparent"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{a||(e.currentTarget.style.background="transparent")},title:null!=l?l:"Change icon","aria-label":"Change icon","aria-expanded":a,children:(0,n.jsx)(I,{name:null!=t?t:null,size:16})}),a&&(0,n.jsxs)("div",{className:"absolute left-0 top-full mt-1 z-50 rounded-lg border shadow-lg flex flex-col",style:{borderColor:"var(--color-border)",background:"var(--color-surface)",boxShadow:"0 8px 24px rgba(0,0,0,0.12)",width:320,maxWidth:"calc(100vw - 2rem)"},children:[(0,n.jsx)("div",{className:"p-2 border-b",style:{borderColor:"var(--color-border)"},children:(0,n.jsx)("input",{ref:h,type:"text",value:i,onChange:e=>c(e.target.value),placeholder:"Search icons…",className:"w-full px-2 py-1.5 rounded-md text-[12px] outline-none border",style:{color:"var(--color-text)",background:"var(--color-bg)",borderColor:"var(--color-border)"}})}),(0,n.jsx)("div",{className:"overflow-y-auto",style:{maxHeight:320},children:m?(0,n.jsx)(ls,{icons:x,value:null!=t?t:null,onSelect:f,emptyText:"No icons found"}):(0,n.jsxs)(n.Fragment,{children:[d.length>0&&(0,n.jsx)(la,{label:"Recent",children:(0,n.jsx)(ls,{icons:d,value:null!=t?t:null,onSelect:f})}),(0,n.jsx)(la,{label:"Popular",children:(0,n.jsx)(ls,{icons:ln,value:null!=t?t:null,onSelect:f})})]})}),(0,n.jsxs)("div",{className:"px-3 py-2 border-t flex items-center justify-between",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("button",{type:"button",onClick:v,className:"text-[11px] transition-colors cursor-pointer",style:{color:"var(--color-text-muted)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--color-text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--color-text-muted)"},children:"Clear icon"}),(0,n.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:"lucide icons"})]})]})]})}function la(e){let{label:t,children:r}=e;return(0,n.jsxs)("div",{className:"px-2 pt-2 pb-1",children:[(0,n.jsx)("div",{className:"px-1 pb-1 text-[9px] lowercase",style:{color:"var(--color-text-muted)",letterSpacing:"0.05em"},children:t}),r]})}function ls(e){let{icons:t,value:r,onSelect:o,emptyText:l}=e;return 0===t.length?(0,n.jsx)("div",{className:"py-6 text-center text-[11px]",style:{color:"var(--color-text-muted)"},children:null!=l?l:"No icons"}):(0,n.jsx)("div",{className:"grid gap-0.5",style:{gridTemplateColumns:"repeat(auto-fill, 32px)"},children:t.map(e=>{let t=e===r;return(0,n.jsx)("button",{type:"button",onClick:()=>o(e),className:"w-8 h-8 rounded-md flex items-center justify-center transition-colors cursor-pointer",style:{color:"var(--color-text)",background:t?"var(--color-chat-sidebar-active-bg)":"transparent"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="transparent")},title:e,"aria-label":e,children:(0,n.jsx)(T.A,{name:e,size:16})},e)})})}var li=r(24946);function lc(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 ld(e){return e.includes("```report-json")}function lu(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 lp(e){return e.includes("```diff")}function lh(){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 lm(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 lx(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)(lm,{expanded:r}),(0,n.jsx)(lh,{}),(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 lf(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)(lx,{file:e},t))})}let lv=(0,li.default)(()=>r.e(53867).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%"}})]})}),lg=(0,li.default)(()=>r.e(45477).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)"}})}),ly=(0,li.default)(()=>Promise.resolve().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 lb(e){let{content:t,title:r,filePath:l,tree:a,onSave:s,onDirty:i,onNavigate:c,searchFn:d}=e,[u,p]=(0,o.useState)(!!l),h=t.replace(/^---\s*\n[\s\S]*?\n---\s*\n/,""),m=h.match(/^#\s+(.+)/m),x=null!=r?r:null==m?void 0:m[1],f=x&&m?h.replace(/^#\s+.+\n?/,""):h;if(u&&l)return(0,n.jsx)(ly,{content:h,rawContent:t,filePath:l,tree:null!=a?a:[],onSave:s,onDirty:i,onNavigate:c,searchFn:d});let v=ld(f)||lp(f),g=(0,o.useCallback)(e=>{let t=e.target.closest("a");if(!t)return;let r=t.getAttribute("href");if(r){if(r.startsWith("#")){var n;e.preventDefault(),e.stopPropagation();let t=r.slice(1),o=e.currentTarget,l=null!=(n=Array.from(o.querySelectorAll("h1, h2, h3, h4, h5, h6")).find(e=>(e.textContent||"").trim().toLowerCase().replace(/[^\w\s-]/g,"").replace(/\s+/g,"-")===t))?n:o.querySelector('[id="'.concat(CSS.escape(t),'"]'));null==l||l.scrollIntoView({behavior:"smooth",block:"start"});return}if(c){if((0,rt.m9)(r)||!r.startsWith("http://")&&!r.startsWith("https://")&&!r.startsWith("mailto:")){e.preventDefault(),e.stopPropagation(),c(r);return}e.preventDefault(),e.stopPropagation(),window.open(r,"_blank","noopener,noreferrer")}}},[c]);return(0,n.jsxs)("div",{className:"px-6 py-8",onClick:g,children:[(0,n.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[x&&(0,n.jsx)("h1",{className:"text-3xl font-bold mb-6 flex-1",style:{color:"var(--color-text)"},children:x}),l&&(0,n.jsxs)("button",{type:"button",onClick:()=>p(!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"})]})]}),v?(0,n.jsx)(lj,{content:f}):(0,n.jsx)("div",{className:"workspace-prose",children:(0,n.jsx)(lv,{content:f})})]})}function lj(e){let{content:t}=e,r=lc(t),o=[];for(let e of r)if("text"===e.type&&lp(e.text))for(let t of lu(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)(lg,{config:e.config})},t):"diff-artifact"===e.type?(0,n.jsx)("div",{className:"my-4",children:(0,n.jsx)(lf,{diff:e.diff})},t):(0,n.jsx)("div",{className:"workspace-prose",children:(0,n.jsx)(lv,{content:e.text})},t))})}var lk=r(81584),lw=r(13292);let lN=new Set(["csv","tsv"]);function lC(e){var t,r;return null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:""}function lS(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 lM(e){let{state:t,onClose:r,onInsertRowAbove:l,onInsertRowBelow:a,onInsertColLeft:s,onInsertColRight:i,onDeleteRow:c,onDeleteCol:d,onClearCells:u}=e,p=(0,o.useRef)(null);if((0,o.useEffect)(()=>{if(!t)return;let e=e=>{p.current&&!p.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:p,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 lT(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),p=(0,o.useRef)(null);(0,o.useEffect)(()=>{var e;null==(e=p.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:p,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 lL(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 lI(){return(0,n.jsx)("div",{style:{width:"1px",height:"18px",background:"var(--color-border)",margin:"0 4px",flexShrink:0}})}function l_(e){var t,r;let{url:l,filename:a,filePath:s,compact:i=!1,onDirty:c}=e,[d,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(0),[m,x]=(0,o.useState)(null),[f,v]=(0,o.useState)(!1),[g,y]=(0,o.useState)(!1),[b,j]=(0,o.useState)(!1),[k,w]=(0,o.useState)(null),[N,C]=(0,o.useState)(null),[S,M]=(0,o.useState)(null),[T,L]=(0,o.useState)(!1),I=(0,o.useRef)(null),[_,R]=(0,o.useState)([]),[E,D]=(0,o.useState)([]);(0,o.useEffect)(()=>{let e=!1;return u(null),h(0),x(null),v(!1),R([]),D([]),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,lw.LF)(t,{type:"array"}),n=r.SheetNames.map(e=>({name:e,data:function(e){let t=lw.Wp.sheet_to_json(e,{header:1,defval:""});if(0===t.length)return(0,lk.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,lk.JH)(50,26)}),u(n)}).catch(t=>{e||x(String(t))}),()=>{e=!0}},[l]);let A=null!=(r=null==d||null==(t=d[p])?void 0:t.data)?r:[],F=(0,o.useMemo)(()=>{let e=0;for(let t of A)t&&(e=Math.max(e,t.length));return e},[A]),P=(0,o.useMemo)(()=>Array.from({length:F},(e,t)=>lS(t)),[F]),B=(0,o.useCallback)(()=>{d&&(R(e=>[...e.slice(-49),{sheetIdx:p,data:d[p].data}]),D([]))},[d,p]),W=(0,o.useCallback)(e=>{u(t=>{if(!t)return t;let r=[...t];return r[p]={...r[p],data:e},r}),v(!0),null==c||c()},[p,c]),O=(0,o.useCallback)(e=>{B(),W(e)},[B,W]),z=(0,o.useCallback)(()=>{if(0===_.length||!d)return;let e=_[_.length-1];D(e=>[...e,{sheetIdx:p,data:d[p].data}]),R(e=>e.slice(0,-1)),u(t=>{if(!t)return t;let r=[...t];return r[e.sheetIdx]={...r[e.sheetIdx],data:e.data},r}),e.sheetIdx!==p&&h(e.sheetIdx)},[_,d,p]),U=(0,o.useCallback)(()=>{if(0===E.length||!d)return;let e=E[E.length-1];R(e=>[...e,{sheetIdx:p,data:d[p].data}]),D(e=>e.slice(0,-1)),u(t=>{if(!t)return t;let r=[...t];return r[e.sheetIdx]={...r[e.sheetIdx],data:e.data},r}),e.sheetIdx!==p&&h(e.sheetIdx)},[E,d,p]),H=(0,o.useCallback)(e=>{B();let t=Array.from({length:F},()=>({value:""})),r=[...A];r.splice(e,0,t),W(r)},[B,W,A,F]),V=(0,o.useCallback)(e=>{if(A.length<=1)return;B();let t=[...A];t.splice(e,1),W(t)},[B,W,A]),K=(0,o.useCallback)(e=>{B(),W(A.map(t=>{let r=[...null!=t?t:[]];return r.splice(e,0,{value:""}),r}))},[B,W,A]),J=(0,o.useCallback)(e=>{F<=1||(B(),W(A.map(t=>{let r=[...null!=t?t:[]];return r.splice(e,1),r})))},[B,W,A,F]),q=(0,o.useCallback)(()=>{if(!N)return;let e=N.toRange(A);if(!e)return;B();let t=A.map(e=>e?[...e]:[]);for(let r of e)t[r.row]&&(t[r.row][r.column]={value:""});W(t)},[N,A,B,W]),G=(0,o.useCallback)(async()=>{if(d&&!g){y(!0);try{if(lN.has(lC(a))){let e="tsv"===lC(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")}(d[p].data,e);if(!(await fetch((0,Z.nC)(s),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:s,content:t})})).ok)throw Error("Save failed")}else{let e=lw.Wp.book_new();for(let t of d)lw.Wp.book_append_sheet(e,function(e){let t=e.map(e=>(null!=e?e:[]).map(e=>e?e.value:""));return lw.Wp.aoa_to_sheet(t)}(t.data),t.name);let t=(0,lw.M9)(e,{type:"array",bookType:lC(a)});if(!(await fetch("/api/workspace/raw-file?path=".concat(encodeURIComponent(s)),{method:"POST",body:t})).ok)throw Error("Save failed")}v(!1),j(!0),setTimeout(()=>j(!1),1500)}catch(e){console.error("Spreadsheet save error:",e)}finally{y(!1)}}},[d,g,a,s,p]);(0,o.useEffect)(()=>{let e=e=>{let t=e.metaKey||e.ctrlKey;t&&"s"===e.key&&(e.preventDefault(),G()),t&&"z"===e.key&&!e.shiftKey&&(e.preventDefault(),z()),t&&"z"===e.key&&e.shiftKey&&(e.preventDefault(),U()),t&&"f"===e.key&&(e.preventDefault(),L(e=>!e))};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[G,z,U]);let $=(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||M({x:e.clientX,y:e.clientY,row:o,col:l})},[]),Y=(0,o.useCallback)(e=>{var t;w(e),null==(t=I.current)||t.activate(e),C(new lk.MH(new lk.m9(e,e)))},[]),Q=(0,o.useMemo)(()=>{var e;if(!k)return"";let t=null==(e=A[k.row])?void 0:e[k.column];return t?String(t.value):""},[k,A]),X=(0,o.useCallback)(e=>{if(!k)return;B();let t=A.map(e=>e?[...e]:[]);t[k.row]||(t[k.row]=[]),t[k.row][k.column]={value:e},W(t)},[k,A,B,W]),ee=(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}})(A,N),[A,N]),et=lC(a).toUpperCase()||"SPREADSHEET";return m?(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:"12px",padding:"24px"},children:[(0,n.jsx)(lR,{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:m})]}):d?(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)(lR,{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:et}),f&&(0,n.jsx)("span",{style:{fontSize:"10px",padding:"1px 6px",borderRadius:"4px",background:"var(--color-warning)",color:"#fff",fontWeight:500,flexShrink:0},children:"Unsaved"}),b&&(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)(lL,{onClick:G,title:"Save (⌘S)",disabled:!f||g,accent: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)("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)(lI,{}),(0,n.jsx)(lL,{onClick:z,title:"Undo (⌘Z)",disabled:0===_.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)(lL,{onClick:U,title:"Redo (⌘⇧Z)",disabled:0===E.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)(lI,{}),(0,n.jsx)(lL,{onClick:()=>k&&H(k.row),title:"Insert row above",disabled:!k,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)(lL,{onClick:()=>k&&K(k.column),title:"Insert column left",disabled:!k,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)(lI,{}),(0,n.jsx)(lL,{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&&f&&(0,n.jsx)(lL,{onClick:G,title:"Save (⌘S)",disabled:g,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:k?"".concat(lS(k.column)).concat(k.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:Q,onChange:e=>X(e.target.value),placeholder:"Select a cell",style:{flex:1,background:"transparent",border:"none",outline:"none",fontSize:"12px",color:"var(--color-text)",fontFamily:"monospace"}})]}),T&&(0,n.jsx)(lT,{data:A,onNavigate:Y,onClose:()=>L(!1)}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto",position:"relative"},onContextMenu:$,children:(0,n.jsx)(lk.Ay,{ref:I,data:A,onChange:O,columnLabels:P,onActivate:w,onSelect:C,darkMode:"undefined"!=typeof document&&document.documentElement.classList.contains("dark"),className:"spreadsheet-editor-grid"})}),(0,n.jsx)(lM,{state:S,onClose:()=>M(null),onInsertRowAbove:()=>S&&H(S.row),onInsertRowBelow:()=>S&&H(S.row+1),onInsertColLeft:()=>S&&K(S.col),onInsertColRight:()=>S&&K(S.col+1),onDeleteRow:()=>S&&V(S.row),onDeleteCol:()=>S&&J(S.col),onClearCells:q}),d.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:d.map((e,t)=>(0,n.jsxs)("button",{type:"button",onClick:()=>h(t),style:{padding:i?"4px 10px":"6px 16px",fontSize:i?"10px":"11px",fontWeight:t===p?600:400,color:t===p?"var(--color-text)":"var(--color-text-muted)",background:t===p?"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===p&&(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:[A.length," row",1!==A.length?"s":""," \xd7 ",F," col",1!==F?"s":"",d.length>1?" \xb7 ".concat(d.length," sheets"):""]}),ee&&(0,n.jsxs)("span",{style:{textAlign:"right"},children:["Count: ",ee.count,ee.numericCount>0&&(0,n.jsxs)(n.Fragment,{children:[" \xb7 ","Sum: ",ee.sum.toLocaleString()," \xb7 ","Avg: ",ee.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 lR(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 lE=r(35778);let lD=null;function lA(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),p=(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)(lB,{}),(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)(lW,{}),"Preview"]}),(0,n.jsxs)("button",{type:"button",onClick:p,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)(lO,{}),"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)(lz,{})})]}),"rendered"===a?(0,n.jsx)(lF,{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)(lP,{content:i})]})}function lF(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 lP(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(!lD&&(lD=(0,lE.O_)({themes:["github-dark","github-light"],langs:["html"]})),lD).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)(lO,{}),(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 lB(){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 lW(){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 lO(){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 lz(){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"})]})}let lU="undefined"!=typeof globalThis?globalThis:window;lU.__denchAppRegistry||(lU.__denchAppRegistry=new Map),lU.__denchAppMessageHandlers||(lU.__denchAppMessageHandlers=new Set);let lH=lU.__denchAppRegistry;function lV(e,t){return"/api/apps/serve/".concat(e,"/").concat(t)}function lK(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return!!e&&r.some(t=>e.includes(t))}function lJ(e){let{appPath:t,manifest:r,onToast:l,onNavigate:a}=e,s=(0,o.useRef)(null),[i,c]=(0,o.useState)(!0),[d,u]=(0,o.useState)(null),p=(0,o.useRef)(null),h=(0,o.useRef)(new Set),m=(0,o.useRef)(new Map),x=(0,o.useRef)(new Map),f=lV(t,r.entry||"index.html"),v=r.permissions||[],g=t.split("/").pop()||t,y=(0,o.useCallback)(()=>{c(!0),u(null),s.current&&(s.current.src="".concat(f,"?_t=").concat(Date.now()))},[f]),b=(0,o.useCallback)(()=>{c(!1)},[]),j=(0,o.useCallback)(()=>{c(!1),u("Failed to load app")},[]);(0,o.useEffect)(()=>{let e,t={appName:g,iframe:s.current,tools:new Map};return p.current=t,(e=lH.get(t.appName))||(e=new Set,lH.set(t.appName,e)),e.add(t),()=>{let e=lH.get(t.appName);for(let r of(e&&(e.delete(t),0===e.size&&lH.delete(t.appName)),m.current.values()))clearInterval(r);m.current.clear()}},[g]),(0,o.useEffect)(()=>{function e(e,t,r,n){var o;null==(o=e.contentWindow)||o.postMessage(n?{type:"dench:response",id:t,error:n}:{type:"dench:response",id:t,result:r},"*")}function n(e,t,r){var n;null==(n=e.contentWindow)||n.postMessage({type:"dench:event",channel:t,data:r},"*")}let o=async o=>{var d,u;let f=s.current;if(!(null==f?void 0:f.contentWindow)||o.source!==f.contentWindow)return;if((null==(d=o.data)?void 0:d.type)==="dench:tool-response"){let{invokeId:e,result:t,error:r}=o.data,n=x.current.get(e);n&&(x.current.delete(e),r?n.reject(Error(r)):n.resolve(t));return}if(!o.data||"dench:request"!==o.data.type)return;let{id:y,method:b,params:j}=o.data;try{let o;if("app.getManifest"===b)o=r;else if("app.getTheme"===b)o=document.documentElement.classList.contains("dark")?"dark":"light";else if("context.getWorkspace"===b)o={name:t.split("/")[0]||"workspace"};else if("context.getAppInfo"===b)o={appPath:t,folderName:g,permissions:v,manifest:r};else if("db.query"===b&&lK(v,"database","database:write")){let e=await fetch("/api/workspace/query",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sql:null==j?void 0:j.sql})});o=await e.json()}else if("db.execute"===b&&lK(v,"database:write")){let e=await fetch("/api/workspace/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sql:null==j?void 0:j.sql})});o=await e.json()}else if("objects.list"===b&&lK(v,"objects")){let e=new URLSearchParams;(null==j?void 0:j.filters)&&e.set("filters",j.filters),(null==j?void 0:j.sort)&&e.set("sort",j.sort),(null==j?void 0:j.search)&&e.set("search",j.search),(null==j?void 0:j.page)&&e.set("page",String(j.page)),(null==j?void 0:j.pageSize)&&e.set("pageSize",String(j.pageSize));let t=await fetch("/api/workspace/objects/".concat(encodeURIComponent(null==j?void 0:j.name),"?").concat(e));o=await t.json()}else if("objects.get"===b&&lK(v,"objects")){let e=await fetch("/api/workspace/objects/".concat(encodeURIComponent(null==j?void 0:j.name),"/entries/").concat(encodeURIComponent(null==j?void 0:j.entryId)));o=await e.json()}else if("objects.create"===b&&lK(v,"objects")){let e=await fetch("/api/workspace/objects/".concat(encodeURIComponent(null==j?void 0:j.name),"/entries"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:null==j?void 0:j.fields})});o=await e.json(),c(f,"object.entry.created",null==j?void 0:j.name,o)}else if("objects.update"===b&&lK(v,"objects")){let e=await fetch("/api/workspace/objects/".concat(encodeURIComponent(null==j?void 0:j.name),"/entries/").concat(encodeURIComponent(null==j?void 0:j.entryId)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:null==j?void 0:j.fields})});o=await e.json(),c(f,"object.entry.updated",null==j?void 0:j.name,{entryId:null==j?void 0:j.entryId})}else if("objects.delete"===b&&lK(v,"objects")){let e=await fetch("/api/workspace/objects/".concat(encodeURIComponent(null==j?void 0:j.name),"/entries/").concat(encodeURIComponent(null==j?void 0:j.entryId)),{method:"DELETE"});o=await e.json(),c(f,"object.entry.deleted",null==j?void 0:j.name,{entryId:null==j?void 0:j.entryId})}else if("objects.bulkDelete"===b&&lK(v,"objects")){let e=await fetch("/api/workspace/objects/".concat(encodeURIComponent(null==j?void 0:j.name),"/entries/bulk-delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({entryIds:null==j?void 0:j.entryIds})});o=await e.json(),c(f,"object.entry.deleted",null==j?void 0:j.name,{entryIds:null==j?void 0:j.entryIds})}else if("objects.getSchema"===b&&lK(v,"objects")){let e=await fetch("/api/workspace/objects/".concat(encodeURIComponent(null==j?void 0:j.name),"?schemaOnly=1"));o=await e.json()}else if("objects.getOptions"===b&&lK(v,"objects")){let e=(null==j?void 0:j.query)?"?q=".concat(encodeURIComponent(j.query)):"",t=await fetch("/api/workspace/objects/".concat(encodeURIComponent(null==j?void 0:j.name),"/entries/options").concat(e));o=await t.json()}else if("files.read"===b&&lK(v,"files","files:write")){let e=await fetch("/api/workspace/file?path=".concat(encodeURIComponent(null==j?void 0:j.path)));o=await e.json()}else if("files.list"===b&&lK(v,"files","files:write")){let e=(null==j?void 0:j.dir)?"?path=".concat(encodeURIComponent(j.dir)):"?showHidden=0",t=await fetch("/api/workspace/browse".concat(e));o=await t.json()}else if("files.write"===b&&lK(v,"files:write")){let e=await fetch("/api/workspace/file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:null==j?void 0:j.path,content:null==j?void 0:j.content})});o=await e.json()}else if("files.delete"===b&&lK(v,"files:write")){let e=await fetch("/api/workspace/file?path=".concat(encodeURIComponent(null==j?void 0:j.path)),{method:"DELETE"});o=await e.json()}else if("files.mkdir"===b&&lK(v,"files:write")){let e=await fetch("/api/workspace/mkdir",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:null==j?void 0:j.path})});o=await e.json()}else if("chat.createSession"===b&&lK(v,"agent")){let e=await fetch("/api/web-sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:null==j?void 0:j.title})});o=await e.json()}else if("chat.send"===b&&lK(v,"agent")){let e=null==j?void 0:j._streamId,t=await fetch("/api/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({messages:[{role:"user",content:null==j?void 0:j.message}],sessionId:null==j?void 0:j.sessionId})});if(e&&t.body){let r=t.body.getReader(),n=new TextDecoder,l="",a="";for(;;){let{done:t,value:o}=await r.read();if(t)break;let s=(l+=n.decode(o,{stream:!0})).split("\n");for(let t of(l=s.pop()||"",s))if(t.startsWith("data: "))try{let r=JSON.parse(t.slice(6));!function(e,t,r,n,o){var l;null==(l=e.contentWindow)||l.postMessage({type:"dench:stream",streamId:t,event:r,data:n,...o},"*")}(f,e,r.type,r.data,{name:r.name,args:r.args,result:r.result}),"text-delta"===r.type&&"string"==typeof r.data&&(a+=r.data)}catch(e){}}o={text:a}}else o=await t.json()}else if("chat.getHistory"===b&&lK(v,"agent")){let e=await fetch("/api/web-sessions/".concat(encodeURIComponent(null==j?void 0:j.sessionId),"/messages"));o=await e.json()}else if("chat.getSessions"===b&&lK(v,"agent")){let e=(null==j?void 0:j.limit)?"?limit=".concat(j.limit):"",t=await fetch("/api/web-sessions".concat(e));o=await t.json()}else if("chat.abort"===b&&lK(v,"agent")){let e=await fetch("/api/chat/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:null==j?void 0:j.sessionId})});o=await e.json()}else if("chat.isActive"===b&&lK(v,"agent")){let e=await fetch("/api/chat/active"),t=await e.json();o=!!Array.isArray(t)&&t.includes(null==j?void 0:j.sessionId)}else if("agent.send"===b&&lK(v,"agent"))o={ok:(await fetch("/api/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({messages:[{role:"user",content:null==j?void 0:j.message}]})})).ok};else if("tool.register"===b&&lK(v,"agent")){let e=p.current;if(e&&(null==j?void 0:j.name)){let t={name:j.name,description:j.description||"",inputSchema:j.inputSchema};e.tools.set(j.name,t)}o={ok:!0}}else if("memory.get"===b&&lK(v,"agent")){let e=await fetch("/api/memories");o=await e.json()}else if("ui.toast"===b&&lK(v,"ui"))l&&l(null==j?void 0:j.message,{type:null==j?void 0:j.type}),o={ok:!0};else if("ui.navigate"===b&&lK(v,"ui"))a&&a(null==j?void 0:j.path),o={ok:!0};else if("ui.openEntry"===b&&lK(v,"ui"))a&&a("/".concat(null==j?void 0:j.objectName,"/").concat(null==j?void 0:j.entryId)),o={ok:!0};else if("ui.setTitle"===b&&lK(v,"ui"))window.dispatchEvent(new CustomEvent("dench:app-title-change",{detail:{appPath:t,title:null==j?void 0:j.title}})),o={ok:!0};else if("ui.confirm"===b&&lK(v,"ui"))o=window.confirm((null==j?void 0:j.message)||"");else if("ui.prompt"===b&&lK(v,"ui"))o=window.prompt((null==j?void 0:j.message)||"",(null==j?void 0:j.defaultValue)||"");else if("store.get"===b&&lK(v,"store")){let e=await fetch("/api/apps/store?app=".concat(encodeURIComponent(g),"&key=").concat(encodeURIComponent(null==j?void 0:j.key)));o=(await e.json()).value}else if("store.set"===b&&lK(v,"store")){let e=await fetch("/api/apps/store",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({app:g,key:null==j?void 0:j.key,value:null==j?void 0:j.value})});o=await e.json()}else if("store.delete"===b&&lK(v,"store")){let e=await fetch("/api/apps/store?app=".concat(encodeURIComponent(g),"&key=").concat(encodeURIComponent(null==j?void 0:j.key)),{method:"DELETE"});o=await e.json()}else if("store.list"===b&&lK(v,"store")){let e=await fetch("/api/apps/store?app=".concat(encodeURIComponent(g)));o=(await e.json()).keys}else if("store.clear"===b&&lK(v,"store")){let e=await fetch("/api/apps/store?app=".concat(encodeURIComponent(g)),{method:"DELETE"});o=await e.json()}else if("http.fetch"===b&&lK(v,"http")){let e=await fetch("/api/apps/proxy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:null==j?void 0:j.url,method:null==j?void 0:j.method,headers:null==j?void 0:j.headers,body:null==j?void 0:j.body})});o=await e.json()}else if("events.subscribe"===b){h.current.add(null==j?void 0:j.channel),(null==j?void 0:j.channel)==="theme.changed"&&(u=f,i||(i=new MutationObserver(()=>{h.current.has("theme.changed")&&n(u,"theme.changed",{theme:document.documentElement.classList.contains("dark")?"dark":"light"})})).observe(document.documentElement,{attributes:!0,attributeFilter:["class"]})),o={ok:!0}}else if("events.unsubscribe"===b)h.current.delete(null==j?void 0:j.channel),o={ok:!0};else if("apps.send"===b&&lK(v,"apps"))!function(e,t,r){let n=lH.get(e);if(n&&0!==n.size)for(let e of n){var o;null==(o=e.iframe.contentWindow)||o.postMessage({type:"dench:event",channel:"apps.message",data:{from:r,message:t}},"*")}}(null==j?void 0:j.targetApp,null==j?void 0:j.message,g),o={ok:!0};else if("apps.list"===b&&lK(v,"apps"))o=function(){let e=[];for(let[t,r]of lH)e.push({name:t,instanceCount:r.size});return e}();else if("cron.schedule"===b&&lK(v,"cron")){let e=await fetch("/api/apps/cron",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"add",params:{expression:null==j?void 0:j.expression,message:null==j?void 0:j.message,channel:null==j?void 0:j.channel}})});o=await e.json()}else if("cron.list"===b&&lK(v,"cron")){let e=await fetch("/api/apps/cron");o=await e.json()}else if("cron.run"===b&&lK(v,"cron")){let e=await fetch("/api/apps/cron",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"run",params:{id:null==j?void 0:j.jobId}})});o=await e.json()}else if("cron.cancel"===b&&lK(v,"cron")){let e=await fetch("/api/apps/cron",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"remove",params:{id:null==j?void 0:j.jobId}})});o=await e.json()}else if("webhooks.register"===b&&lK(v,"webhooks"))o={url:"".concat(window.location.origin,"/api/apps/webhooks/").concat(encodeURIComponent(g),"/").concat(encodeURIComponent(null==j?void 0:j.hookName)),hookName:null==j?void 0:j.hookName};else if("webhooks.subscribe"===b&&lK(v,"webhooks")){let e=null==j?void 0:j.hookName;if(e&&!m.current.has(e)){let t=Date.now(),r=setInterval(async()=>{try{var r;let o=await fetch("/api/apps/webhooks/".concat(encodeURIComponent(g),"/").concat(encodeURIComponent(e),"?poll=1&since=").concat(t)),l=await o.json();if(null==(r=l.events)?void 0:r.length)for(let r of(t=Math.max(...l.events.map(e=>e.receivedAt)),l.events))n(f,"webhooks.".concat(e),r)}catch(e){}},5e3);m.current.set(e,r)}o={ok:!0}}else if("webhooks.poll"===b&&lK(v,"webhooks")){let e=(null==j?void 0:j.since)||0,t=await fetch("/api/apps/webhooks/".concat(encodeURIComponent(g),"/").concat(encodeURIComponent(null==j?void 0:j.hookName),"?poll=1&since=").concat(e));o=await t.json()}else if("clipboard.write"===b&&lK(v,"clipboard"))try{await navigator.clipboard.writeText((null==j?void 0:j.text)||""),o={ok:!0}}catch(t){let e=document.createElement("textarea");e.value=(null==j?void 0:j.text)||"",e.style.position="fixed",e.style.opacity="0",document.body.appendChild(e),e.select(),document.execCommand("copy"),document.body.removeChild(e),o={ok:!0}}else if(!("clipboard.read"===b&&lK(v,"clipboard")))return void e(f,y,null,"Unknown method or insufficient permissions: ".concat(b));else try{o=await navigator.clipboard.readText()}catch(e){o=null}e(f,y,o)}catch(t){e(f,y,null,t instanceof Error?t.message:"Unknown error")}},i=null;function c(e,t,r,n){let o={objectName:r,...n};if(h.current.has(t)){var l;null==(l=e.contentWindow)||l.postMessage({type:"dench:event",channel:t,data:o},"*")}}return window.addEventListener("message",o),()=>{window.removeEventListener("message",o),i&&i.disconnect()}},[r,t,g,v,l,a]);let k=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:[k?(0,n.jsx)("img",{src:lV(t,r.icon),alt:"",width:20,height:20,className:"rounded flex-shrink-0",style:{objectFit:"cover"}}):(0,n.jsx)(lq,{}),(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:y,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:f,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:[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:[k?(0,n.jsx)("img",{src:lV(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)(lq,{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,"..."]})]}),d&&(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:d}),(0,n.jsx)("button",{type:"button",onClick:y,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:s,src:f,className:"w-full h-full border-0",sandbox:"allow-same-origin allow-scripts allow-popups allow-forms",title:r.name,onLoad:b,onError:j,style:{minHeight:"calc(100vh - 120px)"}})]})]})}function lq(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"})]})}lU.__denchAppMessageHandlers;var lG=r(47164);let l$={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 lY(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 lZ(e){var t;return null!=(t=l$[lY(e)])?t:"plaintext"}let lQ=!1;function lX(){return"undefined"!=typeof document&&document.documentElement.classList.contains("dark")}function l0(e){let{content:t,filename:r,filePath:o,className:l,onDirty:a}=e,s=lY(r);return"diff"===s||"patch"===s?(0,n.jsx)("div",{className:"max-w-4xl mx-auto px-6 py-8",children:(0,n.jsx)(lf,{diff:t})}):(0,n.jsx)(l1,{content:t,filename:r,filePath:o,className:l,onDirty:a})}function l1(e){let{content:t,filename:r,filePath:l,className:a,onDirty:s}=e,i=(0,o.useRef)(null),c=(0,o.useRef)(null),[d,u]=(0,o.useState)(lX()?"denchclaw-dark":"denchclaw-light"),[p,h]=(0,o.useState)("clean"),[m,x]=(0,o.useState)({line:1,col:1}),f=(0,o.useRef)(null),v=(0,o.useRef)(t),g=lZ(r),y=!!l;(0,o.useEffect)(()=>{v.current=t},[t]),(0,o.useEffect)(()=>{let e=document.documentElement,t=new MutationObserver(()=>u(lX()?"denchclaw-dark":"denchclaw-light"));return t.observe(e,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]);let b=(0,o.useCallback)(async()=>{if(!l||!i.current)return;let e=i.current.getValue();h("saving");try{if(!(await fetch((0,Z.nC)(l),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:l,content:e})})).ok)throw Error("Save failed");v.current=e,h("saved"),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>h("clean"),2e3)}catch(e){h("error"),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>h("dirty"),3e3)}},[l]),j=(0,o.useCallback)((e,t)=>{i.current=e,c.current=t,lQ||(lQ=!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(lX()?"denchclaw-dark":"denchclaw-light"),e.addCommand(t.KeyMod.CtrlCmd|t.KeyCode.KeyS,()=>{b()}),e.onDidChangeCursorPosition(e=>{x({line:e.position.lineNumber,col:e.position.column})}),e.onDidChangeModelContent(()=>{e.getValue()!==v.current?(h("dirty"),null==s||s()):h("clean")}),e.focus()},[b,s]);(0,o.useEffect)(()=>{c.current&&c.current.editor.setTheme(d)},[d]);let k=function(e){let t=lZ(e);return"plaintext"===t?lY(e)||"TEXT":t}(r),w=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"===p&&(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:k.toUpperCase()}),(0,n.jsxs)("span",{className:"text-[11px] tabular-nums",style:{color:"var(--color-text-muted)"},children:[w," lines"]}),(0,n.jsxs)("span",{className:"text-[11px] tabular-nums",style:{color:"var(--color-text-muted)"},children:["Ln ",m.line,", Col ",m.col]}),y&&(0,n.jsxs)(n.Fragment,{children:["saving"===p&&(0,n.jsx)("span",{className:"text-[11px]",style:{color:"var(--color-text-muted)"},children:"Saving..."}),"saved"===p&&(0,n.jsx)("span",{className:"text-[11px]",style:{color:"var(--color-success)"},children:"Saved"}),"error"===p&&(0,n.jsx)("span",{className:"text-[11px]",style:{color:"var(--color-error)"},children:"Save failed"}),(0,n.jsx)("button",{type:"button",onClick:()=>void b(),disabled:"dirty"!==p,className:"text-[11px] px-2 py-0.5 rounded transition-colors",style:{background:"dirty"===p?"var(--color-accent)":"var(--color-surface-hover)",color:"dirty"===p?"#fff":"var(--color-text-muted)",cursor:"dirty"===p?"pointer":"default",opacity:"dirty"===p?1:.5},children:"Save"})]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0",children:(0,n.jsx)(lG.Ay,{defaultValue:t,language:g,theme:d,onMount:j,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:!y,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"}}})})]})}function l2(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 l4(){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 l5(){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 l3(){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 l6(){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 l8(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 l7(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 l9(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 ae(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 at(){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)(l2,{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 ar(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,p]=(0,o.useState)(!0),[h,m]=(0,o.useState)(null),[x,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,T]=(0,o.useState)(null),[L,I]=(0,o.useState)(null),[_,R]=(0,o.useState)(!1),[E,D]=(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)p(!1);else{var r,n;a(null!=(n=l.tables)?n:[]),(null==(r=l.tables)?void 0:r.length)>0&&m(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 A=(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),A(h,100*j))},[h,j,A]);let F=(0,o.useCallback)(async()=>{if(C.trim()){R(!0),I(null),T(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;T(null!=(e=n.rows)?e:[])}else I(n.error||"HTTP ".concat(r.status))}catch(e){I(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]),B=(0,o.useMemo)(()=>{let e=w&&M?M:x;return y?[...e].toSorted((e,t)=>{let r=l9(e[y.column]),n=l9(t[y.column]),o=r.localeCompare(n,void 0,{numeric:!0});return"asc"===y.direction?o:-o}):e},[w,M,x,y]),W=e=>{b(t=>(null==t?void 0:t.column)===e?"asc"===t.direction?{column:e,direction:"desc"}:null:{column:e,direction:"asc"})},O=(0,o.useMemo)(()=>{let e=w&&M?M:x;return 0===e.length?[]:Object.keys(e[0])},[w,M,x]),z=(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:{borderRightColor:"var(--color-border)",borderBottomColor:"var(--color-border)",borderLeftColor:"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)(l2,{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 flex-col md:flex-row h-full",children:[(0,n.jsxs)("div",{className:"hidden md:flex w-56 flex-shrink-0 border-r 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)(l2,{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:[z," \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:()=>{m(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)(l5,{}):(0,n.jsx)(l4,{})}),(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)(l6,{}),"SQL Query"]})})]}),(0,n.jsxs)("div",{className:"flex md:hidden flex-shrink-0 items-center gap-1.5 px-2 py-1.5 border-b overflow-x-auto",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[l.map(e=>{let t=e.table_name.startsWith("v_"),r=h===e.table_name&&!w;return(0,n.jsxs)("button",{type:"button",onClick:()=>{m(e.table_name),k(0),N(!1)},className:"px-2.5 py-1 text-[11px] rounded-full whitespace-nowrap shrink-0 font-medium flex items-center gap-1",style:{background:r?"var(--color-accent)":"var(--color-surface-hover)",color:r?"white":"var(--color-text-muted)",border:r?"none":"1px solid var(--color-border)"},children:[(0,n.jsx)("span",{className:"flex-shrink-0",style:{color:r?"white":t?"#60a5fa":"var(--color-accent)"},children:t?(0,n.jsx)(l5,{}):(0,n.jsx)(l4,{})}),e.table_name]},e.table_name)}),(0,n.jsxs)("button",{type:"button",onClick:()=>N(!w),className:"px-2.5 py-1 text-[11px] rounded-full whitespace-nowrap shrink-0 font-medium flex items-center gap-1",style:{background:w?"var(--color-accent)":"var(--color-surface-hover)",color:w?"white":"var(--color-text-muted)",border:w?"none":"1px solid var(--color-border)"},children:[(0,n.jsx)(l6,{})," SQL"]})]}),(0,n.jsx)("div",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",children:w?(0,n.jsx)(ao,{sqlInput:C,setSqlInput:S,queryResult:M,queryError:L,queryRunning:_,runQuery:F,dataColumns:O,sortedData:B,sort:y,onSort:W}):P?(0,n.jsx)(an,{table:P,data:B,dataLoading:v,dataColumns:O,sort:y,onSort:W,page:j,pageSize:100,onPageChange:k,showSchema:E,onToggleSchema:()=>D(!E)}):(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)(at,{})}function an(e){let{table:t,data:r,dataLoading:o,dataColumns:l,sort:a,onSort:s,page:i,pageSize:c,onPageChange:d,showSchema:u,onToggleSchema:p}=e,h=t.estimated_row_count,m=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)(l4,{})}),(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:p,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=ae(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)(l3,{})}),(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:{borderRightColor:"var(--color-border)",borderBottomColor:"var(--color-border)",borderLeftColor:"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)(l4,{})}),(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"No data"})]}):(0,n.jsx)(al,{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 ",m]}),(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)(l8,{direction:"left"})}),(0,n.jsx)("button",{type:"button",disabled:i>=m-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)(l8,{direction:"right"})})]})]})]})}function ao(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:{borderRightColor:"rgba(255,255,255,0.3)",borderBottomColor:"rgba(255,255,255,0.3)",borderLeftColor:"rgba(255,255,255,0.3)",borderTopColor:"white"}}):(0,n.jsx)(l6,{}),"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)(al,{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)(l6,{})}),(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Write a SQL query and press Run"})]})]})]})}function al(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?ae(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)(l7,{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)(aa,{value:e[t]})},t))]},r))})]})}function aa(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=l9(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})}function as(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 ai=r(40077);function ac(){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 ad(){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 au(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 ap(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 ah(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 am(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 ax(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)(ac,{}),"Filters"]}),t.map(e=>{var t,o;let l=r[e.id];switch(e.type){case"dateRange":return(0,n.jsx)(au,{filter:e,value:l,onChange:t=>c(e.id,t)},e.id);case"select":return(0,n.jsx)(ap,{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)(ah,{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)(am,{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)(ad,{}),"Clear"]})]})}function af(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 av(){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 ag(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,p]=(0,o.useState)({}),[h,m]=(0,o.useState)({}),[x,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};p(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(()=>({}));p(n=>({...n,[e.id]:{panelId:e.id,rows:[],loading:!1,error:t.error||"HTTP ".concat(r.status)}}));return}let n=await r.json();p(t=>{var r;return{...t,[e.id]:{panelId:e.id,rows:null!=(r=n.rows)?r:[],loading:!1}}})}catch(t){p(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,x]);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)(af,{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)(af,{})}),(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)(av,{})})]})]})}),l.filters&&l.filters.length>0&&(0,n.jsx)(ax,{filters:l.filters,value:h,onChange:m}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-3 sm:p-6",children:(0,n.jsx)("div",{className:"grid grid-cols-2 sm:grid-cols-4 lg:grid-cols-6 gap-3 sm:gap-5",children:l.panels.map(e=>(0,n.jsx)(ay,{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 ay(e){var t;let{panel:r,data:o}=e,l=function(e){switch(e){case"full":return"col-span-2 sm:col-span-4 lg:col-span-6";case"third":return"col-span-1 sm:col-span-2 lg:col-span-2";default:return"col-span-2 sm:col-span-2 lg: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)(ai.N,{config:r,data:null!=(t=null==o?void 0:o.rows)?t:[]})})]})}let ab="denchclaw.crm-inbox.list-width";function aj(e){let{list:t,conversation:r,hasSelection:l}=e,[a,s]=(0,o.useState)(420),[i,c]=(0,o.useState)(!1),d=(0,o.useRef)(null),u=(0,o.useRef)(null);(0,o.useEffect)(()=>{try{let e=window.localStorage.getItem(ab);if(e){let t=parseInt(e,10);Number.isFinite(t)&&s(ak(t,320,640))}}catch(e){}},[]),(0,o.useEffect)(()=>{if("undefined"==typeof ResizeObserver||!u.current)return;let e=new ResizeObserver(e=>{let[t]=e;c(t.contentRect.width<900)});return e.observe(u.current),()=>e.disconnect()},[]);let p=(0,o.useCallback)(e=>{e.preventDefault(),d.current={startX:e.clientX,startWidth:a}},[a]);return((0,o.useEffect)(()=>{let e=e=>{if(!d.current)return;let t=e.clientX-d.current.startX;s(ak(d.current.startWidth+t,320,640))},t=()=>{if(d.current)try{window.localStorage.setItem(ab,String(a))}catch(e){}d.current=null};return window.addEventListener("mousemove",e),window.addEventListener("mouseup",t),()=>{window.removeEventListener("mousemove",e),window.removeEventListener("mouseup",t)}},[a]),i)?(0,n.jsx)("div",{ref:u,className:"h-full min-h-0 w-full",children:l?r:t}):(0,n.jsxs)("div",{ref:u,className:"flex h-full min-h-0 w-full",children:[(0,n.jsx)("div",{className:"flex h-full min-h-0 flex-col",style:{width:a,minWidth:320,background:"var(--color-bg)",borderRight:"1px solid var(--color-border)"},children:t}),(0,n.jsx)("div",{role:"separator","aria-orientation":"vertical",onMouseDown:p,className:"shrink-0 cursor-col-resize transition-colors",style:{width:4,background:"transparent",marginLeft:-2,marginRight:-2,zIndex:1},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-accent-light)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"}}),(0,n.jsx)("div",{className:"flex-1 min-w-0 h-full min-h-0",children:r})]})}function ak(e,t,r){return Math.max(t,Math.min(r,e))}let aw=o.forwardRef((e,t)=>{let{className:r,type:o,...l}=e;return(0,n.jsx)("input",{type:o,className:(0,h.cn)("flex h-9 w-full rounded-md border border-input bg-background px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",r),ref:t,...l})});aw.displayName="Input";let aN=(0,o.forwardRef)(function(e,t){let{search:r,onSearchChange:o,selectedCount:l,onClearSelection:a,onBulkAction:s,onOpenShortcuts:i}=e;return(0,n.jsxs)("div",{className:"shrink-0 flex flex-col",style:{borderBottom:"1px solid var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2",children:[(0,n.jsx)(aw,{ref:t,placeholder:"Search subject + sender…",value:r,onChange:e=>o(e.target.value),className:"h-8 flex-1 text-[13px]"}),(0,n.jsx)("button",{type:"button",onClick:i,title:"Keyboard shortcuts (?)",className:"inline-flex h-8 w-8 items-center justify-center rounded-full transition-colors hover:bg-[var(--color-surface-hover)]",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(aS,{})})]}),l>0&&(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2",style:{background:"var(--color-accent-light)",borderTop:"1px solid var(--color-border)"},children:[(0,n.jsxs)("span",{className:"text-[12px] font-medium",style:{color:"var(--color-text)"},children:[l.toLocaleString()," selected"]}),(0,n.jsx)("button",{type:"button",onClick:a,className:"text-[11px] hover:underline",style:{color:"var(--color-text-muted)"},children:"Clear"}),(0,n.jsx)("span",{className:"flex-1"}),(0,n.jsx)(aC,{onClick:()=>s("read"),children:"Mark read"}),(0,n.jsx)(aC,{onClick:()=>s("star"),children:"Star"}),(0,n.jsx)(aC,{onClick:()=>s("archive"),children:"Archive"})]})]})});function aC(e){let{onClick:t,children:r}=e;return(0,n.jsx)("button",{type:"button",onClick:t,className:"inline-flex items-center gap-1 rounded-md px-2 py-1 text-[12px] font-medium transition-colors hover:bg-[var(--color-surface)]",style:{color:"var(--color-text)"},children:r})}function aS(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[(0,n.jsx)("rect",{x:"2",y:"6",width:"20",height:"12",rx:"2"}),(0,n.jsx)("line",{x1:"6",y1:"10",x2:"6.01",y2:"10"}),(0,n.jsx)("line",{x1:"10",y1:"10",x2:"10.01",y2:"10"}),(0,n.jsx)("line",{x1:"14",y1:"10",x2:"14.01",y2:"10"}),(0,n.jsx)("line",{x1:"18",y1:"10",x2:"18.01",y2:"10"}),(0,n.jsx)("line",{x1:"6",y1:"14",x2:"18",y2:"14"})]})}function aM(e){let{title:t,count:r,toolbar:o,children:l}=e;return(0,n.jsxs)("div",{className:"flex h-full min-h-0 flex-col",style:{background:"var(--color-background)"},children:[(0,n.jsxs)("header",{className:"flex shrink-0 items-center justify-between gap-4 px-6 py-3",style:{borderBottom:"1px solid var(--color-border)"},children:[(0,n.jsxs)("div",{className:"min-w-0 flex items-baseline gap-3",children:[(0,n.jsx)("h1",{className:"font-instrument text-xl tracking-tight truncate",style:{color:"var(--color-text)"},children:t}),"number"==typeof r&&(0,n.jsx)("span",{className:"text-[12px]",style:{color:"var(--color-text-muted)"},children:r.toLocaleString()})]}),o&&(0,n.jsx)("div",{className:"flex items-center gap-2 shrink-0",children:o})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:l})]})}function aT(e){let{title:t,description:r,cta:o}=e;return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-4 px-8 py-16 text-center",children:[(0,n.jsx)("h2",{className:"font-instrument text-2xl tracking-tight",style:{color:"var(--color-text)"},children:t}),r&&(0,n.jsx)("p",{className:"text-sm max-w-md leading-relaxed",style:{color:"var(--color-text-muted)"},children:r}),o]})}function aL(e){let{label:t="Loading…"}=e;return(0,n.jsx)("div",{className:"flex items-center justify-center py-16",children:(0,n.jsx)("span",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:t})})}let aI=["#fda4af","#fbcfe8","#d8b4fe","#a5b4fc","#93c5fd","#7dd3fc","#67e8f9","#5eead4","#86efac","#bef264","#fde68a","#fdba74","#fca5a5"];function a_(e){let{src:t,name:r,seed:l,size:a="md",className:s="",onError:i}=e,[c,d]=(0,o.useState)(!1),u=function(e,t){var r;let n=function(e){if(!e||"string"!=typeof e)return"?";let t=e.trim();if(!t)return"?";let r=t;if(t.includes("@")){let e=t.slice(0,t.indexOf("@"));e&&(r=e)}if(!(r=r.replace(/[._+-]/g," ").trim()))return"?";let n=r.split(/\s+/).filter(Boolean);if(0===n.length)return"?";if(1===n.length)return(n[0].charAt(0)||"?").toUpperCase();let o=n[0].charAt(0),l=n[n.length-1].charAt(0);return"".concat(o).concat(l).toUpperCase()}(e);return{initials:n,background:function(e){let t=(null!=e?e:"").trim();if(!t)return aI[0];let r=0x811c9dc5;for(let e=0;e<t.length;e+=1)r^=t.charCodeAt(e),r=Math.imul(r,0x1000193);let n=Math.abs(r)%aI.length;return aI[n]}(null!=(r=null!=t?t:e)?r:""),foreground:"#0c0a09"}}(null!=r?r:null,null!=l?l:void 0),p=aR[a],h=Math.max(10,Math.round(.4*p)),m=!!t&&!c;return(0,n.jsx)("span",{className:"inline-flex items-center justify-center rounded-full overflow-hidden shrink-0 ".concat(s),style:{width:p,height:p,background:m?"transparent":u.background,color:u.foreground,fontSize:h,fontWeight:600,lineHeight:1},"aria-label":null!=r?r:"Avatar",children:m?(0,n.jsx)("img",{src:null!=t?t:void 0,alt:null!=r?r:"",width:p,height:p,decoding:"async",loading:"lazy",onError:()=>{d(!0),null==i||i()},style:{width:"100%",height:"100%",objectFit:"cover"}}):u.initials})}let aR={sm:24,md:36,lg:48,xl:64};function aE(e){var t,r;let{domain:l,name:a,size:s="md",className:i=""}=e,[c,d]=(0,o.useState)(!1),u=aD[s],p=Math.max(10,Math.round(.42*u)),h=null==l?void 0:l.trim().toLowerCase().replace(/^https?:\/\//,"").replace(/\/.*$/,""),m=h?"https://www.google.com/s2/favicons?sz=128&domain_url=".concat(encodeURIComponent(h)):null,x=(null!=(t=null!=a?a:h)?t:"?").charAt(0).toUpperCase(),f=!!m&&!c;return(0,n.jsx)("span",{className:"inline-flex items-center justify-center rounded-xl overflow-hidden shrink-0 ".concat(i),style:{width:u,height:u,background:f?"transparent":"var(--color-surface-hover)",border:"1px solid var(--color-border)",color:"var(--color-text)",fontSize:p,fontWeight:600,lineHeight:1},"aria-label":null!=(r=null!=a?a:h)?r:"Company",children:f?(0,n.jsx)("img",{src:null!=m?m:void 0,alt:"",width:u,height:u,decoding:"async",loading:"lazy",onError:()=>d(!0),style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}}):x})}let aD={sm:24,md:36,lg:48,xl:64},aA=new Set(["gmail.com","googlemail.com","yahoo.com","yahoo.co.uk","yahoo.co.jp","hotmail.com","hotmail.co.uk","outlook.com","live.com","msn.com","icloud.com","me.com","mac.com","aol.com","proton.me","protonmail.com","pm.me","fastmail.com","gmx.com","gmx.de","zoho.com","mail.com","mail.ru","yandex.com","qq.com","163.com","126.com"]),aF=new Set(["lh3.googleusercontent.com","lh4.googleusercontent.com","lh5.googleusercontent.com","lh6.googleusercontent.com","lh3.google.com","www.gravatar.com","secure.gravatar.com"]),aP=new Set(["noreply","no-reply","do-not-reply","donotreply","notifications","notification","notify","alerts","alert","billing","invoices","invoice","receipts","receipt","support","help","contact","info","hello","team","hi","news","newsletter","updates","mail","mailer","mailing","automated","auto","system","admin","security","account","accounts","orders","order","shipping"]);function aB(e){let{name:t,email:r,avatarUrl:l,seed:a,size:s="sm",className:i}=e,[c,d]=(0,o.useState)(!1),[u,p]=(0,o.useState)(!1),h="string"==typeof l&&l.trim()?l.trim():null;if(h&&!c)return(0,n.jsx)(a_,{src:function(e){try{let t=new URL(e);if(aF.has(t.hostname))return"/api/crm/photos/proxy?url=".concat(encodeURIComponent(e))}catch(e){}return e}(h),name:t,seed:null!=a?a:r,size:s,className:i,onError:()=>d(!0)});if(r&&!u){let e="https://unavatar.io/".concat(encodeURIComponent(r),"?fallback=false");return(0,n.jsx)(a_,{src:e,name:t,seed:null!=a?a:r,size:s,className:i,onError:()=>p(!0)})}let m=function(e){if(!e)return null;let t=e.lastIndexOf("@");return t<0||t===e.length-1?null:e.slice(t+1).trim().toLowerCase()||null}(r);return m&&!aA.has(m)&&function(e,t){let r=function(e){if(!e)return null;let t=e.lastIndexOf("@");return t<=0?null:e.slice(0,t).trim().toLowerCase()||null}(e);if(r&&aP.has(r))return!0;if(r){let e=r.split(/[+.\-_]/)[0];if(e&&aP.has(e))return!0}if(t){let e=t.trim();if(/^(the\s+)?(\w+\s+)?(team|notifications?|security|alerts?|billing|support|updates?)$/i.test(e))return!0}return!1}(r,t)?(0,n.jsx)(aE,{domain:m,name:t,size:s,className:i}):(0,n.jsx)(a_,{name:t,seed:null!=a?a:r,size:s,className:i})}function aW(e){if(!e)return"";let t="string"==typeof e?Date.parse(e):e instanceof Date?e.getTime():e;if(!Number.isFinite(t))return"";let r=Date.now()-t,n=r<0,o=Math.abs(r),l=(e,t)=>n?"in ".concat(e).concat(t):"".concat(e).concat(t," ago");return o<6e4?n?"soon":"just now":o<36e5?l(Math.round(o/6e4),"m"):o<864e5?l(Math.round(o/36e5),"h"):o<6048e5?l(Math.round(o/864e5),"d"):o<2592e6?l(Math.round(o/6048e5),"w"):o<31536e6?l(Math.round(o/2592e6),"mo"):l(Math.round(o/31536e6),"y")}function aO(e){if(!e)return"";let t="string"==typeof e?new Date(e):e instanceof Date?e:new Date(e);return Number.isNaN(t.getTime())?"":new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}).format(t)}function az(e){if(!e)return"";let t="string"==typeof e?new Date(e):e instanceof Date?e:new Date(e);if(Number.isNaN(t.getTime()))return"";let r=new Date,n=new Date(r);n.setDate(r.getDate()-1);let o=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate();return o(t,r)?"Today":o(t,n)?"Yesterday":new Intl.DateTimeFormat(void 0,{weekday:"short",month:"short",day:"numeric",year:t.getFullYear()!==r.getFullYear()?"numeric":void 0}).format(t)}let aU={Marketing:"#ef4444",Transactional:"#3b82f6",Notification:"#f59e0b","Mailing List":"#8b5cf6",Automated:"#94a3b8"};function aH(e){var t,r,o,l,a,s,i,c;let{thread:d,selected:u,read:p,starred:h,inBulkSelection:m,onSelect:x,onToggleSelected:f,onToggleStarred:v}=e,g=function(e){if(e.primary_sender_name||e.primary_sender_email){var t,r,n;let o=e.participants.find(t=>t.id===e.primary_sender_id);return{name:null!=(r=null!=(t=e.primary_sender_name)?t:e.primary_sender_email)?r:null,email:e.primary_sender_email,avatar_url:null!=(n=null==o?void 0:o.avatar_url)?n:null}}let o=e.participants[0];return o?{name:o.name,email:o.email,avatar_url:o.avatar_url}:{name:"Unknown sender",email:null,avatar_url:null}}(d),y=d.primary_sender_type&&"Person"!==d.primary_sender_type?null!=(o=aU[d.primary_sender_type])?o:"#94a3b8":null,b=e=>e.stopPropagation();return(0,n.jsxs)("button",{type:"button",onClick:x,"data-thread-id":d.id,"data-thread-row":"true",className:"group relative w-full grid items-center gap-2 px-4 py-2.5 text-left transition-colors",style:{gridTemplateColumns:"20px 16px auto minmax(0, 1fr) auto",background:u?"var(--color-accent-light)":m?"color-mix(in oklab, var(--color-accent) 5%, transparent)":"transparent",borderLeft:u?"2px solid var(--color-accent)":"2px solid transparent",borderBottom:"1px solid var(--color-border)"},onMouseEnter:e=>{u||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{u||(e.currentTarget.style.background=m?"color-mix(in oklab, var(--color-accent) 5%, transparent)":"transparent")},children:[(0,n.jsx)("span",{role:"checkbox","aria-checked":m,tabIndex:-1,onClick:e=>{b(e),f()},onKeyDown:e=>{(" "===e.key||"Enter"===e.key)&&(e.preventDefault(),f())},className:"inline-flex h-4 w-4 shrink-0 items-center justify-center rounded border cursor-pointer",style:{background:m?"var(--color-accent)":"transparent",borderColor:m?"var(--color-accent)":"var(--color-border-strong)"},children:m&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"#fff",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})})}),(0,n.jsx)("span",{role:"button",tabIndex:-1,onClick:e=>{b(e),v()},title:h?"Unstar":"Star",className:"inline-flex h-4 w-4 shrink-0 items-center justify-center cursor-pointer",children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:h?"#f59e0b":"none",stroke:h?"#f59e0b":"var(--color-text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:(0,n.jsx)("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})})}),(0,n.jsxs)("span",{className:"inline-flex items-center gap-2 min-w-0 max-w-[180px]",children:[(0,n.jsx)(aB,{avatarUrl:g.avatar_url,name:g.name,email:g.email,seed:null!=(l=g.email)?l:d.id,senderType:d.primary_sender_type,size:"sm"}),(0,n.jsxs)("span",{className:"truncate text-[13px]",style:{color:"var(--color-text)",fontWeight:p?400:600},title:null!=(s=null!=(a=g.email)?a:g.name)?s:void 0,children:[null!=(c=null!=(i=g.name)?i:g.email)?c:"Unknown",d.participants.length>1&&(0,n.jsxs)("span",{className:"ml-1 text-[11px] tabular-nums",style:{color:"var(--color-text-muted)",fontWeight:400},children:["(",d.participants.length,")"]})]})]}),(0,n.jsxs)("span",{className:"min-w-0 flex items-baseline gap-2",children:[!p&&(0,n.jsx)("span",{"aria-hidden":!0,className:"shrink-0",style:{width:6,height:6,borderRadius:99,background:"var(--color-accent)"}}),(0,n.jsx)("span",{className:"truncate",style:{color:"var(--color-text)",fontSize:13,fontWeight:p?400:600},children:(null==(t=d.subject)?void 0:t.trim())||"(no subject)"}),y&&(0,n.jsxs)("span",{className:"shrink-0 inline-flex items-center gap-1 rounded-full px-1.5 py-0 text-[10px] uppercase tracking-[0.06em]",style:{background:"".concat(y,"1f"),color:y,fontWeight:600},children:[(0,n.jsx)("span",{"aria-hidden":!0,style:{width:5,height:5,borderRadius:99,background:y}}),d.primary_sender_type]}),(null==(r=d.snippet)?void 0:r.trim())&&(0,n.jsxs)("span",{className:"truncate text-[13px]",style:{color:"var(--color-text-muted)",fontFamily:'"Bookerly", Georgia, "Times New Roman", serif'},children:["— ",d.snippet.trim()]})]}),(0,n.jsx)("span",{className:"text-right text-[11px] tabular-nums shrink-0",style:{color:"var(--color-text-muted)"},title:d.last_message_at?aO(d.last_message_at):void 0,children:d.last_message_at&&aW(d.last_message_at)})]})}function aV(e){let{threads:t,loading:r,selectedThreadId:l,selectedIds:a,isRead:s,isStarred:i,onSelect:c,onToggleSelected:d,onToggleStarred:u}=e,p=(0,o.useMemo)(()=>(function(e){let t=[],r=null;for(let n of e){let e=function(e){if(!e)return"Earlier";let t=Date.parse(e);if(!Number.isFinite(t))return"Earlier";let r=new Date(t),n=new Date,o=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime(),l=Math.floor((o(n)-o(r))/864e5);return l<=0?"Today":1===l?"Yesterday":l<7?new Intl.DateTimeFormat(void 0,{weekday:"long"}).format(r):l<30?"Earlier this month":r.getFullYear()===n.getFullYear()?new Intl.DateTimeFormat(void 0,{month:"long"}).format(r):new Intl.DateTimeFormat(void 0,{month:"short",year:"numeric"}).format(r)}(n.last_message_at);e!==r&&(t.push({label:e,threads:[]}),r=e),t[t.length-1].threads.push(n)}return t})(t),[t]);return r&&0===t.length?(0,n.jsx)(aL,{}):0===t.length?(0,n.jsx)(aT,{title:"Empty",description:"Threads land here as Gmail syncs."}):(0,n.jsx)("div",{className:"flex flex-col",children:p.map(e=>(0,n.jsxs)("section",{children:[(0,n.jsx)("h3",{className:"sticky top-0 z-10 px-4 py-1.5 font-semibold uppercase",style:{color:"var(--color-text-muted)",background:"var(--color-bg)",borderBottom:"1px solid var(--color-border)",letterSpacing:"0.16em",fontSize:"10px"},children:e.label}),(0,n.jsx)("ul",{children:e.threads.map(e=>(0,n.jsx)("li",{children:(0,n.jsx)(aH,{thread:e,selected:l===e.id,read:s(e.id),starred:i(e.id),inBulkSelection:a.has(e.id),onSelect:()=>c(e),onToggleSelected:()=>d(e.id),onToggleStarred:()=>u(e.id)})},e.id))})]},e.label))})}function aK(e){let{participants:t,max:r=4,onOpenPerson:o,variant:l="avatars"}=e;if(0===t.length)return null;let a=t.slice(0,r),s=t.length-a.length;return"avatars"===l?(0,n.jsxs)("div",{className:"flex items-center -space-x-1.5",children:[a.map(e=>{var t,r,l,a;return(0,n.jsx)("button",{type:"button",onClick:()=>null==o?void 0:o(e.id),disabled:!o,title:null!=(r=null!=(t=e.name)?t:e.email)?r:void 0,className:"rounded-full ring-2 ring-[var(--color-bg)] disabled:cursor-default",children:(0,n.jsx)(a_,{src:e.avatar_url,name:null!=(l=e.name)?l:e.email,seed:null!=(a=e.email)?a:e.id,size:"sm"})},e.id)}),s>0&&(0,n.jsxs)("span",{className:"ml-2 text-[11px] tabular-nums",style:{color:"var(--color-text-muted)"},children:["+",s]})]}):(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5",children:[a.map(e=>{var t,r,l,a;return(0,n.jsxs)("button",{type:"button",onClick:()=>null==o?void 0:o(e.id),disabled:!o,className:"inline-flex items-center gap-1.5 rounded-full pl-0.5 pr-2.5 py-0.5 text-[12px] transition-colors disabled:cursor-default",style:{background:"var(--color-surface-hover)",color:"var(--color-text)"},title:null!=(r=e.email)?r:void 0,children:[(0,n.jsx)(a_,{src:e.avatar_url,name:null!=(l=e.name)?l:e.email,seed:null!=(a=e.email)?a:e.id,size:"sm"}),(0,n.jsx)("span",{className:"truncate max-w-[140px]",children:(null==(t=e.name)?void 0:t.trim())||e.email||"Unknown"})]},e.id)}),s>0&&(0,n.jsxs)("span",{className:"text-[11px] tabular-nums",style:{color:"var(--color-text-muted)"},children:["+",s," more"]})]})}function aJ(e){let{subject:t,participants:r,gmailThreadId:o,threadId:l,starred:a,onToggleStar:s,onOpenPerson:i,onClose:c}=e,d=(null==t?void 0:t.trim())||"(no subject)";return(0,n.jsx)("header",{className:"sticky top-0 z-20 px-6 pt-5 pb-3",style:{background:"var(--color-main-bg)",borderBottom:"1px solid var(--color-border)"},children:(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[c&&(0,n.jsx)("button",{type:"button",onClick:c,title:"Back to inbox",className:"shrink-0 inline-flex h-8 w-8 items-center justify-center rounded-full transition-colors hover:bg-[var(--color-surface-hover)]",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(aG,{})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("h1",{className:"tracking-tight",style:{color:"var(--color-text)",fontSize:"clamp(1.25rem, 2vw, 1.5rem)",lineHeight:1.25,fontWeight:600,wordBreak:"break-word"},title:d,children:d}),r.length>0&&(0,n.jsx)("div",{className:"mt-2.5 flex items-center gap-3",children:(0,n.jsx)(aK,{participants:r,max:5,onOpenPerson:i,variant:"named"})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,n.jsx)(aq,{title:a?"Unstar":"Star",onClick:s,active:a,children:(0,n.jsx)(a$,{filled:a})}),o&&(0,n.jsx)(aq,{as:"a",href:"https://mail.google.com/mail/u/0/#all/".concat(o),target:"_blank",rel:"noreferrer",title:"Open in Gmail",children:(0,n.jsx)(aY,{})}),(0,n.jsx)(aq,{title:"Copy thread ID",onClick:()=>{"undefined"!=typeof navigator&&navigator.clipboard&&navigator.clipboard.writeText(l)},children:(0,n.jsx)(aZ,{})})]})]})})}function aq(e){let{title:t,active:r,children:o}=e,l="inline-flex h-8 w-8 items-center justify-center rounded-full transition-colors",a={background:r?"var(--color-surface-hover)":"transparent",color:r?"var(--color-text)":"var(--color-text-muted)"};return"a"===e.as?(0,n.jsx)("a",{href:e.href,target:e.target,rel:e.rel,title:t,className:"".concat(l," hover:bg-[var(--color-surface-hover)] hover:text-[var(--color-text)]"),style:a,children:o}):(0,n.jsx)("button",{type:"button",onClick:e.onClick,title:t,className:"".concat(l," hover:bg-[var(--color-surface-hover)] hover:text-[var(--color-text)]"),style:a,children:o})}function aG(){return(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:(0,n.jsx)("path",{d:"m15 18-6-6 6-6"})})}function a$(e){let{filled:t}=e;return(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:t?"#f59e0b":"none",stroke:t?"#f59e0b":"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:(0,n.jsx)("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})})}function aY(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[(0,n.jsx)("path",{d:"M15 3h6v6"}),(0,n.jsx)("path",{d:"M10 14 21 3"}),(0,n.jsx)("path",{d:"M21 14v5a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5"})]})}function aZ(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}function aQ(e){let{body:t,preview:r}=e,l=(null==t?void 0:t.trim())||(null==r?void 0:r.trim())||"",a=(0,o.useMemo)(()=>{var e;return!!(e=l)&&/<!doctype|<html|<body|<head|<table|<div|<p\b|<a\s|<br\s*\/?>|<img\s|<\/[a-z]/i.test(e)},[l]);return l?a?(0,n.jsx)(aX,{html:l}):(0,n.jsx)("div",{className:"text-[14px] leading-[1.65] whitespace-pre-wrap break-words",style:{color:"var(--color-text)",fontFamily:'"Bookerly", Georgia, "Times New Roman", serif'},children:l}):(0,n.jsx)("p",{className:"text-[13px] italic",style:{color:"var(--color-text-muted)",fontFamily:'"Bookerly", Georgia, "Times New Roman", serif'},children:"(empty body)"})}function aX(e){let{html:t}=e,r=(0,o.useRef)(null),[l,a]=(0,o.useState)(160),s=(0,o.useId)(),i=(0,o.useMemo)(()=>s.replace(/[^a-zA-Z0-9_-]/g,"")||"iframe",[s]),c=(0,o.useMemo)(()=>(function(e,t){let r=function(e){let t=e,r="";for(;t!==r;)r=t,t=t.replace(/<script\b[^>]*>[\s\S]*?<\/script\b[^>]*>/gi,"").replace(/<script\b[^>]*\/>/gi,"").replace(/<\/?script\b[^>]*>/gi,"");for(r="";t!==r;)r=t,t=t.replace(/\s+on[a-z]+\s*=\s*"[^"]*"/gi,"").replace(/\s+on[a-z]+\s*=\s*'[^']*'/gi,"").replace(/\s+on[a-z]+\s*=\s*[^\s>]+/gi,"");for(r="";t!==r;)r=t,t=t.replace(/javascript\s*:/gi,"");return t}(e.trim()),n=/^\s*(?:<!doctype|<html\b)/i.test(r),o="<script>(function(){\nvar TOKEN = ".concat(JSON.stringify(t),";\nfunction measure(){\n try {\n var b = document.body;\n if (!b) return;\n // CRITICAL: only measure the BODY (content), never the documentElement\n // or window. documentElement.clientHeight / scrollHeight reflect the\n // iframe's CURRENT viewport height, not the document's natural height\n // — using them here creates a feedback loop where every measurement\n // reports the iframe's own grown size and the iframe keeps growing.\n var height = Math.max(b.scrollHeight, b.offsetHeight);\n parent.postMessage({ type: 'denchclaw_email_height', token: TOKEN, height: height }, '*');\n } catch (e) {}\n}\nfunction attach(){\n measure();\n try {\n // Observe ONLY the body — observing documentElement would also fire\n // on the viewport resize that we ourselves cause when growing the\n // iframe, contributing to feedback-loop runs.\n if (typeof ResizeObserver !== 'undefined' && document.body) {\n var ro = new ResizeObserver(measure);\n ro.observe(document.body);\n }\n } catch (e) {}\n var imgs = document.images || [];\n for (var i = 0; i < imgs.length; i++) {\n if (!imgs[i].complete) {\n imgs[i].addEventListener('load', measure);\n imgs[i].addEventListener('error', measure);\n }\n }\n var delays = [50, 200, 500, 1000, 2000, 4000, 8000];\n for (var j = 0; j < delays.length; j++) setTimeout(measure, delays[j]);\n}\nif (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', attach);\n} else {\n attach();\n}\nwindow.addEventListener('load', measure);\n})();<\/script>");if(n){let e='<base target="_blank"><style>\n img, video { max-width: 100% !important; height: auto !important; }\n table { max-width: 100%; }\n img[width="1"][height="1"] { display: none !important; }\n</style>'.concat(o),t=r.match(/<head\b[^>]*>/i);if((null==t?void 0:t.index)!==void 0){let n=t.index+t[0].length;return r.slice(0,n)+e+r.slice(n)}let n=r.match(/<html\b[^>]*>/i);if((null==n?void 0:n.index)!==void 0){let t=n.index+n[0].length;return"".concat(r.slice(0,t),"<head>").concat(e,"</head>").concat(r.slice(t))}}return'<!doctype html>\n<html lang="en">\n<head>\n<meta charset="utf-8">\n<meta name="viewport" content="width=device-width, initial-scale=1">\n<base target="_blank">\n<style>'.concat('\n :root { color-scheme: light; }\n html, body {\n margin: 0;\n padding: 16px 18px;\n background: #ffffff;\n color: #1c1c1a;\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;\n font-size: 14px;\n line-height: 1.55;\n word-wrap: break-word;\n overflow-wrap: anywhere;\n }\n body * { max-width: 100% !important; }\n img, video { max-width: 100% !important; height: auto !important; }\n table { border-collapse: collapse; max-width: 100% !important; }\n a { color: #0065A2; text-decoration: underline; }\n blockquote { margin: 0 0 0 8px; padding-left: 12px; border-left: 2px solid rgba(0,0,0,0.12); color: #555; }\n pre, code { font-family: "SF Mono", "Fira Code", monospace; font-size: 13px; }\n pre { white-space: pre-wrap; }\n /* Hide tracking pixels — common 1x1 invisible images. */\n img[width="1"][height="1"] { display: none !important; }\n '.trim(),"</style>\n").concat(o,"\n</head>\n<body>").concat(r,"</body>\n</html>")})(t,i),[t,i]);return(0,o.useEffect)(()=>{let e=r.current;if(!e)return;let t=t=>{if(t.source!==e.contentWindow)return;let r=t.data;if(!r||"object"!=typeof r||"denchclaw_email_height"!==r.type||r.token!==i)return;let n=Number(r.height);if(!Number.isFinite(n))return;let o=Math.max(60,Math.round(n));a(e=>Math.abs(e-o)>2?o:e)};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[i]),(0,n.jsx)("iframe",{ref:r,title:"Email body",srcDoc:c,sandbox:"allow-popups allow-popups-to-escape-sandbox allow-scripts",referrerPolicy:"no-referrer",style:{width:"100%",height:l,border:"none",background:"var(--color-surface)",colorScheme:"light",display:"block"}})}function a0(e){let{count:t}=e;return(0,n.jsxs)("div",{className:"mt-3 inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 text-[12px]",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",color:"var(--color-text-muted)"},title:"Attachment preview is coming when we wire the Gmail attachment fetch.",children:[(0,n.jsx)(a1,{}),(0,n.jsxs)("span",{children:[t&&t>1?"".concat(t," attachments"):"1 attachment"," \xb7 preview coming soon"]})]})}function a1(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,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 17.93 8.8l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.5-8.49"})})}function a2(e){var t,r,l,a,s;let{message:i,people:c,defaultExpanded:d,onOpenPerson:u}=e,[p,h]=(0,o.useState)(d),m=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(d){var e;null==(e=m.current)||e.scrollIntoView({block:"nearest",behavior:"auto"})}},[d]);let x=i.from_person_id?c.get(i.from_person_id):null,f=null!=(l=null!=(r=null==x?void 0:x.name)?r:null==x?void 0:x.email)?l:"Unknown sender",v=null!=(a=null==x?void 0:x.email)?a:null,g=i.to_person_ids.map(e=>c.get(e)).filter(e=>!!e),y=i.cc_person_ids.map(e=>c.get(e)).filter(e=>!!e);return(0,n.jsxs)("article",{ref:m,className:"rounded-2xl border overflow-hidden",style:{background:"var(--color-surface)",borderColor:p?"var(--color-border-strong)":"var(--color-border)",boxShadow:p?"var(--shadow-md)":"none",transition:"border-color 160ms ease-out, box-shadow 160ms ease-out"},children:[(0,n.jsxs)("div",{role:"button",tabIndex:0,"aria-expanded":p,onClick:()=>h(e=>!e),onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),h(e=>!e))},className:"w-full flex items-start gap-3 px-4 py-3 text-left cursor-pointer transition-colors hover:bg-[var(--color-surface-hover)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]",children:[(0,n.jsx)(aB,{avatarUrl:null==x?void 0:x.avatar_url,name:f,email:v,seed:null!=v?v:i.id,senderType:null!=(s=i.sender_type)?s:null,size:"md"}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex items-baseline gap-2 flex-wrap",children:[(0,n.jsx)("span",{className:"text-[14px] font-semibold truncate",style:{color:"var(--color-text)"},children:f}),v&&v!==f&&(0,n.jsxs)("span",{className:"text-[12px] truncate",style:{color:"var(--color-text-muted)"},children:["<",v,">"]}),i.sender_type&&"Person"!==i.sender_type&&(0,n.jsx)(a5,{kind:i.sender_type}),(0,n.jsx)("span",{className:"flex-1"}),(0,n.jsx)("span",{className:"text-[12px] tabular-nums shrink-0",style:{color:"var(--color-text-muted)"},title:i.sent_at?aO(i.sent_at):void 0,children:i.sent_at&&aW(i.sent_at)})]}),!p&&(0,n.jsx)("p",{className:"mt-0.5 truncate text-[13px]",style:{color:"var(--color-text-muted)",fontFamily:'"Bookerly", Georgia, "Times New Roman", serif'},children:(null==(t=i.preview)?void 0:t.trim())||"(empty body)"}),p&&(g.length>0||y.length>0)&&(0,n.jsxs)("p",{className:"mt-1 text-[12px] truncate",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)("span",{style:{color:"var(--color-text-muted)"},children:"To:"})," ",g.map((e,t)=>{var r;return(0,n.jsxs)("span",{children:[t>0&&", ",(0,n.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),null==u||u(e.id)},className:"hover:underline",style:{color:"var(--color-text)"},children:(null==(r=e.name)?void 0:r.trim())||e.email})]},e.id)}),y.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"mx-2",children:"\xb7"}),(0,n.jsx)("span",{style:{color:"var(--color-text-muted)"},children:"Cc:"})," ",y.map((e,t)=>{var r;return(0,n.jsxs)("span",{children:[t>0&&", ",(0,n.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),null==u||u(e.id)},className:"hover:underline",style:{color:"var(--color-text)"},children:(null==(r=e.name)?void 0:r.trim())||e.email})]},e.id)})]})]})]})]}),(0,n.jsx)("div",{className:"grid transition-[grid-template-rows] duration-[220ms] ease-out motion-reduce:transition-none",style:{gridTemplateRows:p?"1fr":"0fr"},children:(0,n.jsx)("div",{className:"overflow-hidden",children:(0,n.jsxs)("div",{className:"px-4 pb-4",children:[(0,n.jsx)(aQ,{body:i.body,preview:i.preview}),i.has_attachments&&(0,n.jsx)(a0,{})]})})})]})}let a4={Marketing:"#ef4444",Transactional:"#3b82f6",Notification:"#f59e0b","Mailing List":"#8b5cf6",Automated:"#94a3b8"};function a5(e){var t;let{kind:r}=e,o=null!=(t=a4[r])?t:"#94a3b8";return(0,n.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full px-1.5 py-0 text-[10px] uppercase tracking-[0.06em]",style:{background:"".concat(o,"1f"),color:o,fontWeight:600},children:[(0,n.jsx)("span",{"aria-hidden":!0,style:{width:5,height:5,borderRadius:99,background:o}}),r]})}function a3(e){let{recipientName:t,onExpand:r}=e,[l,a]=(0,o.useState)(!1),[s,i]=(0,o.useState)(""),c=(0,o.useRef)(null);return((0,o.useEffect)(()=>{if(l){var e;null==(e=c.current)||e.focus(),null==r||r()}},[l,r]),l)?(0,n.jsxs)("div",{className:"rounded-xl border overflow-hidden",style:{background:"var(--color-surface)",borderColor:"var(--color-border-strong)",boxShadow:"var(--shadow-md)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2",style:{borderBottom:"1px solid var(--color-border)"},children:[(0,n.jsx)("span",{className:"text-[12px]",style:{color:"var(--color-text-muted)"},children:"To:"}),(0,n.jsx)("span",{className:"text-[13px] font-medium",style:{color:"var(--color-text)"},children:null!=t?t:"—"}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("button",{type:"button",onClick:()=>{a(!1),i("")},className:"text-[12px] rounded px-2 py-1 hover:bg-[var(--color-surface-hover)]",style:{color:"var(--color-text-muted)"},children:"Discard"})]}),(0,n.jsx)("textarea",{ref:c,value:s,onChange:e=>i(e.target.value),placeholder:"Type a reply…",className:"w-full px-4 py-3 outline-none resize-none",rows:6,style:{background:"var(--color-surface)",color:"var(--color-text)",fontFamily:'"Bookerly", Georgia, "Times New Roman", serif',fontSize:14,lineHeight:1.6,border:"none"}}),(0,n.jsxs)("div",{className:"flex items-center justify-between gap-3 px-4 py-2",style:{borderTop:"1px solid var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 text-[12px]",style:{color:"var(--color-text-muted)"},children:[(0,n.jsxs)("span",{children:[s.length," chars"]}),s.length>0&&(0,n.jsx)("span",{children:"\xb7"}),s.length>0&&(0,n.jsx)("span",{children:"Read-only — not actually sent"})]}),(0,n.jsx)("button",{type:"button",disabled:!0,title:"Two-way Gmail sync is on the roadmap",className:"rounded-lg px-3 py-1.5 text-[12px] font-medium opacity-60 cursor-not-allowed",style:{background:"var(--color-accent)",color:"#fff"},children:"Send"})]})]}):(0,n.jsxs)("button",{type:"button",onClick:()=>a(!0),className:"w-full flex items-center gap-3 rounded-xl border px-4 py-3 text-left transition-colors",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",color:"var(--color-text-muted)",fontFamily:'"Bookerly", Georgia, serif'},onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--color-border-strong)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--color-border)"},children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[(0,n.jsx)("polyline",{points:"9 17 4 12 9 7"}),(0,n.jsx)("path",{d:"M20 18v-2a4 4 0 0 0-4-4H4"})]}),(0,n.jsxs)("span",{className:"text-[14px]",children:["Reply",t?" to ".concat(t.split(" ")[0]):"","…"]})]})}function a6(e){var t;let{threadId:r,seedParticipants:l,recipientName:a,onOpenPerson:s,autoScrollOnLoad:i=!0,showReply:c=!0}=e,[d,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(!1),[m,x]=(0,o.useState)(null),f=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!r){u(null),x(null);return}let e=new AbortController;return h(!0),x(null),(async()=>{try{let t=await fetch("/api/crm/inbox/".concat(encodeURIComponent(r)),{cache:"no-store",signal:e.signal});if(!t.ok)throw Error("HTTP ".concat(t.status));let n=await t.json();u(n)}catch(e){if("AbortError"===e.name)return;x(e instanceof Error?e.message:"Failed to load this thread.")}finally{h(!1)}})(),()=>e.abort()},[r]);let v=(0,o.useMemo)(()=>{let e=new Map;if(null==d?void 0:d.people)for(let t of d.people)e.set(t.id,t);if(l)for(let t of l)e.has(t.id)||e.set(t.id,t);return e},[d,l]);if((0,o.useEffect)(()=>{i&&d&&f.current&&requestAnimationFrame(()=>{var e;let t=null==(e=f.current)?void 0:e.querySelector('[data-thread-message="latest"]');null==t||t.scrollIntoView({block:"nearest",behavior:"auto"})})},[d,i]),p&&!d)return(0,n.jsx)(aL,{label:"Loading conversation…"});if(m)return(0,n.jsx)(aT,{title:"Couldn't load this thread",description:m});if(d&&0===d.messages.length)return(0,n.jsx)(aT,{title:"This thread has no messages",description:"Likely a stub from a manual insert."});if(!d)return null;let g=null==(t=d.messages.at(-1))?void 0:t.id;return(0,n.jsxs)("div",{ref:f,className:"space-y-3",children:[d.messages.map(e=>(0,n.jsx)("div",{"data-thread-message":e.id===g?"latest":void 0,children:(0,n.jsx)(a2,{message:e,people:v,defaultExpanded:e.id===g,onOpenPerson:s})},e.id)),c&&(0,n.jsx)("div",{className:"pt-3",children:(0,n.jsx)(a3,{recipientName:null!=a?a:null})})]})}function a8(e){var t,r;let{selectedThread:l,starred:a,onToggleStar:s,onOpenPerson:i,onClose:c}=e,d=(0,o.useCallback)(()=>{null==c||c()},[c]);if(!l)return(0,n.jsxs)("div",{className:"flex h-full min-h-0 flex-col items-center justify-center px-8 text-center",style:{background:"var(--color-main-bg)"},children:[(0,n.jsx)("span",{className:"text-lg",style:{color:"var(--color-text)",fontWeight:500},children:"Pick a thread"}),(0,n.jsxs)("p",{className:"mt-1.5 text-[13px] max-w-xs",style:{color:"var(--color-text-muted)"},children:["Click any conversation in the list to read it here. Use"," ",(0,n.jsx)("kbd",{className:"rounded border px-1.5 py-0.5 text-[11px]",children:"j"})," /"," ",(0,n.jsx)("kbd",{className:"rounded border px-1.5 py-0.5 text-[11px]",children:"k"})," to navigate."]})]});let u=l.id,p=null!=(r=null!=(t=l.primary_sender_name)?t:l.primary_sender_email)?r:null;return(0,n.jsxs)("div",{className:"flex h-full min-h-0 flex-col motion-safe:animate-[conv-slide-in_180ms_ease-out]",style:{background:"var(--color-main-bg)"},children:[(0,n.jsx)("style",{children:"\n @keyframes conv-slide-in {\n from { opacity: 0; transform: translate3d(8px, 0, 0); }\n to { opacity: 1; transform: translate3d(0, 0, 0); }\n }\n "}),(0,n.jsx)(aJ,{subject:l.subject,participants:l.participants,gmailThreadId:l.gmail_thread_id,threadId:l.id,starred:a,onToggleStar:s,onOpenPerson:i,onClose:d}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto px-6 py-5",children:(0,n.jsx)(a6,{threadId:l.id,seedParticipants:l.participants,recipientName:p,onOpenPerson:i,autoScrollOnLoad:!0})})]},u)}let a7=[{keys:["j","↓"],label:"Next thread"},{keys:["k","↑"],label:"Previous thread"},{keys:["o","Enter"],label:"Open selected thread"},{keys:["Esc"],label:"Back to list"},{keys:["/"],label:"Focus search"},{keys:["x"],label:"Toggle bulk-select on focused thread"},{keys:["s"],label:"Star / unstar focused thread"},{keys:["e"],label:"Archive (read-only — toasts for now)"},{keys:["?"],label:"Open this help"}];function a9(e){let{open:t,onClose:r}=e;return((0,o.useEffect)(()=>{if(!t)return;let e=e=>{"Escape"===e.key&&(e.preventDefault(),r())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t,r]),t)?(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center px-4 py-8",style:{background:"rgba(0,0,0,0.35)"},onClick:r,children:(0,n.jsxs)("div",{role:"dialog","aria-label":"Inbox keyboard shortcuts",onClick:e=>e.stopPropagation(),className:"w-full max-w-md rounded-2xl border overflow-hidden",style:{background:"var(--color-surface)",borderColor:"var(--color-border-strong)",boxShadow:"var(--shadow-xl)"},children:[(0,n.jsxs)("header",{className:"flex items-center justify-between px-5 py-3",style:{borderBottom:"1px solid var(--color-border)"},children:[(0,n.jsx)("h2",{className:"tracking-tight",style:{color:"var(--color-text)",fontSize:"1rem",fontWeight:600},children:"Keyboard shortcuts"}),(0,n.jsx)("button",{type:"button",onClick:r,className:"rounded-md p-1 transition-colors hover:bg-[var(--color-surface-hover)]",style:{color:"var(--color-text-muted)"},"aria-label":"Close",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)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),(0,n.jsx)("ul",{className:"divide-y",style:{borderColor:"var(--color-border)"},children:a7.map(e=>(0,n.jsxs)("li",{className:"flex items-center justify-between px-5 py-2.5 text-[13px]",style:{borderBottom:"1px solid var(--color-border)"},children:[(0,n.jsx)("span",{style:{color:"var(--color-text)"},children:e.label}),(0,n.jsx)("span",{className:"flex items-center gap-1",children:e.keys.map(e=>(0,n.jsx)("kbd",{className:"inline-flex items-center justify-center rounded border px-1.5 py-0.5 text-[11px] tabular-nums",style:{background:"var(--color-bg)",borderColor:"var(--color-border)",color:"var(--color-text)",minWidth:22,fontFamily:"ui-monospace, SFMono-Regular, monospace"},children:e},e))})]},e.label))})]})}):null}function se(e,t){return"".concat("denchclaw.crm-inbox",":").concat(t,":").concat(e)}function st(e,t){try{let r=window.localStorage.getItem(se(e,t));if(!r)return new Set;let n=JSON.parse(r);if(Array.isArray(n))return new Set(n.filter(e=>"string"==typeof e))}catch(e){}return new Set}function sr(e,t,r){try{window.localStorage.setItem(se(e,t),JSON.stringify(Array.from(r)))}catch(e){}}function sn(e,t){let[r,n]=(0,o.useState)(0),l=(0,o.useMemo)(()=>st(e,t),[e,t,r]);(0,o.useEffect)(()=>{let r=se(e,t),o=e=>{e.key===r&&n(e=>e+1)};return window.addEventListener("storage",o),()=>window.removeEventListener("storage",o)},[e,t]);let a=(0,o.useCallback)(r=>{let o=st(e,t);o.has(r)?o.delete(r):o.add(r),sr(e,t,o),n(e=>e+1)},[e,t]),s=(0,o.useCallback)(r=>{let o=st(e,t);o.has(r)||(o.add(r),sr(e,t,o),n(e=>e+1))},[e,t]),i=(0,o.useCallback)(r=>{let o=st(e,t);o.has(r)&&(o.delete(r),sr(e,t,o),n(e=>e+1))},[e,t]),c=(0,o.useCallback)((r,o)=>{let l=st(e,t),a=!1;for(let e of r)o&&!l.has(e)?(l.add(e),a=!0):!o&&l.has(e)&&(l.delete(e),a=!0);a&&(sr(e,t,l),n(e=>e+1))},[e,t]),d=(0,o.useCallback)(()=>{sr(e,t,new Set),n(e=>e+1)},[e,t]),u=(0,o.useCallback)(e=>l.has(e),[l]);return{set:l,has:u,toggle:a,setOn:s,setOff:i,setMany:c,clear:d}}function so(e){var t,r;let{onOpenPerson:a}=e,s=(0,l.useRouter)(),i=(0,l.useSearchParams)(),c=i.get("thread"),d=null!=(t=i.get("q"))?t:"",u=i.get("sender"),[p,h]=(0,o.useState)(d),[m]=(0,o.useState)("all"===u||"automated"===u?u:"person"),[x,f]=(0,o.useState)(c),[v,g]=(0,o.useState)(0),[y,b]=(0,o.useState)(!1),[j,k]=(0,o.useState)([]),[w,N]=(0,o.useState)(0),[C,S]=(0,o.useState)(!0),[M,T]=(0,o.useState)(null),L="default",I=sn("starred",L),_=sn("read",L),R=sn("selected",L),E=(0,o.useRef)(null),D=(0,o.useRef)(null),A=(0,o.useCallback)(async e=>{S(!0),T(null);try{let t=new URLSearchParams;p.trim()&&t.set("q",p.trim()),t.set("sender",m),t.set("limit",String(100));let r=await fetch("/api/crm/inbox?".concat(t.toString()),{cache:"no-store",signal:e});if(!r.ok)throw Error("HTTP ".concat(r.status));let n=await r.json();k(n.threads),N(n.total)}catch(e){if("AbortError"===e.name)return;T(e instanceof Error?e.message:"Failed to load inbox.")}finally{S(!1)}},[p,m]);(0,o.useEffect)(()=>{D.current&&clearTimeout(D.current);let e=new AbortController;return D.current=setTimeout(()=>{A(e.signal)},150),()=>{e.abort(),D.current&&clearTimeout(D.current)}},[A]),(0,o.useEffect)(()=>{let e=new URLSearchParams(i.toString());e.set("crm","inbox"),p.trim()?e.set("q",p.trim()):e.delete("q"),"person"!==m?e.set("sender",m):e.delete("sender"),x?e.set("thread",x):e.delete("thread");let t="/?".concat(e.toString());t!=="".concat(window.location.pathname).concat(window.location.search)&&s.replace(t,{scroll:!1})},[p,m,x,s]),(0,o.useEffect)(()=>{if(!x)return;let e=j.findIndex(e=>e.id===x);e>=0&&g(e)},[x,j]),(0,o.useEffect)(()=>{x&&_.setOn(x)},[x]);let F=(0,o.useMemo)(()=>{var e;return null!=(e=j.find(e=>e.id===x))?e:null},[j,x]),P=null!=(r=j[v])?r:null,B=(0,o.useCallback)(e=>{f(e.id),g(j.findIndex(t=>t.id===e.id))},[j]),W=(0,o.useCallback)(()=>{f(null)},[]),O=(0,o.useCallback)(e=>{let t=Array.from(R.set);"read"===e?R.set.forEach(e=>_.setOn(e)):"star"===e?t.forEach(e=>I.toggle(e)):window.alert("Read-only inbox — archive will work once two-way Gmail sync ships.")},[R,_,I]);return!function(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1];(0,o.useEffect)(()=>{if(!t)return;let r=t=>{if(!t.metaKey&&!t.ctrlKey&&!t.altKey){if(function(e){if(!(e instanceof HTMLElement))return!1;let t=e.tagName;return"INPUT"===t||"TEXTAREA"===t||"SELECT"===t||!!e.isContentEditable}(t.target)){if("Escape"===t.key){var r,n;null==(r=(n=t.target).blur)||r.call(n)}return}switch(t.key){case"j":case"ArrowDown":t.preventDefault(),e.next();return;case"k":case"ArrowUp":t.preventDefault(),e.prev();return;case"o":case"Enter":t.preventDefault(),e.openSelected();return;case"Escape":t.preventDefault(),e.back();return;case"/":t.preventDefault(),e.focusSearch();return;case"x":t.preventDefault(),e.toggleSelectedBulk();return;case"s":t.preventDefault(),e.toggleStar();return;case"e":t.preventDefault(),e.archiveSelected();return;case"?":t.preventDefault(),e.openHelp();return;default:return}}};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[t,e])}({next:()=>{if(0===j.length)return;let e=Math.min(j.length-1,v+1);g(e);let t=j[e];t&&B(t)},prev:()=>{if(0===j.length)return;let e=Math.max(0,v-1);g(e);let t=j[e];t&&B(t)},openSelected:()=>{P&&B(P)},back:()=>{if(y)return void b(!1);f(null)},focusSearch:()=>{var e,t;null==(e=E.current)||e.focus(),null==(t=E.current)||t.select()},toggleSelectedBulk:()=>{P&&R.toggle(P.id)},toggleStar:()=>{P&&I.toggle(P.id)},archiveSelected:()=>{O("archive")},openHelp:()=>b(!0)},!y),(0,o.useEffect)(()=>{var e,t;if(!P)return;let r=document.querySelector('[data-thread-row="true"][data-thread-id="'.concat((e=P.id,"function"==typeof(null==(t=window.CSS)?void 0:t.escape)?window.CSS.escape(e):e.replace(/['"\\]/g,"\\$&")),'"]'));r&&r.scrollIntoView({block:"nearest",behavior:"auto"})},[P]),(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(aj,{hasSelection:!!F,list:(0,n.jsxs)("div",{className:"flex h-full min-h-0 flex-col",style:{background:"var(--color-bg)"},children:[(0,n.jsx)(aN,{ref:E,search:p,onSearchChange:h,selectedCount:R.set.size,onClearSelection:R.clear,onBulkAction:O,onOpenShortcuts:()=>b(!0)}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[M&&(0,n.jsx)("div",{className:"px-4 py-3 text-[13px]",style:{color:"var(--color-text-muted)"},children:M}),(0,n.jsx)(aV,{threads:j,loading:C,selectedThreadId:x,selectedIds:R.set,isRead:_.has,isStarred:I.has,onSelect:B,onToggleSelected:R.toggle,onToggleStarred:I.toggle}),!C&&w>j.length&&(0,n.jsxs)("div",{className:"px-4 py-3 text-[12px]",style:{color:"var(--color-text-muted)"},children:["Showing ",j.length.toLocaleString()," of ",w.toLocaleString()," threads."]})]})]}),conversation:(0,n.jsx)(a8,{selectedThread:F,starred:!!F&&I.has(F.id),onToggleStar:()=>{F&&I.toggle(F.id)},onOpenPerson:a,onClose:W})}),(0,n.jsx)(a9,{open:y,onClose:()=>b(!1)})]})}function sl(e){var t,r,o,l;let{event:a,expanded:s,onToggle:i,onOpenPerson:c,onOpenCompany:d}=e,u=a.start_at?new Date(a.start_at):null,p=a.end_at?new Date(a.end_at):null,h=u?p?"".concat(su(u)," – ").concat(su(p)):su(u):"",m=(null!=(o=a.attendees)?o:[]).slice(0,5),x=(null!=(l=null==(t=a.attendees)?void 0:t.length)?l:0)-m.length;return(0,n.jsxs)("li",{className:"overflow-hidden",style:{background:s?"var(--color-surface-hover)":"transparent",transition:"background 120ms ease"},children:[(0,n.jsxs)("div",{role:"button",tabIndex:0,"aria-expanded":s,onClick:i,onKeyDown:e=>{e.target===e.currentTarget&&("Enter"===e.key||" "===e.key)&&(e.preventDefault(),i())},className:"group/event w-full flex items-center gap-3 px-3 py-2 text-left cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] transition-colors",onMouseEnter:e=>{s||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{s||(e.currentTarget.style.background="transparent")},children:[(0,n.jsx)("div",{className:"text-[12px] tabular-nums shrink-0 whitespace-nowrap",style:{color:"var(--color-text-muted)",width:"11rem"},children:h||(a.start_at?aW(a.start_at):"")}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[(0,n.jsx)("p",{className:"truncate text-[13.5px]",style:{color:"var(--color-text)",fontWeight:500},children:(null==(r=a.title)?void 0:r.trim())||"(no title)"}),a.meeting_type&&(0,n.jsx)("span",{className:"shrink-0 rounded-full px-1.5 py-0 text-[10px] uppercase tracking-[0.06em]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)",fontWeight:600},children:a.meeting_type})]}),(0,n.jsxs)("div",{className:"flex shrink-0 items-center gap-2",children:[m.length>0&&(0,n.jsxs)("div",{className:"flex items-center -space-x-1.5",children:[m.slice(0,4).map(e=>{var t,r,o;return(0,n.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),null==c||c(e.id)},disabled:!c,title:null!=(r=null!=(t=e.name)?t:e.email)?r:void 0,className:"disabled:cursor-default rounded-full",style:{boxShadow:"0 0 0 2px var(--color-background)"},children:(0,n.jsx)(a_,{src:e.avatar_url,name:e.name,seed:null!=(o=e.email)?o:e.id,size:"sm"})},e.id)}),x>0&&(0,n.jsxs)("span",{className:"ml-1 text-[11px] tabular-nums",style:{color:"var(--color-text-muted)"},children:["+",x]})]}),(0,n.jsx)(sd,{expanded:s})]})]}),(0,n.jsx)("div",{className:"grid transition-[grid-template-rows] duration-[220ms] ease-out motion-reduce:transition-none",style:{gridTemplateRows:s?"1fr":"0fr"},children:(0,n.jsx)("div",{className:"overflow-hidden",children:s&&(0,n.jsx)(sa,{eventId:a.id,fallbackEvent:a,onOpenPerson:c,onOpenCompany:d})})})]})}function sa(e){var t,r,l,a,s,i,c,d,u;let{eventId:p,fallbackEvent:h,onOpenPerson:m,onOpenCompany:x}=e,[f,v]=(0,o.useState)(null),[g,y]=(0,o.useState)(!0),[b,j]=(0,o.useState)(null);(0,o.useEffect)(()=>{let e=!1;return y(!0),j(null),fetch("/api/crm/calendar/".concat(encodeURIComponent(p)),{cache:"no-store"}).then(e=>{if(!e.ok)throw Error("HTTP ".concat(e.status));return e.json()}).then(t=>{e||v(t)}).catch(t=>{e||j(t instanceof Error?t.message:"Failed to load meeting details.")}).finally(()=>{e||y(!1)}),()=>{e=!0}},[p]);let k=(null!=(t=null==f?void 0:f.event.start_at)?t:h.start_at)?new Date(null!=(r=null==f?void 0:f.event.start_at)?r:h.start_at):null,w=(null!=(l=null==f?void 0:f.event.end_at)?l:h.end_at)?new Date(null!=(a=null==f?void 0:f.event.end_at)?a:h.end_at):null,N=k?(u=k,new Intl.DateTimeFormat(void 0,{weekday:"long",month:"long",day:"numeric",year:"numeric"}).format(u)):null,C=k?w?"".concat(su(k)," – ").concat(su(w)):su(k):null,S=k&&w?function(e,t){let r=t.getTime()-e.getTime();if(r<=0)return"";let n=Math.round(r/6e4);if(n>=1440){let e=Math.round(n/1440);return"".concat(e," day").concat(1===e?"":"s")}let o=Math.floor(n/60),l=n%60;return 0===o?"".concat(l," min"):0===l?"".concat(o,"h"):"".concat(o,"h ").concat(l,"m")}(k,w):null,M=null!=(s=null==f?void 0:f.organizer)?s:null,T=null!=(c=null!=(i=null==f?void 0:f.attendees)?i:h.attendees)?c:[],L=null!=(d=null==f?void 0:f.companies)?d:[];return(0,n.jsxs)("div",{className:"border-t px-4 py-4",style:{borderColor:"var(--color-border)",background:"var(--color-background)"},children:[(N||C||S)&&(0,n.jsx)(ss,{label:"When",children:(0,n.jsxs)("div",{className:"text-[13px]",style:{color:"var(--color-text)"},children:[N&&(0,n.jsx)("div",{className:"font-medium",children:N}),(C||S)&&(0,n.jsxs)("div",{className:"mt-0.5",style:{color:"var(--color-text-muted)"},children:[C,C&&S&&" \xb7 ",S]})]})}),M&&(0,n.jsx)(ss,{label:"Organizer",children:(0,n.jsx)(si,{person:M,onOpenPerson:m})}),T.length>0&&(0,n.jsx)(ss,{label:"Attendees \xb7 ".concat(T.length),children:(0,n.jsx)("div",{className:"flex flex-col gap-1.5",children:T.map(e=>(0,n.jsx)(si,{person:e,onOpenPerson:m},e.id))})}),L.length>0&&(0,n.jsx)(ss,{label:1===L.length?"Company":"Companies",children:(0,n.jsx)("div",{className:"flex flex-col gap-1.5",children:L.map(e=>(0,n.jsx)(sc,{company:e,onOpenCompany:x},e.id))})}),g&&!f&&(0,n.jsx)("p",{className:"text-[12px]",style:{color:"var(--color-text-muted)"},children:"Loading meeting details…"}),b&&(0,n.jsxs)("p",{className:"text-[12px]",style:{color:"var(--color-text-muted)"},children:["Couldn’t load meeting details (",b,"). Showing what we have."]}),!g&&!b&&f&&0===T.length&&!M&&0===L.length&&(0,n.jsx)("p",{className:"text-[12px]",style:{color:"var(--color-text-muted)"},children:"No additional details for this meeting."})]})}function ss(e){let{label:t,children:r}=e;return(0,n.jsxs)("div",{className:"mb-4 last:mb-0",children:[(0,n.jsx)("h4",{className:"mb-1.5 text-[10px] font-semibold uppercase tracking-[0.16em]",style:{color:"var(--color-text-muted)"},children:t}),r]})}function si(e){var t,r,o;let{person:l,onOpenPerson:a}=e,s=(null==(t=l.name)?void 0:t.trim())||l.email||"Unknown",i=(null==(r=l.name)?void 0:r.trim())&&l.email?l.email:null;return(0,n.jsxs)("button",{type:"button",onClick:()=>null==a?void 0:a(l.id),disabled:!a,className:"flex items-center gap-2.5 rounded-lg px-2 py-1.5 text-left transition-colors disabled:cursor-default",style:{color:"var(--color-text)"},onMouseEnter:e=>{a&&(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,n.jsx)(a_,{src:l.avatar_url,name:s,seed:null!=(o=l.email)?o:l.id,size:"sm"}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("p",{className:"truncate text-[13px] font-medium",style:{color:"var(--color-text)"},children:s}),i&&(0,n.jsx)("p",{className:"truncate text-[11px]",style:{color:"var(--color-text-muted)"},children:i})]})]})}function sc(e){var t;let{company:r,onOpenCompany:o}=e,l=(null==(t=r.name)?void 0:t.trim())||r.domain||"Unknown company";return(0,n.jsxs)("button",{type:"button",onClick:()=>null==o?void 0:o(r.id),disabled:!o,className:"flex items-center gap-2.5 rounded-lg px-2 py-1.5 text-left transition-colors disabled:cursor-default",onMouseEnter:e=>{o&&(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,n.jsx)(aE,{domain:r.domain,name:r.name,size:"sm"}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("p",{className:"truncate text-[13px] font-medium",style:{color:"var(--color-text)"},children:l}),r.domain&&r.name&&(0,n.jsx)("p",{className:"truncate text-[11px]",style:{color:"var(--color-text-muted)"},children:r.domain})]})]})}function sd(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","aria-hidden":!0,className:"motion-reduce:transition-none",style:{color:"var(--color-text-muted)",transform:t?"rotate(180deg)":"rotate(0deg)",transition:"transform 180ms ease"},children:(0,n.jsx)("path",{d:"m6 9 6 6 6-6"})})}function su(e){return new Intl.DateTimeFormat(void 0,{hour:"numeric",minute:"2-digit"}).format(e)}function sp(e){var t,r;let{event:l,anchor:a,onClose:s,onOpenPerson:i,onOpenCompany:c}=e,[d,u]=(0,o.useState)(!1);(0,o.useEffect)(()=>{u(!0)},[]),(0,o.useEffect)(()=>{let e=e=>{"Escape"===e.key&&s()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[s]);let p=(0,o.useMemo)(()=>{let e=window.innerWidth,t=window.innerHeight,r=a.right+8;if(r+360+8>e){let t=a.left-360-8;r=t>=8?t:Math.max(8,Math.min(e-360-8,a.left))}let n=a.top;return n+480+8>t&&(n=Math.max(8,t-480-8)),n<8&&(n=8),{left:r,top:n}},[a]);return d?(0,rR.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"fixed inset-0 z-[60]",onClick:s,style:{background:"transparent"},"aria-hidden":!0}),(0,n.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":(null==(t=l.title)?void 0:t.trim())||"Meeting details",className:"fixed z-[61] flex flex-col rounded-xl overflow-hidden",style:{left:p.left,top:p.top,width:360,maxHeight:480,background:"var(--color-surface)",border:"1px solid var(--color-border)",boxShadow:"var(--shadow-lg)"},onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex shrink-0 items-center justify-between gap-2 px-4 py-2.5",style:{borderBottom:"1px solid var(--color-border)"},children:[(0,n.jsx)("p",{className:"truncate text-[13px] font-medium",style:{color:"var(--color-text)"},children:(null==(r=l.title)?void 0:r.trim())||"(no title)"}),(0,n.jsx)("button",{type:"button",onClick:s,className:"shrink-0 p-1 rounded cursor-pointer",style:{color:"var(--color-text-muted)"},"aria-label":"Close",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)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:(0,n.jsx)(sa,{eventId:l.id,fallbackEvent:l,onOpenPerson:i,onOpenCompany:c})})]})]}),document.body):null}function sh(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function sm(e){let t=sh(e);return t.setDate(t.getDate()-t.getDay()),t}function sx(e,t){let r=sh(e);return r.setDate(r.getDate()+t),r}function sf(e){return"".concat(e.getFullYear(),"-").concat(String(e.getMonth()+1).padStart(2,"0"),"-").concat(String(e.getDate()).padStart(2,"0"))}function sv(e){var t;let{event:r,onClick:o}=e,l=r.start_at?new Date(r.start_at).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):"",a=(null==(t=r.title)?void 0:t.trim())||"(no title)";return(0,n.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),o(r,e.currentTarget.getBoundingClientRect())},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:l?"".concat(l," \xb7 ").concat(a):a,children:[l&&(0,n.jsx)("span",{className:"opacity-80 mr-1",children:l}),(0,n.jsx)("span",{children:a})]})}function sg(e){let{onOpenPerson:t,onOpenCompany:r}=e,[l,a]=(0,o.useState)("month"),[s,i]=(0,o.useState)(()=>sh(new Date)),[c,d]=(0,o.useState)([]),[u,p]=(0,o.useState)(!0),[h,m]=(0,o.useState)(null),[x,f]=(0,o.useState)(null),{rangeFrom:v,rangeTo:g}=(0,o.useMemo)(()=>{let e=s.getFullYear(),t=s.getMonth();if("day"===l){let r=new Date(e,t,s.getDate());return{rangeFrom:r,rangeTo:sx(r,1)}}if("week"===l){let e=sm(s);return{rangeFrom:e,rangeTo:sx(e,7)}}if("year"===l)return{rangeFrom:new Date(e,0,1),rangeTo:new Date(e+1,0,1)};let r=sm(new Date(e,t,1));return{rangeFrom:r,rangeTo:sx(r,42)}},[s,l]);(0,o.useEffect)(()=>{let e=new AbortController;p(!0),m(null);let t=new URLSearchParams;return t.set("from",v.toISOString()),t.set("to",g.toISOString()),t.set("limit","500"),fetch("/api/crm/calendar?".concat(t.toString()),{cache:"no-store",signal:e.signal}).then(e=>{if(!e.ok)throw Error("HTTP ".concat(e.status));return e.json()}).then(e=>d(e.events)).catch(e=>{"AbortError"!==e.name&&m(e instanceof Error?e.message:"Failed to load calendar.")}).finally(()=>p(!1)),()=>e.abort()},[v,g]);let y=(0,o.useMemo)(()=>(function(e){let t=new Map;for(let n of e){var r;if(!n.start_at)continue;let e=new Date(n.start_at);if(Number.isNaN(e.getTime()))continue;let o=sf(e),l=null!=(r=t.get(o))?r:[];l.push(n),t.set(o,l)}for(let e of t.values())e.sort((e,t)=>(e.start_at?Date.parse(e.start_at):0)-(t.start_at?Date.parse(t.start_at):0));return t})(c),[c]),b=sf(new Date),j=(0,o.useCallback)(e=>{i(t=>{if("month"===l){let r=new Date(t.getFullYear(),t.getMonth(),1);r.setMonth(r.getMonth()+e);let n=new Date(r.getFullYear(),r.getMonth()+1,0).getDate();return r.setDate(Math.min(t.getDate(),n)),r}if("week"===l)return sx(t,7*e);if("day"===l)return sx(t,e);let r=new Date(t.getFullYear()+e,t.getMonth(),1),n=new Date(r.getFullYear(),r.getMonth()+1,0).getDate();return r.setDate(Math.min(t.getDate(),n)),r})},[l]),k=(0,o.useCallback)((e,t)=>{f({event:e,rect:t})},[]),w=(0,o.useMemo)(()=>{if("day"===l)return s.toLocaleDateString(void 0,{weekday:"long",month:"long",day:"numeric",year:"numeric"});if("week"===l){let e=sm(s),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(s.getFullYear()):s.toLocaleDateString(void 0,{month:"long",year:"numeric"})},[s,l]);return(0,n.jsxs)("div",{className:"px-6 py-4",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-4 flex-wrap gap-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:()=>j(-1),className:"p-1.5 rounded-lg cursor-pointer",style:{color:"var(--color-text-muted)"},"aria-label":"Previous",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:w}),(0,n.jsx)("button",{type:"button",onClick:()=>j(1),className:"p-1.5 rounded-lg cursor-pointer",style:{color:"var(--color-text-muted)"},"aria-label":"Next",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:()=>i(sh(new Date)),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:()=>a(e),className:"px-3 py-1 rounded-md text-xs font-medium cursor-pointer capitalize",style:{background:l===e?"var(--color-surface)":"transparent",color:l===e?"var(--color-text)":"var(--color-text-muted)"},children:e},e))})]}),h&&(0,n.jsx)("div",{className:"mb-3 text-[13px]",style:{color:"var(--color-text-muted)"},children:h}),u&&0===c.length?(0,n.jsx)(aL,{}):u||0!==c.length?(0,n.jsxs)(n.Fragment,{children:["day"===l&&(0,n.jsx)(sy,{anchor:s,eventsByDay:y,todayStr:b,onChipClick:k}),"week"===l&&(0,n.jsx)(sb,{anchor:s,eventsByDay:y,todayStr:b,onChipClick:k,onSelectDay:e=>{let t=function(e){let t=e.match(/^(\d{4})-(\d{2})-(\d{2})$/);return t?new Date(Number(t[1]),Number(t[2])-1,Number(t[3])):null}(e);t&&(i(t),a("day"))}}),"month"===l&&(0,n.jsx)(sj,{anchor:s,eventsByDay:y,todayStr:b,onChipClick:k}),"year"===l&&(0,n.jsx)(sk,{anchor:s,eventsByDay:y,todayStr:b,onSelectMonth:e=>{i(e),a("month")}})]}):(0,n.jsx)(aT,{title:"No events in this range",description:"Try a different month, or connect Google Calendar in onboarding to import events."}),x&&(0,n.jsx)(sp,{event:x.event,anchor:x.rect,onClose:()=>f(null),onOpenPerson:t,onOpenCompany:r})]})}function sy(e){var t;let{anchor:r,eventsByDay:l,todayStr:a,onChipClick:s}=e,i=sf(r),c=null!=(t=l.get(i))?t:[],d=i===a,u=Array.from({length:24},(e,t)=>t),p=(0,o.useMemo)(()=>{let e=new Map;for(let r of c){var t;if(!r.start_at)continue;let n=new Date(r.start_at).getHours(),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=p.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=>(0,n.jsx)(sv,{event:e,onClick:s},e.id))})]},e)})})}function sb(e){let{anchor:t,eventsByDay:r,todayStr:o,onChipClick:l,onSelectDay:a}=e,s=sm(t),i=Array.from({length:7},(e,t)=>{let r=new Date(s);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:i.map(e=>{let t=sf(e),r=t===o;return(0,n.jsxs)("button",{type:"button",onClick:()=>a(t),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:i.map(e=>{var t;let a=sf(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=>(0,n.jsx)(sv,{event:e,onClick:l},e.id)),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 sj(e){let{anchor:t,eventsByDay:r,todayStr:l,onChipClick:a}=e,s=(0,o.useMemo)(()=>{let e=sm(new Date(t.getFullYear(),t.getMonth(),1)),r=[];for(let t=0;t<6;t++){let n=[];for(let r=0;r<7;r++){let o=new Date(e);o.setDate(o.getDate()+7*t+r),n.push(o)}r.push(n)}return r},[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=sf(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=>(0,n.jsx)(sv,{event:e,onClick:a},e.id)),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 sk(e){let{anchor:t,eventsByDay:r,todayStr:o,onSelectMonth:l}=e,a=t.getFullYear(),s=Array.from({length:12},(e,t)=>t);return(0,n.jsx)("div",{className:"grid grid-cols-3 sm:grid-cols-4 gap-4",children:s.map(e=>{let t=new Date(a,e,1),s=t.getDay(),i=new Date(a,e+1,0).getDate(),c=[];for(let e=0;e<s;e++)c.push(null);for(let e=1;e<=i;e++)c.push(e);let d=0;for(let t=1;t<=i;t++){var u;let n="".concat(a,"-").concat(String(e+1).padStart(2,"0"),"-").concat(String(t).padStart(2,"0"));d+=(null!=(u=r.get(n))?u:[]).length}return(0,n.jsxs)("button",{type:"button",onClick:()=>l(t),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)),c.map((t,l)=>{var s;if(null===t)return(0,n.jsx)("div",{},"e-".concat(l));let i="".concat(a,"-").concat(String(e+1).padStart(2,"0"),"-").concat(String(t).padStart(2,"0")),c=null!=(s=r.get(i))?s:[],d=i===o,u=c.length>0;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:u?"color-mix(in srgb, var(--color-accent) 10%, transparent)":void 0},children:t},i)})]}),d>0&&(0,n.jsxs)("div",{className:"text-[9px] mt-1.5",style:{color:"var(--color-text-muted)"},children:[d," event",1!==d?"s":""]})]},e)})})}let sw=[{id:"upcoming",label:"Upcoming"},{id:"this_week",label:"This week"},{id:"past",label:"Past"}],sN=[{id:"list",label:"List"},{id:"calendar",label:"Calendar"}];function sC(e){let{onOpenPerson:t,onOpenCompany:r}=e,[l,a]=(0,o.useState)("list"),[s,i]=(0,o.useState)("upcoming"),[c,d]=(0,o.useState)([]),[u,p]=(0,o.useState)(null),[h,m]=(0,o.useState)(!0),[x,f]=(0,o.useState)(null),[v,g]=(0,o.useState)(null),y=(0,o.useCallback)(async e=>{m(!0),f(null);try{let t=new URLSearchParams,r=new Date;if("upcoming"===s)t.set("from",new Date(r.getTime()-216e5).toISOString());else if("this_week"===s){let e=function(e){let t=new Date(e),r=t.getDay();return t.setDate(t.getDate()-(r+6)%7),t.setHours(0,0,0,0),t}(r),n=new Date(e);n.setDate(e.getDate()+7),t.set("from",e.toISOString()),t.set("to",n.toISOString())}else t.set("to",r.toISOString());t.set("limit","200");let n=await fetch("/api/crm/calendar?".concat(t.toString()),{cache:"no-store",signal:e});if(!n.ok)throw Error("HTTP ".concat(n.status));let o=await n.json(),l=[...o.events].toSorted((e,t)=>{let r=e.start_at?Date.parse(e.start_at):0,n=t.start_at?Date.parse(t.start_at):0;return"past"===s?n-r:r-n});d(l),p(o.total)}catch(e){if("AbortError"===e.name)return;f(e instanceof Error?e.message:"Failed to load calendar.")}finally{m(!1)}},[s]);(0,o.useEffect)(()=>{if("list"!==l)return;let e=new AbortController;return y(e.signal),()=>e.abort()},[y,l]);let b=(0,o.useMemo)(()=>{let e=new Map;for(let t of c){let r=t.start_at?az(t.start_at):"Unknown date";e.has(r)||e.set(r,[]),e.get(r).push(t)}return Array.from(e.entries())},[c]),j=(0,n.jsx)("div",{className:"flex items-center gap-1 rounded-lg p-0.5",style:{background:"var(--color-surface-hover)"},children:sN.map(e=>{let t=l===e.id;return(0,n.jsx)("button",{type:"button",onClick:()=>a(e.id),className:"px-3 py-1 rounded-md text-[12px] font-medium cursor-pointer transition-colors",style:{background:t?"var(--color-surface)":"transparent",color:t?"var(--color-text)":"var(--color-text-muted)",boxShadow:t?"var(--shadow-sm)":"none"},children:e.label},e.id)})});return(0,n.jsx)(aM,{title:"Calendar",count:"list"===l&&null!=u?u:void 0,toolbar:j,children:"calendar"===l?(0,n.jsx)(sg,{onOpenPerson:t,onOpenCompany:r}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"sticky top-0 z-10 flex flex-wrap items-center gap-1 px-6 py-3",style:{background:"var(--color-background)",borderBottom:"1px solid var(--color-border)"},children:sw.map(e=>{let t=s===e.id;return(0,n.jsx)("button",{type:"button",onClick:()=>i(e.id),className:"rounded-full px-3 py-1 text-[12px] font-medium transition-colors",style:{background:t?"var(--color-text)":"transparent",color:t?"var(--color-background)":"var(--color-text-muted)",border:t?"1px solid var(--color-text)":"1px solid var(--color-border)"},children:e.label},e.id)})}),x&&(0,n.jsx)("div",{className:"px-6 py-3 text-[13px]",style:{color:"var(--color-text-muted)"},children:x}),h&&0===c.length?(0,n.jsx)(aL,{}):0===c.length?(0,n.jsx)(aT,{title:"No events",description:"Connect Google Calendar in onboarding to import events."}):(0,n.jsx)("div",{className:"px-6 py-2",children:b.map(e=>{let[o,l]=e;return(0,n.jsxs)("section",{className:"mb-4 last:mb-0",children:[(0,n.jsx)("h3",{className:"sticky top-[57px] z-[1] mb-1 px-1 py-1.5 text-[10px] font-semibold uppercase tracking-[0.18em]",style:{color:"var(--color-text-muted)",background:"var(--color-background)"},children:o}),(0,n.jsx)("ul",{className:"overflow-hidden rounded-lg",style:{border:"1px solid var(--color-border)",background:"var(--color-surface)"},children:l.map((e,o)=>(0,n.jsx)("div",{style:{borderBottom:o===l.length-1?"none":"1px solid var(--color-border)"},children:(0,n.jsx)(sl,{event:e,expanded:v===e.id,onToggle:()=>g(t=>t===e.id?null:e.id),onOpenPerson:t,onOpenCompany:r})},e.id))})]},o)})})]})})}var sS=r(34471);let sM=[{min:500,label:"Inner circle",color:"#6366f1",rank:4},{min:100,label:"Strong",color:"#22c55e",rank:3},{min:20,label:"Active",color:"#3b82f6",rank:2},{min:1,label:"Weak",color:"#f59e0b",rank:1},{min:0,label:"Cold",color:"#94a3b8",rank:0}];function sT(e){let{score:t,size:r="md",showLabel:o=!0}=e,l=function(e){let t="string"==typeof e?Number(e):null!=e?e:0;if(!Number.isFinite(t)||t<0){let e=sM[sM.length-1];return{label:e.label,color:e.color,rank:e.rank}}for(let e of sM)if(t>=e.min)return{label:e.label,color:e.color,rank:e.rank};let r=sM[sM.length-1];return{label:r.label,color:r.color,rank:r.rank}}(t),a="sm"===r?6:8;return(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5 rounded-full font-medium",style:{background:"var(--color-surface-hover)",color:"var(--color-text)",padding:"sm"===r?"1px 6px":"2px 8px",fontSize:"sm"===r?10:11,lineHeight:1.4},title:"Connection strength: ".concat(l.label),children:[(0,n.jsx)("span",{"aria-hidden":!0,style:{width:a,height:a,borderRadius:99,background:l.color,flexShrink:0}}),o&&l.label]})}let sL={Marketing:"#ef4444",Transactional:"#3b82f6",Notification:"#f59e0b","Mailing List":"#8b5cf6",Automated:"#94a3b8"};function sI(e){let{threads:t,onOpenPerson:r}=e,[l,a]=(0,o.useState)(null);return(0,n.jsx)("ul",{className:"divide-y",style:{borderTop:"1px solid var(--color-border)",borderBottom:"1px solid var(--color-border)"},children:t.map(e=>(0,n.jsx)(s_,{thread:e,expanded:l===e.id,onToggle:()=>a(t=>t===e.id?null:e.id),onOpenPerson:r},e.id))})}function s_(e){var t,r,o,l,a,s,i,c,d,u,p;let{thread:h,expanded:m,onToggle:x,onOpenPerson:f}=e,v=null!=(s=null!=(a=h.primary_sender_name)?a:h.primary_sender_email)?s:null,g=null!=(i=h.primary_sender_email)?i:null,y=h.primary_sender_type&&"Person"!==h.primary_sender_type?null!=(c=sL[h.primary_sender_type])?c:"#94a3b8":null,b=h.gmail_thread_id?"https://mail.google.com/mail/u/0/#all/".concat(h.gmail_thread_id):null;return(0,n.jsxs)("li",{children:[(0,n.jsxs)("div",{role:"button",tabIndex:0,onClick:x,onKeyDown:e=>{e.target===e.currentTarget&&("Enter"===e.key||" "===e.key)&&(e.preventDefault(),x())},"aria-expanded":m,className:"group grid w-full items-center gap-3 px-4 py-3 text-left transition-colors cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]",style:{gridTemplateColumns:"auto minmax(0, 1fr) auto",background:m?"var(--color-accent-light)":"transparent",borderLeft:m?"2px solid var(--color-accent)":"2px solid transparent"},onMouseEnter:e=>{m||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{m||(e.currentTarget.style.background="transparent")},children:[(0,n.jsx)(a_,{src:h.primary_sender_avatar_url,name:null!=(d=null!=v?v:h.subject)?d:"Email",seed:null!=g?g:h.id,size:"sm"}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-baseline gap-2 flex-wrap",children:[(0,n.jsx)("span",{className:"truncate",style:{color:"var(--color-text)",fontSize:13,fontWeight:600},children:(null==(t=h.subject)?void 0:t.trim())||"(no subject)"}),y&&(0,n.jsxs)("span",{className:"shrink-0 inline-flex items-center gap-1 rounded-full px-1.5 py-0 text-[10px] uppercase tracking-[0.06em]",style:{background:"".concat(y,"1f"),color:y,fontWeight:600},children:[(0,n.jsx)("span",{"aria-hidden":!0,style:{width:5,height:5,borderRadius:99,background:y}}),h.primary_sender_type]}),(0,n.jsxs)("span",{className:"text-[11px] tabular-nums",style:{color:"var(--color-text-muted)",fontWeight:400},children:[null!=(u=h.message_count)?u:0," ",(null!=(p=h.message_count)?p:0)===1?"msg":"msgs"]})]}),((null==(r=h.snippet)?void 0:r.trim())||v)&&(0,n.jsxs)("p",{className:"mt-0.5 truncate text-[13px]",style:{color:"var(--color-text-muted)",fontFamily:'"Bookerly", Georgia, "Times New Roman", serif'},children:[v&&(0,n.jsx)("span",{style:{color:"var(--color-text)"},children:v}),v&&(null==(o=h.snippet)?void 0:o.trim())&&(0,n.jsxs)("span",{children:[" — ",h.snippet.trim()]}),!v&&(null==(l=h.snippet)?void 0:l.trim())&&h.snippet.trim()]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[b&&(0,n.jsx)("a",{href:b,target:"_blank",rel:"noreferrer",onClick:e=>e.stopPropagation(),title:"Open in Gmail",className:"inline-flex h-7 w-7 items-center justify-center rounded transition-colors opacity-0 group-hover:opacity-100",style:{color:"var(--color-text-muted)"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface)",e.currentTarget.style.color="var(--color-text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--color-text-muted)"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[(0,n.jsx)("path",{d:"M15 3h6v6"}),(0,n.jsx)("path",{d:"M10 14 21 3"}),(0,n.jsx)("path",{d:"M21 14v5a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5"})]})}),(0,n.jsx)("span",{className:"text-right text-[11px] tabular-nums",style:{color:"var(--color-text-muted)"},title:h.last_message_at?aO(h.last_message_at):void 0,children:h.last_message_at&&aW(h.last_message_at)})]})]}),(0,n.jsx)("div",{className:"grid transition-[grid-template-rows] duration-[220ms] ease-out motion-reduce:transition-none",style:{gridTemplateRows:m?"1fr":"0fr"},children:(0,n.jsx)("div",{className:"overflow-hidden",children:m&&(0,n.jsx)("div",{className:"px-4 py-4",style:{background:"var(--color-main-bg)"},children:(0,n.jsx)(a6,{threadId:h.id,recipientName:v,onOpenPerson:f,autoScrollOnLoad:!1})})})})]})}let sR=["today","yesterday","this_week","last_week","this_month"];function sE(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function sD(e){let{personId:t,onOpenPerson:r,onOpenCompany:l}=e,[a,s]=(0,o.useState)([]),[i,c]=(0,o.useState)(0),[d,u]=(0,o.useState)(0),[p,h]=(0,o.useState)(!1),[m,x]=(0,o.useState)(!0),[f,v]=(0,o.useState)(!1),[g,y]=(0,o.useState)(null),[b,j]=(0,o.useState)(null),k=(0,o.useCallback)(async(e,r)=>{let n=await fetch("/api/crm/people/".concat(encodeURIComponent(t),"/activity?limit=").concat(100,"&offset=").concat(e),{cache:"no-store",signal:r});if(!n.ok)throw Error("HTTP ".concat(n.status));return await n.json()},[t]);(0,o.useEffect)(()=>{let e=new AbortController;return x(!0),y(null),s([]),u(0),h(!1),j(null),(async()=>{try{let t=await k(0,e.signal);if(!t)return;s(t.activities),c(t.total),h(t.has_more),u(t.activities.length)}catch(e){if("AbortError"===e.name)return;y(e instanceof Error?e.message:"Failed to load activity.")}finally{x(!1)}})(),()=>e.abort()},[k]);let w=(0,o.useCallback)(async()=>{if(!f&&p){v(!0);try{let e=await k(d);if(!e)return;s(t=>[...t,...e.activities]),h(e.has_more),u(t=>t+e.activities.length)}catch(e){y(e instanceof Error?e.message:"Failed to load more activity.")}finally{v(!1)}}},[p,k,f,d]),N=(0,o.useMemo)(()=>{let e=new Date,t=new Map;for(let r of a){let n=function(e,t){if(null==e)return"unknown";let r="string"==typeof e?Date.parse(e):e instanceof Date?e.getTime():e;if(!Number.isFinite(r))return"unknown";let n=new Date(r);if(sE(n,t))return"today";let o=new Date(t);if(o.setDate(t.getDate()-1),sE(n,o))return"yesterday";let l=function(e){let t=new Date(e),r=t.getDay();return t.setDate(t.getDate()-(r+6)%7),t.setHours(0,0,0,0),t}(t),a=new Date(l);a.setDate(l.getDate()-7);let s=new Date(l);if(n>=l&&n<=t)return"this_week";if(n>=a&&n<s)return"last_week";if(n.getFullYear()===t.getFullYear()&&n.getMonth()===t.getMonth())return"this_month";let i=n.getFullYear(),c=String(n.getMonth()+1).padStart(2,"0");return"older:".concat(i,"-").concat(c)}(r.occurred_at,e);t.has(n)||t.set(n,[]),t.get(n).push(r)}return Array.from(t.entries()).sort((e,t)=>{let[r]=e,[n]=t,o=sR.indexOf(r),l=sR.indexOf(n);return -1!==o&&-1!==l?o-l:-1!==o?-1:-1!==l||"unknown"===r?1:"unknown"===n?-1:r<n?1:r>n?-1:0})},[a]);return m&&0===a.length?(0,n.jsx)(aL,{label:"Loading activity…"}):g&&0===a.length?(0,n.jsx)(aT,{title:"Couldn't load activity",description:g}):0===a.length?(0,n.jsx)(aT,{title:"No activity yet",description:"Emails and meetings appear here once they're synced."}):(0,n.jsxs)("div",{className:"space-y-6",children:[N.map(e=>{let[t,o]=e;return(0,n.jsxs)("section",{children:[(0,n.jsx)("h3",{className:"sticky top-0 z-[1] mb-2 px-1 py-1 text-[11px] font-semibold uppercase tracking-[0.16em]",style:{color:"var(--color-text-muted)",background:"var(--color-background)"},children:function(e){switch(e){case"today":return"Today";case"yesterday":return"Yesterday";case"this_week":return"Earlier this week";case"last_week":return"Last week";case"this_month":return"Earlier this month";case"unknown":return"Unknown date";default:{let t=/^older:(\d{4})-(\d{2})$/.exec(e);if(!t)return e;let r=Number(t[1]),n=Number(t[2])-1;return new Intl.DateTimeFormat(void 0,{month:"long",year:"numeric"}).format(new Date(r,n,1))}}}(t)}),(0,n.jsx)("ul",{className:"space-y-2",children:o.map(e=>(0,n.jsx)(sF,{row:e,expanded:b===e.id,onToggle:()=>j(t=>t===e.id?null:e.id),onOpenPerson:r,onOpenCompany:l},e.id))})]},t)}),p&&(0,n.jsx)("div",{className:"flex justify-center pt-2",children:(0,n.jsx)(sS.$,{type:"button",variant:"outline",size:"sm",onClick:w,disabled:f,children:f?"Loading…":"Show more (".concat((i-a.length).toLocaleString()," remaining)")})}),g&&a.length>0&&(0,n.jsx)("p",{className:"text-center text-[12px]",style:{color:"var(--color-text-muted)"},children:g})]})}let sA={Sent:{label:"You",color:"#22c55e"},Received:{label:"Them",color:"#3b82f6"},Internal:{label:"Internal",color:"#94a3b8"}};function sF(e){var t,r,o,l;let{row:a,expanded:s,onToggle:i,onOpenPerson:c,onOpenCompany:d}=e,u=a.direction?sA[a.direction]:null,p=u?"".concat(u.color,"1a"):"var(--color-surface-hover)",h=u?u.color:"var(--color-text-muted)",m="Email"===a.type?(null==(r=a.email)||null==(t=r.subject)?void 0:t.trim())||"(no subject)":(null==(l=a.event)||null==(o=l.title)?void 0:o.trim())||"(no title)";return(0,n.jsxs)("li",{className:"rounded-xl border overflow-hidden",style:{borderColor:s?"var(--color-accent)":"var(--color-border)",background:"var(--color-surface)",transition:"border-color 120ms ease"},children:[(0,n.jsxs)("div",{role:"button",tabIndex:0,"aria-expanded":s,onClick:i,onKeyDown:e=>{e.target===e.currentTarget&&("Enter"===e.key||" "===e.key)&&(e.preventDefault(),i())},className:"grid w-full items-start gap-3 px-4 py-3 text-left cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] transition-colors",style:{gridTemplateColumns:"auto minmax(0, 1fr) auto"},onMouseEnter:e=>{s||(e.currentTarget.style.background="var(--color-surface-hover)")},onMouseLeave:e=>{s||(e.currentTarget.style.background="transparent")},children:[(0,n.jsx)("span",{className:"inline-flex h-7 w-7 items-center justify-center rounded-full shrink-0",style:{background:p,color:h},"aria-hidden":!0,children:"Email"===a.type?(0,n.jsx)(sW,{}):(0,n.jsx)(sO,{})}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-baseline gap-2 flex-wrap",children:[(0,n.jsx)("span",{className:"font-instrument truncate",style:{color:"var(--color-text)",fontSize:14,fontWeight:600},children:m}),u&&(0,n.jsx)("span",{className:"shrink-0 inline-flex items-center gap-1 rounded-full px-1.5 py-0 text-[10px] uppercase tracking-[0.06em]",style:{background:"".concat(u.color,"1f"),color:u.color,fontWeight:600},children:u.label})]}),(0,n.jsx)(sP,{row:a})]}),(0,n.jsx)("span",{className:"text-right text-[11px] tabular-nums shrink-0",style:{color:"var(--color-text-muted)"},title:a.occurred_at?aO(a.occurred_at):void 0,children:a.occurred_at&&aW(a.occurred_at)})]}),(0,n.jsx)("div",{className:"grid transition-[grid-template-rows] duration-[220ms] ease-out motion-reduce:transition-none",style:{gridTemplateRows:s?"1fr":"0fr"},children:(0,n.jsx)("div",{className:"overflow-hidden",children:s&&(0,n.jsx)(sB,{row:a,onOpenPerson:c,onOpenCompany:d})})})]})}function sP(e){let{row:t}=e;if("Email"===t.type&&t.email){var r,o,l,a;let e=(null==(o=t.email.from)||null==(r=o.name)?void 0:r.trim())||(null==(l=t.email.from)?void 0:l.email)||null,s=null==(a=t.email.snippet)?void 0:a.trim();return e||s?(0,n.jsxs)("p",{className:"mt-0.5 truncate text-[13px]",style:{color:"var(--color-text-muted)",fontFamily:'"Bookerly", Georgia, "Times New Roman", serif'},children:[e&&(0,n.jsx)("span",{style:{color:"var(--color-text)"},children:e}),e&&s&&(0,n.jsxs)("span",{children:[" — ",s]}),!e&&s]}):null}if("Meeting"===t.type&&t.event){let e=function(e,t){if(!e)return null;let r=new Date(e);if(Number.isNaN(r.getTime()))return null;let n=new Intl.DateTimeFormat(void 0,{hour:"numeric",minute:"2-digit"}).format(r);if(!t)return n;let o=new Date(t);if(Number.isNaN(o.getTime()))return n;let l=new Intl.DateTimeFormat(void 0,{hour:"numeric",minute:"2-digit"}).format(o);return"".concat(n," – ").concat(l)}(t.event.start_at,t.event.end_at),r=t.event.meeting_type;return e||r?(0,n.jsxs)("p",{className:"mt-0.5 text-[12px]",style:{color:"var(--color-text-muted)"},children:[e,e&&r&&" \xb7 ",r]}):null}return null}function sB(e){let{row:t,onOpenPerson:r,onOpenCompany:o}=e;if("Email"===t.type){var l,a,s,i,c;return(null==(l=t.email)?void 0:l.thread_id)?(0,n.jsx)("div",{className:"border-t px-4 py-4",style:{borderColor:"var(--color-border)",background:"var(--color-background)"},children:(0,n.jsx)(a6,{threadId:t.email.thread_id,recipientName:null!=(c=null!=(i=null==(a=t.email.from)?void 0:a.name)?i:null==(s=t.email.from)?void 0:s.email)?c:null,onOpenPerson:r,autoScrollOnLoad:!1,showReply:!1})}):(0,n.jsx)("div",{className:"border-t px-4 py-4 text-[12px]",style:{borderColor:"var(--color-border)",background:"var(--color-background)",color:"var(--color-text-muted)"},children:"The thread for this message is no longer available."})}return"Meeting"===t.type&&t.event?(0,n.jsx)(sa,{eventId:t.event.id,fallbackEvent:{id:t.event.id,title:t.event.title,start_at:t.event.start_at,end_at:t.event.end_at,meeting_type:t.event.meeting_type},onOpenPerson:r,onOpenCompany:o}):null}function sW(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[(0,n.jsx)("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),(0,n.jsx)("path",{d:"m3 7 9 6 9-6"})]})}function sO(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"17",rx:"2"}),(0,n.jsx)("path",{d:"M3 10h18"}),(0,n.jsx)("path",{d:"M8 2v4"}),(0,n.jsx)("path",{d:"M16 2v4"})]})}function sz(e){var t;let{name:r,saveName:l}=e,a=null!=(t=null==r?void 0:r.trim())?t:"",s=0===a.length,[i,c]=(0,o.useState)(!1),[d,u]=(0,o.useState)(""),[p,h]=(0,o.useState)(!1),[m,x]=(0,o.useState)(null),f=(0,o.useRef)(null),v=(0,o.useRef)(!1);(0,o.useEffect)(()=>{i&&f.current&&(f.current.focus(),f.current.select())},[i]);let g=(0,o.useCallback)(()=>{u(""),x(null),c(!0)},[]),y=(0,o.useCallback)(()=>{c(!1),u(""),x(null)},[]),b=(0,o.useCallback)(async()=>{if(v.current)return;let e=d.trim();if(!e)return void y();v.current=!0,h(!0),x(null);try{await l(e),c(!1),u("")}catch(e){x(e instanceof Error?e.message:"Failed to save name.")}finally{v.current=!1,h(!1)}},[d,y,l]);return i?(0,n.jsxs)("div",{className:"flex flex-1 items-center gap-3 min-w-0",children:[(0,n.jsx)("input",{ref:f,type:"text",value:d,onChange:e=>u(e.target.value),onBlur:()=>{b()},onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),b()):"Escape"===e.key&&(e.preventDefault(),y())},disabled:p,placeholder:"Add a name","aria-label":"Name",className:"font-instrument text-3xl tracking-tight w-full min-w-0",style:{color:"var(--color-text)",background:"transparent",border:"none",outline:"none",padding:0}}),m&&(0,n.jsx)("span",{className:"text-[12px] shrink-0",style:{color:"var(--color-error)"},role:"alert",children:m})]}):s?(0,n.jsxs)("button",{type:"button",onClick:g,title:"Add a name","aria-label":"Add a name",className:"font-instrument text-3xl tracking-tight inline-flex items-center gap-2 cursor-pointer hover:opacity-80 transition-opacity outline-none focus-visible:ring-2 rounded-sm",style:{color:"var(--color-text-muted)",background:"transparent",border:"none",padding:0},children:[(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"M12 20h9"}),(0,n.jsx)("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z"})]}),(0,n.jsx)("span",{style:{fontStyle:"italic"},children:"Add a name"})]}):(0,n.jsx)("h1",{className:"font-instrument text-3xl tracking-tight truncate",style:{color:"var(--color-text)"},children:a})}let sU=[{id:"overview",label:"Overview"},{id:"emails",label:"Emails",getCount:e=>e.threads.length},{id:"calendar",label:"Meetings",getCount:e=>e.events.length},{id:"activity",label:"Activity",getCount:e=>e.interactions_summary.total},{id:"notes",label:"Notes"}];function sH(e){let{personId:t,activeTab:r,onOpenPerson:l,onOpenCompany:a,onBackToList:s,onTabChange:i}=e,[c,d]=(0,o.useState)(null),[u,p]=(0,o.useState)(!0),[h,m]=(0,o.useState)(null),[x,f]=(0,o.useState)("overview"),[v,g]=(0,o.useState)(t);t!==v&&(g(t),f("overview"));let y="overview"===r||"emails"===r||"calendar"===r||"activity"===r||"notes"===r?r:x,b=(0,o.useCallback)(e=>{f(e),null==i||i(e)},[i]),j=(0,o.useCallback)(async()=>{p(!0),m(null);try{let r=await fetch("/api/crm/people/".concat(encodeURIComponent(t)),{cache:"no-store"});if(404===r.status){m("Person not found."),d(null);return}if(!r.ok){var e;let t=await r.json().catch(()=>({}));throw Error(null!=(e=t.error)?e:"HTTP ".concat(r.status))}let n=await r.json();d(n)}catch(e){m(e instanceof Error?e.message:"Failed to load person.")}finally{p(!1)}},[t]);(0,o.useEffect)(()=>{j()},[j]);let k=(0,o.useCallback)(async e=>{let r=await fetch("/api/workspace/objects/people/entries/".concat(encodeURIComponent(t)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:{"Full Name":e}})});if(!r.ok){var n;throw Error(null!=(n=(await r.json().catch(()=>({}))).error)?n:"HTTP ".concat(r.status))}d(t=>t?{...t,person:{...t.person,name:e}}:t)},[t]),w=(0,o.useCallback)(async e=>{let r=await fetch("/api/workspace/objects/people/entries/".concat(encodeURIComponent(t)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:{Notes:e}})});if(!r.ok){var n;throw Error(null!=(n=(await r.json().catch(()=>({}))).error)?n:"HTTP ".concat(r.status))}d(t=>t?{...t,person:{...t.person,notes:e,updated_at:new Date().toISOString()}}:t)},[t]);return u&&!c?(0,n.jsx)("div",{className:"flex h-full flex-col",style:{background:"var(--color-background)"},children:(0,n.jsx)(aL,{label:"Loading profile…"})}):h||!c?(0,n.jsx)("div",{className:"flex h-full flex-col",style:{background:"var(--color-background)"},children:(0,n.jsx)(aT,{title:"Couldn't load this contact",description:null!=h?h:"The record may have been deleted.",cta:s&&(0,n.jsx)(sS.$,{variant:"outline",size:"sm",onClick:s,children:"Back to People"})})}):(0,n.jsxs)("div",{className:"flex h-full min-h-0 flex-col",style:{background:"var(--color-background)"},children:[(0,n.jsx)(sV,{data:c,tab:y,onTabChange:b,onOpenCompany:a,onBackToList:s,onSaveName:k}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:(0,n.jsxs)("div",{className:"mx-auto w-full max-w-4xl px-6 py-6",children:["overview"===y&&(0,n.jsx)(sK,{data:c,onOpenCompany:a}),"emails"===y&&(0,n.jsx)(sJ,{data:c,onOpenPerson:l}),"calendar"===y&&(0,n.jsx)(sq,{data:c,onOpenPerson:l,onOpenCompany:a}),"activity"===y&&(0,n.jsx)(sG,{data:c,onOpenPerson:l,onOpenCompany:a}),"notes"===y&&(0,n.jsx)(s$,{data:c,onSave:w})]})})]})}function sV(e){var t,r,o;let{data:l,tab:a,onTabChange:s,onOpenCompany:i,onBackToList:c,onSaveName:d}=e,{person:u,company:p,derived_website:h}=l,m=(null==(t=u.name)?void 0:t.trim())||u.email||"Unknown contact",x=(null==p?void 0:p.website)||h;return(0,n.jsxs)("header",{className:"shrink-0 px-6 pt-4 pb-0",style:{borderBottom:"1px solid var(--color-border)",background:"var(--color-background)"},children:[(0,n.jsx)("div",{className:"mb-3 flex items-center gap-2 text-[12px]",style:{color:"var(--color-text-muted)"},children:c&&(0,n.jsxs)("button",{type:"button",onClick:c,className:"inline-flex items-center gap-1 hover:underline",children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:(0,n.jsx)("path",{d:"m15 18-6-6 6-6"})}),"People"]})}),(0,n.jsxs)("div",{className:"flex items-start gap-4",children:[(0,n.jsx)(a_,{src:u.avatar_url,name:m,seed:null!=(r=u.email)?r:u.id,size:"xl"}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-1",children:[(0,n.jsx)(sz,{name:u.name,saveName:d}),(0,n.jsx)(sT,{score:u.strength_score})]}),(0,n.jsxs)("div",{className:"mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[13px]",children:[u.email&&(0,n.jsx)("a",{href:"mailto:".concat(u.email),className:"hover:underline truncate",style:{color:"var(--color-text-muted)"},children:u.email}),p&&i&&(0,n.jsxs)("button",{type:"button",onClick:()=>i(p.id),className:"inline-flex items-center gap-1.5 hover:underline",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)(aE,{domain:p.domain,name:p.name,size:"sm"}),(0,n.jsx)("span",{children:null!=(o=p.name)?o:p.domain})]}),x&&(0,n.jsx)("a",{href:x,target:"_blank",rel:"noreferrer",className:"hover:underline",style:{color:"var(--color-text-muted)"},children:x.replace(/^https?:\/\//,"")})]}),(u.job_title||u.phone||u.linkedin_url)&&(0,n.jsxs)("div",{className:"mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[12px]",style:{color:"var(--color-text-muted)"},children:[u.job_title&&(0,n.jsx)("span",{children:u.job_title}),u.phone&&(0,n.jsx)("span",{children:u.phone}),u.linkedin_url&&(0,n.jsx)("a",{href:u.linkedin_url,target:"_blank",rel:"noreferrer",className:"hover:underline",children:"LinkedIn"})]})]}),(0,n.jsxs)("div",{className:"flex shrink-0 items-center gap-2",children:[u.email&&(0,n.jsx)("a",{href:"mailto:".concat(u.email),className:"inline-flex h-8 w-8 items-center justify-center rounded-lg",style:{background:"var(--color-surface)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},title:"Compose email",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),(0,n.jsx)("path",{d:"m3 7 9 6 9-6"})]})}),u.email&&(0,n.jsx)("a",{href:"https://mail.google.com/mail/u/0/#search/".concat(encodeURIComponent("from:"+u.email+" OR to:"+u.email)),target:"_blank",rel:"noreferrer",className:"inline-flex h-8 w-8 items-center justify-center rounded-lg",style:{background:"var(--color-surface)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},title:"Open in Gmail",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("path",{d:"M15 3h6v6"}),(0,n.jsx)("path",{d:"M10 14 21 3"}),(0,n.jsx)("path",{d:"M21 14v5a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5"})]})})]})]}),(0,n.jsx)("div",{className:"mt-5 flex items-center gap-4 -mb-px",children:sU.map(e=>{var t;let r=null==(t=e.getCount)?void 0:t.call(e,l),o=e.id===a;return(0,n.jsxs)("button",{type:"button",onClick:()=>s(e.id),className:"relative flex items-center gap-1.5 px-1 py-2 text-[13px] font-medium transition-colors",style:{color:o?"var(--color-text)":"var(--color-text-muted)",borderBottom:o?"2px solid var(--color-text)":"2px solid transparent"},children:[e.label,"number"==typeof r&&r>0&&(0,n.jsx)("span",{className:"rounded-full px-1.5 py-0 text-[10px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:r})]},e.id)})})]})}function sK(e){var t,r,o;let{data:l,onOpenCompany:a}=e,{person:s,company:i,interactions_summary:c}=l;return(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsxs)("section",{children:[(0,n.jsx)("h3",{className:"mb-3 text-[11px] font-semibold uppercase tracking-[0.16em]",style:{color:"var(--color-text-muted)"},children:"At a glance"}),(0,n.jsxs)("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[(0,n.jsx)(sY,{label:"Strength",value:s.strength_label}),(0,n.jsx)(sY,{label:"Last contact",value:s.last_interaction_at?aW(s.last_interaction_at):"—"}),(0,n.jsx)(sY,{label:"Emails",value:c.email_count.toLocaleString()}),(0,n.jsx)(sY,{label:"Meetings",value:c.meeting_count.toLocaleString()})]})]}),(0,n.jsxs)("section",{children:[(0,n.jsx)("h3",{className:"mb-3 text-[11px] font-semibold uppercase tracking-[0.16em]",style:{color:"var(--color-text-muted)"},children:"Contact"}),(0,n.jsxs)("div",{className:"space-y-2.5 rounded-2xl border p-4",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)(sZ,{label:"Email",value:s.email,link:s.email?"mailto:".concat(s.email):void 0}),(0,n.jsx)(sZ,{label:"Phone",value:s.phone,link:s.phone?"tel:".concat(s.phone):void 0}),(0,n.jsx)(sZ,{label:"LinkedIn",value:s.linkedin_url,link:null!=(t=s.linkedin_url)?t:void 0,external:!0}),(0,n.jsx)(sZ,{label:"Job title",value:s.job_title}),(0,n.jsx)(sZ,{label:"Status",value:s.status}),(0,n.jsx)(sZ,{label:"Source",value:s.source})]})]}),i&&(0,n.jsxs)("section",{children:[(0,n.jsx)("h3",{className:"mb-3 text-[11px] font-semibold uppercase tracking-[0.16em]",style:{color:"var(--color-text-muted)"},children:"Company"}),(0,n.jsxs)("button",{type:"button",onClick:()=>null==a?void 0:a(i.id),disabled:!a,className:"flex w-full items-center gap-3 rounded-2xl border p-4 text-left transition-colors disabled:cursor-default",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},onMouseEnter:e=>{a&&(e.currentTarget.style.borderColor="var(--color-accent)")},onMouseLeave:e=>{a&&(e.currentTarget.style.borderColor="var(--color-border)")},children:[(0,n.jsx)(aE,{domain:i.domain,name:i.name,size:"lg"}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("p",{className:"text-sm font-medium truncate",style:{color:"var(--color-text)"},children:null!=(o=null!=(r=i.name)?r:i.domain)?o:"Unknown company"}),(i.domain||i.industry)&&(0,n.jsx)("p",{className:"mt-0.5 text-[12px]",style:{color:"var(--color-text-muted)"},children:[i.domain,i.industry].filter(Boolean).join(" \xb7 ")})]}),(0,n.jsx)(sT,{score:i.strength_score})]})]})]})}function sJ(e){let{data:t,onOpenPerson:r}=e;return 0===t.threads.length?(0,n.jsx)(aT,{title:"No threads with this contact yet",description:"Threads appear here as soon as Gmail is connected and the next sync tick runs."}):(0,n.jsx)(sI,{threads:t.threads,onOpenPerson:r})}function sq(e){let{data:t,onOpenPerson:r,onOpenCompany:l}=e,[a,s]=(0,o.useState)(null);if(0===t.events.length)return(0,n.jsx)(aT,{title:"No meetings with this contact",description:"Once Calendar is connected and the next sync runs, meetings show up here."});let i=new Map;for(let e of t.events){let t=e.start_at?az(e.start_at):"Unknown date";i.has(t)||i.set(t,[]),i.get(t).push(e)}return(0,n.jsx)("div",{className:"space-y-6",children:Array.from(i.entries()).map(e=>{let[t,o]=e;return(0,n.jsxs)("section",{children:[(0,n.jsx)("h3",{className:"sticky top-0 z-10 mb-2 px-1 py-1 text-[11px] font-semibold uppercase tracking-[0.16em]",style:{color:"var(--color-text-muted)",background:"var(--color-background)"},children:t}),(0,n.jsx)("ul",{className:"space-y-2",children:o.map(e=>(0,n.jsx)(sl,{event:e,expanded:a===e.id,onToggle:()=>s(t=>t===e.id?null:e.id),onOpenPerson:r,onOpenCompany:l},e.id))})]},t)})})}function sG(e){let{data:t,onOpenPerson:r,onOpenCompany:o}=e,l=t.interactions_summary;return 0===l.total?(0,n.jsx)(aT,{title:"No activity yet",description:"Emails and meetings appear here once they're synced."}):(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsxs)("section",{className:"space-y-3",children:[(0,n.jsxs)("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[(0,n.jsx)(sY,{label:"Interactions",value:l.total.toLocaleString()}),(0,n.jsx)(sY,{label:"Emails",value:l.email_count.toLocaleString()}),(0,n.jsx)(sY,{label:"Meetings",value:l.meeting_count.toLocaleString()}),(0,n.jsx)(sY,{label:"Last reply",value:l.last_inbound_at?aW(l.last_inbound_at):"—"})]}),l.last_outbound_at&&(0,n.jsx)("div",{className:"rounded-2xl border px-4 py-3 text-[13px]",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:(0,n.jsxs)("p",{style:{color:"var(--color-text-muted)"},children:["You last reached out"," ",(0,n.jsx)("strong",{style:{color:"var(--color-text)"},children:aW(l.last_outbound_at)}),"."]})})]}),(0,n.jsxs)("section",{children:[(0,n.jsx)("h3",{className:"mb-3 text-[11px] font-semibold uppercase tracking-[0.16em]",style:{color:"var(--color-text-muted)"},children:"Timeline"}),(0,n.jsx)(sD,{personId:t.person.id,onOpenPerson:r,onOpenCompany:o})]})]})}function s$(e){var t,r,l;let{data:a,onSave:s}=e,i=null!=(r=a.person.notes)?r:"",c=a.person.updated_at,[d,u]=(0,o.useState)(i),[p,h]=(0,o.useState)(!1),[m,x]=(0,o.useState)(c),[f,v]=(0,o.useState)(null),g=(0,o.useRef)(null),y=(0,o.useRef)(i),b=(0,o.useRef)(!1);(0,o.useEffect)(()=>{i!==y.current&&(y.current=i,u(i)),x(c)},[i,c]);let j=(0,o.useCallback)(()=>{let e=g.current;e&&(e.style.height="auto",e.style.height="".concat(Math.max(e.scrollHeight,160),"px"))},[]);(0,o.useEffect)(()=>{j()},[d,j]);let k=(0,o.useCallback)(async e=>{if(!b.current&&e!==y.current){b.current=!0,h(!0),v(null);try{await s(e),y.current=e,x(new Date().toISOString())}catch(e){v(e instanceof Error?e.message:"Couldn't save note.")}finally{b.current=!1,h(!1)}}},[s]),[,w]=(0,o.useState)(0);(0,o.useEffect)(()=>{if(!m||p)return;let e=window.setInterval(()=>w(e=>e+1),3e4);return()=>window.clearInterval(e)},[m,p]);let N=null!=(l=null==(t=a.person.name)?void 0:t.trim().split(/\s+/)[0])?l:null,C=d!==y.current;return(0,n.jsxs)("section",{className:"space-y-2",children:[(0,n.jsx)("textarea",{ref:g,value:d,onChange:e=>u(e.target.value),onBlur:()=>{k(d)},onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key?(e.preventDefault(),k(d)):"Escape"===e.key&&(e.preventDefault(),u(y.current),v(null))},placeholder:N?"Write a note about ".concat(N,"…"):"Write a note…","aria-label":"Notes",className:"w-full resize-none rounded-2xl border px-4 py-3 text-[14px] leading-relaxed transition-shadow focus:outline-none focus:ring-2 focus:ring-(--color-accent)/30",style:{minHeight:160,color:"var(--color-text)",background:"var(--color-surface)",borderColor:"var(--color-border)",fontFamily:"inherit"}}),(0,n.jsx)("div",{className:"flex items-center justify-end gap-2 px-1 text-[11px]",style:{color:"var(--color-text-muted)"},children:f?(0,n.jsx)("button",{type:"button",onClick:()=>{k(d)},className:"hover:underline",style:{color:"var(--color-error)"},children:"Couldn't save — retry"}):p?(0,n.jsx)("span",{children:"Saving…"}):C?(0,n.jsx)("span",{style:{opacity:.7},children:"Unsaved changes"}):m?(0,n.jsxs)("span",{children:["Saved"," \xb7 ",aW(m)||"just now"]}):null})]})}function sY(e){let{label:t,value:r}=e;return(0,n.jsxs)("div",{className:"rounded-2xl border p-3",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)("dt",{className:"text-[10px] font-semibold uppercase tracking-[0.16em]",style:{color:"var(--color-text-muted)"},children:t}),(0,n.jsx)("dd",{className:"mt-1 text-[14px] font-medium",style:{color:"var(--color-text)"},children:r})]})}function sZ(e){let{label:t,value:r,link:o,external:l}=e;if(!r)return(0,n.jsxs)("div",{className:"flex items-baseline gap-3 text-[13px]",children:[(0,n.jsx)("dt",{className:"w-24 shrink-0",style:{color:"var(--color-text-muted)"},children:t}),(0,n.jsx)("dd",{style:{color:"var(--color-text-muted)"},children:"—"})]});let a=o?(0,n.jsx)("a",{href:o,target:l?"_blank":void 0,rel:l?"noreferrer":void 0,className:"hover:underline truncate",style:{color:"var(--color-text)"},children:r}):(0,n.jsx)("span",{className:"truncate",style:{color:"var(--color-text)"},children:r});return(0,n.jsxs)("div",{className:"flex items-baseline gap-3 text-[13px] min-w-0",children:[(0,n.jsx)("dt",{className:"w-24 shrink-0",style:{color:"var(--color-text-muted)"},children:t}),(0,n.jsx)("dd",{className:"min-w-0",children:a})]})}o.useMemo;let sQ=[{id:"overview",label:"Overview",count:()=>null},{id:"team",label:"Team",count:e=>e.summary.people_count},{id:"emails",label:"Emails",count:e=>e.summary.thread_count},{id:"meetings",label:"Meetings",count:e=>e.summary.event_count}];function sX(e){let{companyId:t,activeTab:r,onOpenPerson:l,onOpenCompany:a,onBackToList:s,onTabChange:i}=e,[c,d]=(0,o.useState)(null),[u,p]=(0,o.useState)(!0),[h,m]=(0,o.useState)(null),[x,f]=(0,o.useState)("overview"),[v,g]=(0,o.useState)(t);t!==v&&(g(t),f("overview"));let y="overview"===r||"team"===r||"emails"===r||"meetings"===r?r:x,b=(0,o.useCallback)(e=>{f(e),null==i||i(e)},[i]),j=(0,o.useCallback)(async()=>{p(!0),m(null);try{let r=await fetch("/api/crm/companies/".concat(encodeURIComponent(t)),{cache:"no-store"});if(404===r.status){m("Company not found."),d(null);return}if(!r.ok){var e;let t=await r.json().catch(()=>({}));throw Error(null!=(e=t.error)?e:"HTTP ".concat(r.status))}let n=await r.json();d(n)}catch(e){m(e instanceof Error?e.message:"Failed to load company.")}finally{p(!1)}},[t]);(0,o.useEffect)(()=>{j()},[j]);let k=(0,o.useCallback)(async e=>{let r=await fetch("/api/workspace/objects/company/entries/".concat(encodeURIComponent(t)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:{"Company Name":e}})});if(!r.ok){var n;throw Error(null!=(n=(await r.json().catch(()=>({}))).error)?n:"HTTP ".concat(r.status))}d(t=>t?{...t,company:{...t.company,name:e}}:t)},[t]);return u&&!c?(0,n.jsx)("div",{className:"flex h-full flex-col",style:{background:"var(--color-background)"},children:(0,n.jsx)(aL,{label:"Loading company…"})}):h||!c?(0,n.jsx)("div",{className:"flex h-full flex-col",style:{background:"var(--color-background)"},children:(0,n.jsx)(aT,{title:"Couldn't load this company",description:null!=h?h:"The record may have been deleted.",cta:s&&(0,n.jsx)(sS.$,{variant:"outline",size:"sm",onClick:s,children:"Back to Companies"})})}):(0,n.jsxs)("div",{className:"flex h-full min-h-0 flex-col",style:{background:"var(--color-background)"},children:[(0,n.jsx)(s0,{data:c,tab:y,onTabChange:b,onBackToList:s,onSaveName:k}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:(0,n.jsxs)("div",{className:"mx-auto w-full max-w-4xl px-6 py-6",children:["overview"===y&&(0,n.jsx)(s1,{data:c}),"team"===y&&(0,n.jsx)(s2,{data:c,onOpenPerson:l}),"emails"===y&&(0,n.jsx)(s4,{data:c,onOpenPerson:l}),"meetings"===y&&(0,n.jsx)(s5,{data:c,onOpenPerson:l,onOpenCompany:a})]})})]})}function s0(e){let{data:t,tab:r,onTabChange:o,onBackToList:l,onSaveName:a}=e,{company:s}=t;return(0,n.jsxs)("header",{className:"shrink-0 px-6 pt-4 pb-0",style:{borderBottom:"1px solid var(--color-border)",background:"var(--color-background)"},children:[(0,n.jsx)("div",{className:"mb-3 flex items-center gap-2 text-[12px]",style:{color:"var(--color-text-muted)"},children:l&&(0,n.jsxs)("button",{type:"button",onClick:l,className:"inline-flex items-center gap-1 hover:underline",children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:(0,n.jsx)("path",{d:"m15 18-6-6 6-6"})}),"Companies"]})}),(0,n.jsxs)("div",{className:"flex items-start gap-4",children:[(0,n.jsx)(aE,{domain:s.domain,name:s.name,size:"xl"}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-1",children:[(0,n.jsx)(sz,{name:s.name,saveName:a}),(0,n.jsx)(sT,{score:s.strength_score})]}),(0,n.jsxs)("div",{className:"mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[13px]",style:{color:"var(--color-text-muted)"},children:[s.website&&(0,n.jsx)("a",{href:s.website,target:"_blank",rel:"noreferrer",className:"hover:underline",children:s.website.replace(/^https?:\/\//,"")}),s.industry&&(0,n.jsx)("span",{children:s.industry}),s.type&&(0,n.jsx)("span",{children:s.type})]})]})]}),(0,n.jsx)("div",{className:"mt-5 flex items-center gap-4 -mb-px",children:sQ.map(e=>{let l=e.count(t),a=e.id===r;return(0,n.jsxs)("button",{type:"button",onClick:()=>o(e.id),className:"relative flex items-center gap-1.5 px-1 py-2 text-[13px] font-medium transition-colors",style:{color:a?"var(--color-text)":"var(--color-text-muted)",borderBottom:a?"2px solid var(--color-text)":"2px solid transparent"},children:[e.label,"number"==typeof l&&l>0&&(0,n.jsx)("span",{className:"rounded-full px-1.5 py-0 text-[10px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:l})]},e.id)})})]})}function s1(e){var t;let{data:r}=e,{company:o,summary:l}=r;return(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsxs)("section",{children:[(0,n.jsx)("h3",{className:"mb-3 text-[11px] font-semibold uppercase tracking-[0.16em]",style:{color:"var(--color-text-muted)"},children:"At a glance"}),(0,n.jsxs)("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[(0,n.jsx)(s3,{label:"People",value:l.people_count.toLocaleString()}),(0,n.jsx)(s3,{label:"Threads",value:l.thread_count.toLocaleString()}),(0,n.jsx)(s3,{label:"Meetings",value:l.event_count.toLocaleString()}),(0,n.jsx)(s3,{label:"Strength",value:o.strength_label})]})]}),(0,n.jsxs)("section",{children:[(0,n.jsx)("h3",{className:"mb-3 text-[11px] font-semibold uppercase tracking-[0.16em]",style:{color:"var(--color-text-muted)"},children:"Details"}),(0,n.jsxs)("div",{className:"space-y-2.5 rounded-2xl border p-4",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)(s6,{label:"Domain",value:o.domain}),(0,n.jsx)(s6,{label:"Website",value:o.website?o.website.replace(/^https?:\/\//,""):null,link:null!=(t=o.website)?t:void 0,external:!0}),(0,n.jsx)(s6,{label:"Industry",value:o.industry}),(0,n.jsx)(s6,{label:"Type",value:o.type}),(0,n.jsx)(s6,{label:"Source",value:o.source}),(0,n.jsx)(s6,{label:"Last contact",value:o.last_interaction_at?aW(o.last_interaction_at):null})]})]}),l.strongest_contact&&(0,n.jsxs)("p",{className:"text-[12px]",style:{color:"var(--color-text-muted)"},children:["Strongest contact: ",(0,n.jsx)("strong",{style:{color:"var(--color-text)"},children:l.strongest_contact})]})]})}function s2(e){let{data:t,onOpenPerson:r}=e;return 0===t.people.length?(0,n.jsx)(aT,{title:"No people at this company yet"}):(0,n.jsx)("ul",{className:"divide-y",style:{borderTop:"1px solid var(--color-border)",borderBottom:"1px solid var(--color-border)"},children:t.people.map(e=>{var t,o;let l=(null==(t=e.name)?void 0:t.trim())||e.email||"Unknown";return(0,n.jsx)("li",{children:(0,n.jsxs)("button",{type:"button",onClick:()=>null==r?void 0:r(e.id),disabled:!r,className:"flex w-full items-center gap-3 px-4 py-3 text-left hover:bg-[var(--color-surface-hover)] disabled:cursor-default",children:[(0,n.jsx)(a_,{src:e.avatar_url,name:l,seed:null!=(o=e.email)?o:e.id,size:"md"}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("p",{className:"truncate text-[14px] font-medium",style:{color:"var(--color-text)"},children:l}),(0,n.jsx)("p",{className:"mt-0.5 truncate text-[12px]",style:{color:"var(--color-text-muted)"},children:[e.job_title,e.email].filter(Boolean).join(" \xb7 ")})]}),(0,n.jsx)(sT,{score:e.strength_score,size:"sm",showLabel:!1}),(0,n.jsx)("span",{className:"text-right text-[11px] shrink-0 w-16",style:{color:"var(--color-text-muted)"},children:e.last_interaction_at?aW(e.last_interaction_at):""})]})},e.id)})})}function s4(e){let{data:t,onOpenPerson:r}=e;return 0===t.threads.length?(0,n.jsx)(aT,{title:"No threads yet"}):(0,n.jsx)(sI,{threads:t.threads,onOpenPerson:r})}function s5(e){let{data:t,onOpenPerson:r,onOpenCompany:l}=e,[a,s]=(0,o.useState)(null);if(0===t.events.length)return(0,n.jsx)(aT,{title:"No meetings with this company yet"});let i=new Map;for(let e of t.events){let t=e.start_at?az(e.start_at):"Unknown date";i.has(t)||i.set(t,[]),i.get(t).push(e)}return(0,n.jsx)("div",{className:"space-y-6",children:Array.from(i.entries()).map(e=>{let[t,o]=e;return(0,n.jsxs)("section",{children:[(0,n.jsx)("h3",{className:"sticky top-0 z-10 mb-2 px-1 py-1 text-[11px] font-semibold uppercase tracking-[0.16em]",style:{color:"var(--color-text-muted)",background:"var(--color-background)"},children:t}),(0,n.jsx)("ul",{className:"space-y-2",children:o.map(e=>(0,n.jsx)(sl,{event:e,expanded:a===e.id,onToggle:()=>s(t=>t===e.id?null:e.id),onOpenPerson:r,onOpenCompany:l},e.id))})]},t)})})}function s3(e){let{label:t,value:r}=e;return(0,n.jsxs)("div",{className:"rounded-2xl border p-3",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)("dt",{className:"text-[10px] font-semibold uppercase tracking-[0.16em]",style:{color:"var(--color-text-muted)"},children:t}),(0,n.jsx)("dd",{className:"mt-1 text-[14px] font-medium",style:{color:"var(--color-text)"},children:r})]})}function s6(e){let{label:t,value:r,link:o,external:l}=e;if(!r)return(0,n.jsxs)("div",{className:"flex items-baseline gap-3 text-[13px]",children:[(0,n.jsx)("dt",{className:"w-24 shrink-0",style:{color:"var(--color-text-muted)"},children:t}),(0,n.jsx)("dd",{style:{color:"var(--color-text-muted)"},children:"—"})]});let a=o?(0,n.jsx)("a",{href:o,target:l?"_blank":void 0,rel:l?"noreferrer":void 0,className:"hover:underline truncate",style:{color:"var(--color-text)"},children:r}):(0,n.jsx)("span",{className:"truncate",style:{color:"var(--color-text)"},children:r});return(0,n.jsxs)("div",{className:"flex items-baseline gap-3 text-[13px] min-w-0",children:[(0,n.jsx)("dt",{className:"w-24 shrink-0",style:{color:"var(--color-text-muted)"},children:t}),(0,n.jsx)("dd",{className:"min-w-0",children:a})]})}var s8=r(77592),s7=r(70793),s9=r(1061),ie=r(52973),it=r(80148),ir=r(64518),io=r(81199),il=r(50045),ia=r(47186),is=r(39128),ii=r(18520),ic=r(80096),id=r(54113),iu=r(72092);let ip=[{id:"hubspot-sync-contacts",label:"Sync HubSpot Contacts",subtitle:"Import & deduplicate CRM contacts",icon:s9.mM8,iconType:"brand",brandColor:"#FF7A59",category:"crm-sales",prompt:"Connect to my HubSpot CRM and pull all contacts updated this week. Deduplicate them by email and list any with missing phone numbers or job titles so I can clean up the data."},{id:"salesforce-pipeline",label:"Salesforce Pipeline",subtitle:"Analyze deal stages & revenue",icon:s9.wsd,iconType:"brand",brandColor:"#00A1E0",category:"crm-sales",prompt:"Connect to Salesforce and pull my current sales pipeline. Break down deals by stage, show total expected revenue per stage, and flag any deals that have been stuck in the same stage for more than 14 days."},{id:"apollo-enrich-lead",label:"Enrich Lead via Apollo",subtitle:"Find LinkedIn, company data & funding",icon:ie.default,iconType:"generic",category:"crm-sales",prompt:"I just added a new lead — use Apollo enrichment to find their LinkedIn profile, current company, job title, company size, funding stage, and any recent news. Update the contact record with everything you find."},{id:"hubspot-deal-update",label:"Update HubSpot Deals",subtitle:"Bulk update deal properties",icon:s9.mM8,iconType:"brand",brandColor:"#FF7A59",category:"crm-sales",prompt:"Find all HubSpot deals in 'Negotiation' stage that haven't been touched in 7+ days. Move them to 'Needs Follow-up' and add a note saying 'Auto-flagged: no activity for 7 days'."},{id:"salesforce-lead-score",label:"Score Salesforce Leads",subtitle:"Rank leads by engagement signals",icon:s9.wsd,iconType:"brand",brandColor:"#00A1E0",category:"crm-sales",prompt:"Pull all Salesforce leads from this month. Score them based on email opens, meeting attendance, and form submissions. Give me a ranked list of the top 20 hottest leads with their scores and recommended next actions."},{id:"apollo-company-research",label:"Research Company",subtitle:"Apollo + web research on a prospect",icon:it.default,iconType:"generic",category:"crm-sales",prompt:"Research this prospect's company using Apollo enrichment and Exa web search. I need: company size, revenue, tech stack, recent news, key decision-makers, and any mutual connections. Compile everything into a one-page briefing."},{id:"intercom-tickets",label:"Intercom Ticket Summary",subtitle:"Summarize open support tickets",icon:s9.ezH,iconType:"brand",brandColor:"#6AFDEF",category:"crm-sales",prompt:"Pull all open Intercom conversations from this week. Categorize them by issue type (bug, feature request, billing, onboarding) and summarize the top 5 most urgent ones with recommended responses."},{id:"zendesk-trends",label:"Zendesk Support Trends",subtitle:"Analyze ticket patterns",icon:s9.x5_,iconType:"brand",brandColor:"#03363D",category:"crm-sales",prompt:"Analyze my Zendesk tickets from the past 30 days. What are the most common issues? Show a breakdown by category, average resolution time, and flag any recurring problems that might need a product fix."},{id:"crm-weekly-report",label:"CRM Weekly Report",subtitle:"Pipeline + activity summary",icon:ir.default,iconType:"generic",category:"crm-sales",prompt:"Generate a weekly CRM report: new leads added, deals moved forward, deals closed (won/lost), total pipeline value, and team activity metrics. Format it as a clean summary I can share with leadership."},{id:"gmail-follow-up",label:"Gmail Follow-ups",subtitle:"Draft replies to unanswered threads",icon:s9.nP5,iconType:"brand",brandColor:"#EA4335",category:"email-comms",prompt:"Check my Gmail for threads where I was the last sender and haven't gotten a reply in 3+ days. Draft a friendly follow-up for each one, keeping the original context. Show me all drafts before sending."},{id:"slack-standup",label:"Slack Standup Summary",subtitle:"Digest #standup channel updates",icon:s9.D6W,iconType:"brand",brandColor:"#4A154B",category:"email-comms",prompt:"Read today's messages in #standup on Slack. Summarize what each team member is working on, any blockers they mentioned, and highlight anything that needs my attention or a response."},{id:"discord-moderation",label:"Discord Community Digest",subtitle:"Summarize server activity",icon:s9.Nxe,iconType:"brand",brandColor:"#5865F2",category:"email-comms",prompt:"Pull the last 24 hours of messages from my Discord server's #general and #support channels. Summarize the key discussions, flag any unanswered questions, and list new member introductions."},{id:"gmail-newsletter-cleanup",label:"Clean Up Gmail",subtitle:"Unsubscribe from noisy newsletters",icon:s9.nP5,iconType:"brand",brandColor:"#EA4335",category:"email-comms",prompt:"Scan my Gmail inbox for newsletter and promotional emails I haven't opened in the last 30 days. List them with their sender and frequency, then help me draft unsubscribe actions for the ones I don't need."},{id:"slack-channel-summary",label:"Slack Channel Recap",subtitle:"Catch up on missed conversations",icon:s9.D6W,iconType:"brand",brandColor:"#4A154B",category:"email-comms",prompt:"I've been away for 2 days. Summarize the important messages and decisions from my top Slack channels (#engineering, #sales, #general). Highlight anything that needs my input and any @mentions I missed."},{id:"phone-call-summary",label:"Call Summary",subtitle:"Recap client phone calls",icon:io.default,iconType:"generic",category:"email-comms",prompt:"I just finished a client call. Help me write a structured summary: key discussion points, decisions made, action items for each party, and next meeting date. Format it so I can paste it directly into the CRM notes."},{id:"twilio-sms-campaign",label:"SMS Campaign via Twilio",subtitle:"Draft & schedule text messages",icon:s9.vzR,iconType:"brand",brandColor:"#F22F46",category:"email-comms",prompt:"I need to send a promotional SMS to my customer list via Twilio. Draft a short, compelling message (under 160 chars) about our new feature launch, with a link to the landing page. Set it up to send tomorrow at 10am."},{id:"github-pr-review",label:"Review GitHub PRs",subtitle:"Summarize open pull requests",icon:s9.SrF,iconType:"brand",brandColor:"#181717",category:"dev-tools",prompt:"List all open pull requests on my GitHub repo. For each one, summarize the changes, check if CI passed, note how long it's been open, and flag any that have merge conflicts or are missing reviews."},{id:"linear-sprint-status",label:"Linear Sprint Status",subtitle:"Track current sprint progress",icon:s9.iU0,iconType:"brand",brandColor:"#5E6AD2",category:"dev-tools",prompt:"Pull the current sprint from Linear. Show me: total issues, completed vs in-progress vs blocked, who's overloaded, and which issues are at risk of not being completed by sprint end. Suggest priorities."},{id:"jira-backlog-groom",label:"Groom Jira Backlog",subtitle:"Prioritize & clean up stale tickets",icon:s9.$lo,iconType:"brand",brandColor:"#0052CC",category:"dev-tools",prompt:"Review my Jira backlog. Find tickets older than 90 days with no activity, duplicates, and vague tickets missing acceptance criteria. Suggest which to close, merge, or update with better descriptions."},{id:"github-issue-triage",label:"Triage GitHub Issues",subtitle:"Categorize & label new issues",icon:s9.SrF,iconType:"brand",brandColor:"#181717",category:"dev-tools",prompt:"Go through unlabeled GitHub issues in my repo from this week. Read each one, categorize it (bug, feature, question, docs), suggest appropriate labels and priority, and draft a short acknowledgment comment for each."},{id:"linear-create-issues",label:"Create Linear Issues",subtitle:"Turn meeting notes into tasks",icon:s9.iU0,iconType:"brand",brandColor:"#5E6AD2",category:"dev-tools",prompt:"I have meeting notes in my workspace with action items. Parse them and create Linear issues for each action item. Set appropriate priorities, assign to team members mentioned, and add them to the current sprint."},{id:"github-release-notes",label:"GitHub Release Notes",subtitle:"Auto-generate changelog from PRs",icon:s9.SrF,iconType:"brand",brandColor:"#181717",category:"dev-tools",prompt:"Generate release notes for my GitHub repo based on all merged PRs since the last release tag. Categorize changes into Features, Bug Fixes, and Improvements. Format as a clean Markdown changelog ready to publish."},{id:"notion-meeting-notes",label:"Notion Meeting Notes",subtitle:"Create structured meeting page",icon:s9.i4$,iconType:"brand",brandColor:"#000000",category:"productivity",prompt:"Create a new page in my Notion workspace for today's team meeting. Include sections for Attendees, Agenda, Discussion Notes, Action Items, and Decisions. Pre-fill the agenda from my calendar event details."},{id:"gcal-schedule-optimizer",label:"Optimize My Calendar",subtitle:"Find focus time & reduce conflicts",icon:s9._eB,iconType:"brand",brandColor:"#4285F4",category:"productivity",prompt:"Analyze my Google Calendar for this week. Identify back-to-back meetings without breaks, suggest which meetings could be shorter or async, and find 2-hour blocks I can protect as focus time for deep work."},{id:"asana-project-plan",label:"Asana Project Plan",subtitle:"Break down a project into tasks",icon:s9.lic,iconType:"brand",brandColor:"#F06A6A",category:"productivity",prompt:"I'm starting a new product launch. Create an Asana project with milestones for: market research, design, development, testing, marketing prep, and launch day. Add subtasks under each milestone with estimated durations."},{id:"airtable-tracker",label:"Airtable Content Tracker",subtitle:"Build a content pipeline base",icon:s9.J2O,iconType:"brand",brandColor:"#18BFFF",category:"productivity",prompt:"Create an Airtable base for tracking our content marketing pipeline. I need columns for: Title, Type (blog/video/social), Status (idea/draft/review/published), Author, Due Date, Target Audience, and Performance Metrics."},{id:"notion-weekly-planning",label:"Notion Weekly Plan",subtitle:"Structure your week ahead",icon:s9.i4$,iconType:"brand",brandColor:"#000000",category:"productivity",prompt:"Create a weekly planning page in Notion for next week. Pull my upcoming calendar events, pending tasks from my project boards, and any deadlines. Organize them by day with priority levels and estimated time needed."},{id:"google-sheets-dashboard",label:"Sheets KPI Dashboard",subtitle:"Build a metrics tracking sheet",icon:s9.CZR,iconType:"brand",brandColor:"#34A853",category:"productivity",prompt:"Create a Google Sheets dashboard to track our key business metrics: MRR, churn rate, new signups, active users, NPS score, and support ticket volume. Include formulas for month-over-month changes and visual sparklines."},{id:"trello-kanban",label:"Trello Board Setup",subtitle:"Design a workflow board",icon:s9.N3N,iconType:"brand",brandColor:"#0052CC",category:"productivity",prompt:"Set up a Trello board for our hiring pipeline. Create lists for: Applications Received, Phone Screen, Technical Interview, Culture Fit, Offer Sent, and Hired. Add card templates with checklists for each stage."},{id:"gcal-meeting-prep",label:"Calendar Meeting Prep",subtitle:"Brief me before each meeting",icon:s9._eB,iconType:"brand",brandColor:"#4285F4",category:"productivity",prompt:"Check my Google Calendar for tomorrow's meetings. For each one, pull the attendee list, find relevant context (recent emails, CRM notes, past meeting notes), and create a quick briefing with talking points I should prepare."},{id:"figma-handoff",label:"Figma Design Handoff",subtitle:"Extract specs from designs",icon:s9.lNO,iconType:"brand",brandColor:"#F24E1E",category:"productivity",prompt:"I have a new Figma design ready for development. Extract all the key specs: colors, typography, spacing, component hierarchy, and interaction notes. Format them as a developer handoff document with clear implementation guidance."},{id:"zoom-meeting-summary",label:"Zoom Call Summary",subtitle:"Summarize recorded calls",icon:s9.gkj,iconType:"brand",brandColor:"#0B5CFF",category:"productivity",prompt:"I have a Zoom recording transcript from my latest client call. Summarize the key discussion points, extract action items with assigned owners, and highlight any concerns or risks the client raised that we need to address."},{id:"dropbox-organize",label:"Organize Dropbox",subtitle:"Clean up shared folders",icon:s9.z3D,iconType:"brand",brandColor:"#0061FF",category:"productivity",prompt:"Scan my Dropbox workspace for duplicate files, outdated documents, and files with no clear folder. Suggest a cleaner folder structure and help me reorganize by project and document type."},{id:"gdrive-doc-summary",label:"Summarize Google Docs",subtitle:"Digest long documents",icon:s9.unz,iconType:"brand",brandColor:"#4285F4",category:"productivity",prompt:"I have several long Google Docs from last quarter's planning sessions. Read through them and create a single executive summary covering: key decisions made, goals set, assigned responsibilities, and current status of each initiative."},{id:"exa-competitor-research",label:"Research Competitors",subtitle:"Deep web search via Exa",icon:il.default,iconType:"generic",category:"search-research",prompt:"Use Exa to research my top 5 competitors. For each, find: pricing page, recent blog posts, product updates in the last 3 months, customer reviews, and social media presence. Compile into a comparison matrix."},{id:"exa-industry-trends",label:"Industry Trend Report",subtitle:"Search for latest trends & insights",icon:ia.default,iconType:"generic",category:"search-research",prompt:"Use Exa web search to find the latest trends in my industry from the past month. Look for analyst reports, notable funding rounds, product launches, and thought leadership articles. Create a trends briefing I can share with the team."},{id:"exa-prospect-intel",label:"Prospect Intelligence",subtitle:"Research a prospect before outreach",icon:il.default,iconType:"generic",category:"search-research",prompt:"I'm about to reach out to a prospect. Use Exa to research their company: recent news, tech blog posts, job openings (to infer priorities), and any public talks by their team. Help me craft a personalized outreach message based on what you find."},{id:"web-market-analysis",label:"Market Analysis",subtitle:"Research market size & opportunities",icon:is.default,iconType:"generic",category:"search-research",prompt:"Research the market opportunity for our product category. Find total addressable market size, growth rate, key players and their market share, emerging trends, and any analyst predictions for the next 2-3 years."},{id:"exa-content-ideas",label:"Content Research",subtitle:"Find trending topics for content",icon:ia.default,iconType:"generic",category:"search-research",prompt:"Search the web for the most popular and trending content in my industry from the last 2 weeks. Find top-performing blog posts, viral social threads, and trending discussions. Suggest 10 content ideas based on the gaps you see."},{id:"auto-lead-nurture",label:"Lead Nurture Workflow",subtitle:"Auto-follow-up new signups",icon:ii.default,iconType:"generic",category:"automation",prompt:"Design an automated lead nurture workflow: when a new user signs up, send a welcome email via Gmail, wait 3 days, check if they've logged in — if not, send a helpful onboarding tip. If still inactive after 7 days, alert the sales team on Slack."},{id:"auto-invoice-tracking",label:"Invoice Automation",subtitle:"Track & remind overdue payments",icon:s9.kDV,iconType:"brand",brandColor:"#635BFF",category:"automation",prompt:"Set up a workflow that checks Stripe for invoices overdue by more than 5 days. For each one, draft a friendly reminder email, send it via Gmail, and post a summary in the #finance Slack channel. Run this check every morning at 9am."},{id:"auto-onboarding",label:"Client Onboarding Flow",subtitle:"Automate new client setup",icon:ic.default,iconType:"generic",category:"automation",prompt:"Build an automated client onboarding workflow: create a Notion project page, set up a Slack channel, add a HubSpot deal, schedule a kickoff meeting via Google Calendar, and send a welcome email with next steps. Trigger it when a deal is marked 'Closed Won'."},{id:"auto-daily-digest",label:"Daily Briefing Bot",subtitle:"Morning summary across all tools",icon:id.default,iconType:"generic",category:"automation",prompt:"Create a daily briefing cron job that runs at 8:30am: pull today's calendar events, unread email count, open support tickets, any blocked tasks from Linear, and yesterday's revenue from Stripe. Compile into a clean summary and post to #daily-digest on Slack."},{id:"auto-github-slack",label:"GitHub → Slack Alerts",subtitle:"Notify team of PR & issue activity",icon:s9.SrF,iconType:"brand",brandColor:"#181717",category:"automation",prompt:"Set up a workflow that watches my GitHub repo. When a new PR is opened, post a summary in #engineering on Slack with the author, description, and a review link. When CI fails, alert the PR author directly via DM."},{id:"auto-deal-alert",label:"Deal Stage Alerts",subtitle:"Notify sales on CRM changes",icon:s9.mM8,iconType:"brand",brandColor:"#FF7A59",category:"automation",prompt:"Create an automation that watches HubSpot deal stage changes. When a deal moves to 'Demo Scheduled', send the AE a prep email with the prospect's enrichment data. When it moves to 'Closed Won', post a celebration message in #wins on Slack."},{id:"auto-shopify-support",label:"Shopify Order Alerts",subtitle:"Auto-handle order issues",icon:s9.jHc,iconType:"brand",brandColor:"#96BF48",category:"automation",prompt:"Set up a workflow for my Shopify store: when an order is flagged as high-risk, automatically hold it, create a Zendesk ticket for review, and notify the team on Slack. When an order is refunded, update the customer record in HubSpot."},{id:"auto-content-pipeline",label:"Content Pipeline Bot",subtitle:"Auto-assign & remind writers",icon:s9.i4$,iconType:"brand",brandColor:"#000000",category:"automation",prompt:"Build a workflow that checks my Notion content calendar every Monday. For any pieces due this week that are still in 'Idea' status, assign them to available writers, send them a Slack message with the brief, and set a reminder for Wednesday if the draft isn't started."},{id:"auto-expense-report",label:"Auto Expense Report",subtitle:"Compile weekly expenses",icon:iu.default,iconType:"generic",category:"automation",prompt:"Create a weekly automation that pulls transaction data from Stripe, categorizes expenses (software, marketing, operations), calculates totals, and generates a formatted expense report in Google Sheets. Email the report to the finance team every Friday at 5pm."},{id:"auto-meeting-followup",label:"Auto Meeting Follow-up",subtitle:"Send notes after every meeting",icon:s9._eB,iconType:"brand",brandColor:"#4285F4",category:"automation",prompt:"After each meeting on my Google Calendar, automatically compile the notes (from Notion or the calendar description), extract action items, and send a follow-up email to all attendees via Gmail with the summary and their assigned tasks."}];function ih(e){let{suggestion:t,onClick:r}=e,o=t.icon,l="brand"===t.iconType;return(0,n.jsxs)("button",{type:"button",onClick:()=>r(t.prompt),className:"group flex items-center gap-1.5 px-3 md:px-3.5 py-1.5 md:py-2 text-[11px] md:text-xs font-medium whitespace-nowrap rounded-xl transition-all duration-200 border shrink-0",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",color:"var(--color-text-secondary)"},children:[(0,n.jsx)("div",{className:"flex-shrink-0 transition-all duration-200 ".concat(l?"grayscale opacity-50 group-hover:grayscale-0 group-hover:opacity-100":"opacity-45 group-hover:opacity-100"),children:l?(0,n.jsx)(o,{className:"w-3.5 h-3.5",style:{color:t.brandColor}}):(0,n.jsx)(o,{className:"w-3.5 h-3.5"})}),t.label]})}function im(e){let{compact:t,onPromptClick:r}=e,[l]=(0,o.useState)(0),a=(0,o.useMemo)(()=>(function(e){let t=[...e];for(let e=t.length-1;e>0;e--){let r=Math.floor(Math.random()*(e+1));[t[e],t[r]]=[t[r],t[e]]}return t})(ip).slice(0,6),[l]),s=a.slice(0,3),i=a.slice(3);return(0,n.jsxs)("div",{className:"mt-4 md:mt-6 flex flex-col gap-2 md:gap-2.5 w-full max-w-[720px] mx-auto ".concat(t?"px-2":"px-4"),children:[(0,n.jsx)("div",{className:"flex items-center justify-center gap-2 flex-wrap",children:s.map(e=>(0,n.jsx)(ih,{suggestion:e,onClick:r},e.id))}),(0,n.jsx)("div",{className:"flex items-center justify-center gap-2 flex-wrap",children:i.map(e=>(0,n.jsx)(ih,{suggestion:e,onClick:r},e.id))})]})}let ix={x:"x",twitter:"x",googlecalendar:"google-calendar","google-calendar":"google-calendar",googlesheets:"google-sheets","google-sheets":"google-sheets",googledrive:"google-drive","google-drive":"google-drive",googledocs:"google-docs","google-docs":"google-docs"},iv={x:["twitter","x"],"google-calendar":["google calendar","googlecalendar","google-calendar"],"google-sheets":["google sheets","googlesheets","google-sheets"],"google-drive":["google drive","googledrive","google-drive"],"google-docs":["google docs","googledocs","google-docs"]},ig={x:"twitter","google-calendar":"googlecalendar","google-sheets":"googlesheets","google-drive":"googledrive","google-docs":"googledocs"};function iy(e){var t;let r=e.trim().toLowerCase();return null!=(t=ix[r])?t:r}function ib(e,t){let r=iy(t);return"x"===r?"X":"string"==typeof e&&e.trim().length>0?e.trim():r}function ij(e){return Array.isArray(e)?e.filter(e=>"string"==typeof e&&e.trim().length>0):[]}function ik(e){return"string"==typeof e&&e.trim()?e.trim():void 0}function iw(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];for(let e of t){let t=ik(e);if(t)return t}}function iN(e){var t,r,n,o,l;let a=(l=e.meta)&&"object"==typeof l&&!Array.isArray(l)?l:void 0,s=null!=(t=iw(e.slug,e.name))?t:"unknown",i=iy(s),c="number"==typeof(null==a?void 0:a.tools_count)?a.tools_count:void 0,d="number"==typeof e.tools_count?e.tools_count:"number"==typeof e.toolsCount?e.toolsCount:null!=c?c:0,u=ij(e.categories),p=ij(null==a?void 0:a.categories),h=u.length>0?u:p;return{slug:i,connect_slug:s,name:ib(iw(e.name,e.slug),s),description:null!=(r=iw(e.description,e.description_short,e.summary,ik(null==a?void 0:a.description)))?r:"",logo:null!=(n=iw(e.logo,e.logo_url,e.icon,e.image,ik(null==a?void 0:a.logo)))?n:null,categories:h,auth_schemes:ij(null!=(o=e.auth_schemes)?o:e.authSchemes),tools_count:d}}function iC(e){var t,r,n,o,l;let a=(null!=(r=e.items)?r:[]).map(iN),s=(null==(t=e.categories)?void 0:t.length)?e.categories:Array.from(new Set(a.flatMap(e=>e.categories)));return{items:a,categories:s,cursor:null!=(l=null!=(o=null!=(n=e.cursor)?n:e.next_cursor)?o:e.nextCursor)?l:null,total:"number"==typeof e.total?e.total:"number"==typeof e.total_items?e.total_items:a.length}}function iS(e){var t,r;return((null==(t=e.connections)?void 0:t.length)?e.connections:null!=(r=e.items)?r:[]).map(iM)}function iM(e){var t,r,n,o,l,a,s,i,c,d,u,p,h,m,x,f,v,g,y,b;let j=null!=(p=iw(e.id,e.connectionId))?p:"unknown-connection",k=null!=(h=iw(e.toolkit_slug,null==(t=e.toolkit)?void 0:t.slug))?h:"unknown",w=iy(k),N=iw(e.toolkit_name,null==(r=e.toolkit)?void 0:r.name,k),C=iw(e.account_label,null==(n=e.account)?void 0:n.label),S=iw(e.account_name,null==(o=e.account)?void 0:o.label,C),M=iw(e.account_email,null==(l=e.account)?void 0:l.email),T=iw(e.external_account_id,null==(s=e.account)||null==(a=s.rawIds)?void 0:a.externalAccountId,null==(c=e.account)||null==(i=c.rawIds)?void 0:i.providerAccountId),L=iw(e.account_stable_id,null==(d=e.account)?void 0:d.stableId);return{id:j,toolkit_slug:w,toolkit_name:ib(N,k),status:null!=(m=iw(e.status))?m:"UNKNOWN",created_at:null!=(x=iw(e.created_at,e.createdAt))?x:"",updated_at:null!=(f=iw(e.updated_at,e.updatedAt))?f:null,account_label:null!=C?C:null,account_name:null!=S?S:null,account_email:null!=M?M:null,external_account_id:null!=T?T:null,account_stable_id:null!=L?L:null,toolkit:{slug:w,name:ib(iw(null==(u=e.toolkit)?void 0:u.name,N),k)},account:e.account?{...e.account,stableId:null!=L?L:null,confidence:null!=(v=e.account.confidence)?v:void 0,label:null!=C?C:null,email:null!=M?M:null}:void 0,reconnect:e.reconnect?{claim:null!=(g=e.reconnect.claim)?g:"unknown",confidence:null!=(y=e.reconnect.confidence)?y:"unknown",relatedConnectionIds:null!=(b=e.reconnect.relatedConnectionIds)?b:[]}:void 0}}function iT(e){var t,r,n,o,l,a,s;let i="string"==typeof(s=e.status)&&s.trim()?s.trim().toUpperCase():"UNKNOWN",c=function(e){var t,r,n;let o=iw(e.account_stable_id,null==(t=e.account)?void 0:t.stableId);if(o)return{value:o,source:"gateway_stable_id",confidence:null!=(n=null==(r=e.account)?void 0:r.confidence)?n:"high"};let l=[e.external_account_id,e.account_email,e.account_name,e.account_label].find(e=>"string"==typeof e&&e.trim());return l?{value:"".concat(iy(e.toolkit_slug),":").concat(l.trim().toLowerCase()),source:"legacy_heuristic",confidence:e.external_account_id?"high":"low"}:{value:"".concat(iy(e.toolkit_slug),":").concat(e.id),source:"connection_id",confidence:"unknown"}}(e),d=null!=(o=null==(t=e.reconnect)?void 0:t.claim)?o:"unknown",u=null!=(l=null==(r=e.reconnect)?void 0:r.confidence)?l:"unknown",p=null!=(a=null==(n=e.reconnect)?void 0:n.relatedConnectionIds)?a:[];return{...e,normalized_toolkit_slug:iy(e.toolkit_slug),normalized_status:i,is_active:"ACTIVE"===i,account_identity:c.value,account_identity_source:c.source,identity_confidence:c.confidence,display_label:function(e){let t=[e.account_label,e.account_name,e.account_email].find(e=>"string"==typeof e&&e.trim());return t||"Connection ".concat(e.id.slice(-6))}(e),reconnect_claim:d,reconnect_confidence:u,related_connection_ids:p,is_same_account_reconnect:"same"===d&&"high"===u}}function iL(e){let t=Date.parse(e.created_at);return Number.isFinite(t)?t:0}function iI(e,t){if(e.is_active!==t.is_active)return e.is_active?-1:1;let r=iL(t)-iL(e);return 0!==r?r:e.display_label.localeCompare(t.display_label)}function i_(e){return e.map(iT).sort(iI)}let iR="composio-connected-apps-snapshot",iE=[{slug:"gmail",label:"Gmail",fallbackIcon:s9.nP5,fallbackColor:"#EA4335"},{slug:"google-calendar",label:"Calendar",fallbackIcon:s9._eB,fallbackColor:"#4285F4"},{slug:"slack",label:"Slack",fallbackIcon:s9.D6W,fallbackColor:"#E01E5A"},{slug:"notion",label:"Notion",fallbackIcon:s9.i4$,fallbackColor:"#111111"}];function iD(e){return i_(e).some(e=>e.is_active)}function iA(e){let{onNavigate:t,forceVisible:r=!1,className:l=""}=e,[a,s]=(0,o.useState)(!1),[i,c]=(0,o.useState)({});(0,o.useEffect)(()=>{s(function(){try{var e;let t=localStorage.getItem(iR);if(!t)return!1;let r=JSON.parse(t);return iD(null!=(e=r.connections)?e:[])}catch(e){return!1}}());let e=!1;return(async()=>{try{let[n,o]=await Promise.all([fetch("/api/composio/connections?include_toolkits=1",{cache:"no-store"}),fetch("/api/composio/toolkits?limit=24",{cache:"force-cache"})]);if(!n.ok)return;let l=await n.json(),a=iS(l);var t,r=null!=(t=l.toolkits)?t:[];try{localStorage.setItem(iR,JSON.stringify({connectedToolkits:r,connections:a}))}catch(e){}if(e||s(iD(a)),!o.ok)return;let i=await o.json(),d=iC(i).items;e||c(Object.fromEntries(d.filter(e=>e.logo).map(e=>[e.slug,e.logo])))}catch(e){}})(),()=>{e=!0}},[]);let d=(0,o.useMemo)(()=>null!=t?t:()=>window.location.assign((0,rt.bJ)("~integrations")),[t]);return a&&!r?null:(0,n.jsx)("div",{className:"flex w-full justify-center px-4 ".concat(l),children:(0,n.jsxs)("button",{type:"button",onClick:d,className:"inline-flex items-center gap-2.5 rounded-full border px-3 py-1.5 transition-all hover:opacity-90",style:{background:"color-mix(in srgb, var(--color-surface) 50%, transparent)",borderColor:"color-mix(in srgb, var(--color-border) 58%, transparent)",boxShadow:"0 8px 22px rgba(0,0,0,0.045)",backdropFilter:"blur(12px)"},"aria-label":"Connect recommended apps",title:"Open integrations",children:[(0,n.jsx)("span",{className:"text-[11px] md:text-xs font-medium",style:{color:"var(--color-text-secondary)"},children:"Connect recommended apps"}),(0,n.jsx)("div",{className:"h-4 w-px shrink-0",style:{background:"color-mix(in srgb, var(--color-border) 75%, transparent)"},"aria-hidden":"true"}),(0,n.jsx)("div",{className:"flex items-center gap-1.5",children:iE.map(e=>{let{slug:t,label:r,fallbackIcon:o,fallbackColor:l}=e;return(0,n.jsx)("div",{className:"flex h-4 w-auto items-center justify-center",title:r,"aria-hidden":"true",children:i[t]?(0,n.jsx)("img",{src:i[t],alt:"",className:"block h-4 w-auto object-contain",loading:"lazy"}):(0,n.jsx)(o,{size:14,color:l})},t)})})]})})}var iF=r(29341),iP=r(94003),iB=r(12594),iW=r(60743),iO=r(64049),iz=r(97185);let iU={displayName:"Dench Integrations",searchLabel:"Searching Dench Integrations",callLabel:"Calling Dench Integration",genericToolLabel:"Using Dench Integrations",attentionLabel:"Dench Integrations needs attention"};function iH(e,t){let r="Failed to ".concat(e," ").concat(iU.displayName," status");return"number"==typeof t?"".concat(r," (").concat(t,")"):"".concat(r,".")}let iV=new Set(["jpg","jpeg","png","gif","webp","svg","bmp","avif","heic","heif","tiff","tif","ico"]),iK=new Set(["mp4","webm","mov","avi","mkv"]),iJ=new Set(["pdf"]),iq=new Set(["mp3","wav","ogg","m4a"]);function iG(e){var t;let r=(null!=(t=e.split(".").pop())?t:"").toLowerCase();return iV.has(r)?"image":iK.has(r)?"video":iJ.has(r)?"pdf":iq.has(r)?"audio":null}function i$(e){return e.startsWith("http://")||e.startsWith("https://")?e:"/api/workspace/raw-file?path=".concat(encodeURIComponent(e))}let iY=/(?:^|[\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,iZ=["path","file","file_path","filePath","filename","url","src","name","target"];function iQ(e,t){if(e)for(let t of iZ){let r=e[t];if("string"==typeof r&&r.length>0)return r}if(t)for(let e of iZ){let r=t[e];if("string"==typeof r&&r.length>0&&iX(r))return r}if(e){let t=i0(e);if(t)return t}if((null==t?void 0:t.text)&&"string"==typeof t.text){let e=t.text.match(iY);if(e)return e[1]}if(t){let e=i0(t);if(e)return e}return null}function iX(e){return e.length>2&&e.length<500&&/\.\w{1,5}$/.test(e)&&!e.includes(" ")}function i0(e){for(let t of Object.values(e))if("string"==typeof t&&iX(t))return t;return null}let i1=/https?:\/\/[^\s"'<>,;)}\]]+/gi;function i2(e){return"https://www.google.com/s2/favicons?sz=64&domain_url=".concat(encodeURIComponent(e))}function i4(e){return e&&"object"==typeof e&&!Array.isArray(e)?e:null}function i5(e){return Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e&&!Array.isArray(e)):[]}function i3(e){return"string"==typeof e&&e.trim().length>0?e.trim():null}function i6(e){return Array.isArray(e)?e.filter(e=>"string"==typeof e&&e.trim().length>0).map(e=>e.trim()):[]}function i8(e){let{label:t,value:r}=e;return(0,n.jsxs)("div",{className:"text-[11px] leading-relaxed",style:{color:"var(--color-text-secondary)"},children:[(0,n.jsxs)("span",{style:{color:"var(--color-text-muted)"},children:[t,": "]}),(0,n.jsx)("span",{children:r})]})}function i7(e,t,r){if("dench_search_integrations"===e||"dench_execute_integrations"===e||"composio_search_tools"===e||"composio_call_tool"===e)return"composio";let n=e.toLowerCase().replace(/[_-]/g,"");if(["websearch","search","googlesearch","bingsearch","browsersearch","tavily"].some(e=>n.includes(e)))return"search";if("browser"===n){let e="string"==typeof(null==t?void 0:t.action)?t.action.toLowerCase():"";return"open"===e||"navigate"===e?"fetch":"screenshot"===e?"image":"generic"}if(["fetchurl","fetch","browse","browseurl","webfetch"].some(e=>n.includes(e)))return"fetch";if(["read","file","readfile","getfile"].some(e=>n.includes(e)))return"read";if(["bash","shell","execute","exec","terminal","command","run"].some(e=>n.includes(e)))return"exec";if(["write","create","edit","str_replace","save","patch"].some(e=>n.includes(e)))return"write";if(["image","screenshot","photo","picture","dalle","generateimage"].some(e=>n.includes(e))){if(("string"==typeof(null==t?void 0:t.description)?t.description.trim():"")||n.includes("generateimage")||n.includes("dalle"))return"image";let e=iQ(t,r);return e&&"image"===iG(e)?"read":"image"}return"generic"}function i9(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")},[]),p=(0,o.useRef)(!1);(0,o.useEffect)(()=>{r?p.current=!0:p.current&&t.length>0&&(p.current=!1,a(!1))},[r,t.length]);let h=t.filter(e=>"reasoning"===e.kind).map(e=>e.text).join(""),m=t.some(e=>"reasoning"===e.kind&&e.isStreaming),x=function(e){let t=[],r=0;for(;r<e.length;){let n=e[r],o=i7(n.toolName,n.args,n.output),l=iQ(n.args,n.output),a=l?iG(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=i7(t.toolName,t.args,t.output),n=iQ(t.args,t.output),l=n?iG(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"===i7(t.toolName,t.args,t.output))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)(cc,{className:"w-4 h-4 flex-shrink-0 opacity-60"}),(0,n.jsx)("span",{className:"font-medium",children:f}),(0,n.jsx)(cd,{className:"w-3.5 h-3.5 ml-1 flex-shrink-0 transition-transform duration-200 ".concat(l?"":"-rotate-90")})]}),(0,n.jsx)(iB.N,{initial:!1,children:l&&(0,n.jsx)(iW.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)(iB.N,{initial:!1,children:[h&&(0,n.jsxs)(iW.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)(ce,{text:h,isStreaming:m})})]},"reasoning"),x.map((e,t)=>"media-group"===e.type?(0,n.jsx)(iW.P.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.25,ease:"easeOut"},children:(0,n.jsx)(cr,{mediaKind:e.mediaKind,items:e.items})},"media-".concat(t)):"fetch-group"===e.type?(0,n.jsx)(iW.P.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.25,ease:"easeOut"},children:(0,n.jsx)(ct,{items:e.items})},"fetch-".concat(t)):(0,n.jsx)(iW.P.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.25,ease:"easeOut"},children:(0,n.jsx)(co,{...e.tool})},e.tool.toolCallId))]})]})},"content")})]})}function ce(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 ct(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)(ca,{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:i2(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 cr(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),p=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)(ca,{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)(cn,{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)(ca,{kind:"image"})})}),p&&(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:i$(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:i$(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)(ci,{}),(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:i$(e.path),controls:!0,preload:"metadata",className:"max-w-[280px] h-8"},e.tool.toolCallId))})]})]})}function cn(e){var t;let{path:r,single:l}=e,[a,s]=(0,o.useState)(!1),i=null!=(t=r.split("/").pop())?t:r,c=i$(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 co(e){var t;let{toolName:r,status:l,args:a,output:s,errorText:i}=e,c=i7(r,a,s),d="dench_search_integrations"===r||"composio_search_tools"===r,u="dench_execute_integrations"===r||"composio_call_tool"===r,[p,h]=(0,o.useState)(!(d||u)&&("exec"===c||"generic"===c)),[m,x]=(0,o.useState)(!0),f=function(e,t,r,n){var o,l,a,s,i,c,d,u,p,h,m,x,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"composio":return"dench_search_integrations"===t||"composio_search_tools"===t?iU.searchLabel:"dench_execute_integrations"===t||"composio_call_tool"===t?iU.callLabel:iU.genericToolLabel;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=iQ(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!=(p=w("path"))?p:w("file"))?h:w("file_path");if(e){let t=null!=(m=e.split("/").pop())?m: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!=(x=w("command"))?x: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),v=d?function(e){var t,r,n,o,l,a,s;if(!e)return null;let i=i5(e.results),c=null!=(t=i4(e.recommended_result))?t:i[0],d=i.slice(0,3).map(e=>{var t,r;return null!=(r=null!=(t=i3(e.tool))?t:i3(e.tool_slug))?r:i3(e.name)}).filter(e=>!!e),u=i4(null==c?void 0:c.selected_account),p=i5(null!=(r=null==c?void 0:c.account_candidates)?r:null==c?void 0:c.accounts),h=i4(null!=(n=null==c?void 0:c.input_schema)?n:null==c?void 0:c.input_parameters),m=i4(null==h?void 0:h.properties),x=m?Object.keys(m):[],f=i6(null==h?void 0:h.required),v=i6(null!=(o=null==c?void 0:c.recommended_plan_steps)?o:e.next_steps_guidance).slice(0,3),g=i6(null==c?void 0:c.known_pitfalls).slice(0,2),y="number"==typeof(null==c?void 0:c.account_count)?c.account_count:p.length,b=i4(null==c?void 0:c.toolkit),j=null!=(l=i3(null==b?void 0:b.name))?l:i3(null==b?void 0:b.slug),k="number"==typeof e.result_count?e.result_count:i.length,w=i6(e.connected_toolkits),N=null!=(a=i3(e.toolkit_filter))?a:i3(e.app_filter);return{resultSummary:k>0?"".concat(k," tool").concat(1===k?"":"s"," found"):N?"No ".concat(N," tools matched"):"No tools matched",connectedToolkits:w.length>0?w.join(", "):null,topTools:d,sessionId:i3(e.search_session_id),accountSummary:null!=(s=i3(null==u?void 0:u.display_label))?s:y>0?"".concat(y," connected account").concat(1===y?"":"s").concat(j?" (".concat(j,")"):""):(null==c?void 0:c.is_connected)===!0?"Connected":null,schemaSummary:x.length>0?"".concat(x.length," input fields").concat(f.length>0?", ".concat(f.length," required"):""):null,schemaText:h?JSON.stringify(h,null,2):null,planSteps:v,pitfalls:g}}(s):null,g=u?function(e,t){var r,n,o,l,a,s,i,c,d,u,p,h,m,x;let f=i4(null==t?void 0:t.execution),v=i4(null==t?void 0:t.recovery),g=null!=(l=null!=(o=null!=(n=i3(null==e?void 0:e.tool_name))?n:i3(null==e?void 0:e.tool_slug))?o:i3(null==t?void 0:t.tool_slug))?l:i3(null==f?void 0:f.tool_name);if(!g)return null;let y=i4(null==e?void 0:e.arguments),b=y?Object.entries(y).slice(0,3).map(e=>{let[t,r]=e,n="string"==typeof r?r:JSON.stringify(r);return"".concat(t,": ").concat(n)}):[],j=i4(null==t?void 0:t.structuredContent),k=null!=j?j:t,w=Array.isArray(null==k?void 0:k.data)?k.data:Array.isArray(null==k?void 0:k.items)?k.items:void 0,N=w?"".concat(w.length," result").concat(1===w.length?"":"s"):null!=(a=i3(null==t?void 0:t.status))?a:null,C=[Object.hasOwn(null!=k?k:{},"has_more")?"has_more: ".concat(String(null==k?void 0:k.has_more)):null,i3(null==k?void 0:k.next_cursor)?"next_cursor: ".concat(i3(null==k?void 0:k.next_cursor)):null,i3(null==k?void 0:k.starting_after)?"starting_after: ".concat(i3(null==k?void 0:k.starting_after)):null].filter(e=>!!e),S=[i3(null==v?void 0:v.recovered_via),i3(null==v?void 0:v.retried_with_account)?"account: ".concat(i3(null==v?void 0:v.retried_with_account)):null,i3(null==v?void 0:v.refreshed_execution_ref)?"refreshed execution_ref returned":null].filter(e=>!!e),M=g.split("_"),T=M.length>1?null==(r=M[0])?void 0:r.toLowerCase():null;return{app:null!=(c=null!=(i=null!=(s=i3(null==e?void 0:e.app))?s:i3(null==t?void 0:t.toolkit))?i:i3(null==f?void 0:f.toolkit))?c:T,toolName:g,account:null!=(m=null!=(h=null!=(p=null!=(u=null!=(d=i3(null==e?void 0:e.account))?d:i3(null==t?void 0:t.account))?u:i3(null==f?void 0:f.account))?p:i3(null==e?void 0:e.connected_account_id))?h:i3(null==t?void 0:t.connectedAccountId))?m:i3(null==e?void 0:e.account_identity),keyArgs:b,pagination:C.length>0?C.join(" | "):null,resultSummary:N,sessionId:null!=(x=i3(null==t?void 0:t.tool_router_session_id))?x:i3(null==f?void 0:f.tool_router_session_id),recoverySummary:S.length>0?S.join(" | "):null}}(a,s):null,y="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(i1))?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):[],b="string"==typeof(null==s?void 0:s.error)?s.error:void 0,j=null!=i?i:b,k="string"==typeof(null==s?void 0:s.text)?s.text:void 0,w=(()=>{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")}})(),N=iQ(a,s),C=N?iG(N):null,S="read"===c&&C&&"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)(cs,{}):(0,n.jsx)("span",{className:"running"===l?"animate-pulse":"",children:(0,n.jsx)(ca,{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":"").concat(!k||S||w||"done"!==l?"":" cursor-pointer hover:underline"),onClick:!k||S||w||"done"!==l?void 0:()=>h(e=>!e),children:f}),"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:""]})]}),w&&"done"===l&&(0,n.jsxs)("div",{className:"mt-1.5",children:[(0,n.jsx)("button",{type:"button",onClick:()=>x(e=>!e),className:"text-[11px] hover:underline cursor-pointer mb-1",style:{color:"var(--color-accent)"},children:m?"Hide changes":"Show changes"}),m&&(0,n.jsx)(lf,{diff:w})]}),S&&N&&"image"===C&&(0,n.jsx)("div",{className:"mt-1.5",children:(0,n.jsx)(cn,{path:N,single:!0})}),S&&N&&"video"===C&&(0,n.jsx)("video",{src:i$(N),controls:!0,preload:"metadata",className:"mt-1.5 rounded-lg max-w-[240px] max-h-[160px]",style:{border:"1px solid var(--color-border)"}}),S&&N&&"pdf"===C&&(0,n.jsxs)("a",{href:i$(N),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)(ci,{}),(0,n.jsx)("span",{className:"truncate max-w-[200px]",children:null!=(t=N.split("/").pop())?t:N})]}),S&&N&&"audio"===C&&(0,n.jsx)("audio",{src:i$(N),controls:!0,preload:"metadata",className:"mt-1.5 max-w-[280px] h-8"}),y.length>0&&"running"!==l&&(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap mt-1.5",children:y.map(e=>(0,n.jsx)(cl,{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:y.length>0?y.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:i2(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&&j&&(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:j}),v&&(0,n.jsxs)("div",{className:"mt-1.5 rounded-lg px-2.5 py-2",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)(i8,{label:"Results",value:v.resultSummary}),v.connectedToolkits&&(0,n.jsx)(i8,{label:"Connected",value:v.connectedToolkits}),v.topTools.length>0&&(0,n.jsx)(i8,{label:"Top matches",value:v.topTools.join(", ")}),v.accountSummary&&(0,n.jsx)(i8,{label:"Accounts",value:v.accountSummary}),v.schemaSummary&&(0,n.jsx)(i8,{label:"Schema",value:v.schemaSummary}),v.planSteps.length>0&&(0,n.jsx)(i8,{label:"Plan",value:v.planSteps.join(" -> ")}),v.pitfalls.length>0&&(0,n.jsx)(i8,{label:"Pitfalls",value:v.pitfalls.join(" | ")}),v.sessionId&&(0,n.jsx)(i8,{label:"Session",value:v.sessionId}),v.schemaText&&(0,n.jsxs)("details",{className:"mt-2",children:[(0,n.jsx)("summary",{className:"text-[11px] cursor-pointer",style:{color:"var(--color-text-secondary)"},children:"Schema details"}),(0,n.jsx)("pre",{className:"mt-2 text-[11px] font-mono rounded-lg px-2.5 py-2 overflow-x-auto whitespace-pre-wrap break-all max-h-56 overflow-y-auto leading-relaxed",style:{color:"var(--color-text-muted)",background:"var(--color-surface-hover)"},children:v.schemaText})]})]}),g&&(0,n.jsxs)("div",{className:"mt-1.5 rounded-lg px-2.5 py-2",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)"},children:[(0,n.jsx)(i8,{label:"Tool",value:g.app?"".concat(g.app," / ").concat(g.toolName):g.toolName}),g.account&&(0,n.jsx)(i8,{label:"Account",value:g.account}),g.sessionId&&(0,n.jsx)(i8,{label:"Session",value:g.sessionId}),g.recoverySummary&&(0,n.jsx)(i8,{label:"Recovery",value:g.recoverySummary}),g.keyArgs.length>0&&(0,n.jsx)(i8,{label:"Args",value:g.keyArgs.join(" | ")}),g.pagination&&(0,n.jsx)(i8,{label:"Pagination",value:g.pagination}),g.resultSummary&&(0,n.jsx)(i8,{label:"Result",value:g.resultSummary})]}),!k&&!w&&!S&&"running"!==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)}),k&&!S&&!w&&(0,n.jsx)("div",{className:"mt-1",children:(p||"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:k.length>1e4?k.slice(0,1e4)+"\n... (truncated)":k})})]})]})}function cl(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:i2(t),alt:"",width:16,height:16,className:"rounded-sm flex-shrink-0",loading:"lazy"}),r]})}function ca(e){let{kind:t}=e,r="var(--color-text-muted)";switch(t){case"composio":return(0,n.jsx)("img",{src:"/dench-integrations-icon.png",alt:"",width:16,height:16,className:"rounded-sm"});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 cs(){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 ci(){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 cc(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 cd(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 cu=["Preparing response...","Optimizing session context...","Waiting for subagent results...","Waiting for subagents..."];function cp(e){return e.trim().replace(/\s+/g," ")}function ch(e){return"text"===e.type&&"string"==typeof e.text&&cp(e.text).length>0}function cm(e){return"dynamic-tool"===e.type||"tool-invocation"===e.type||e.type.startsWith("tool-")}function cx(e){for(let t=e.length-1;t>=0;t--)if(cm(e[t]))return t;return -1}function cf(e){return"dynamic-tool"===e.type?"string"==typeof e.toolName?e.toolName:null:e.type.startsWith("tool-")?"string"==typeof e.title&&e.title.trim()?e.title:"string"==typeof e.toolName&&e.toolName.trim()?e.toolName:e.type.replace(/^tool-/,""):null}function cv(e){return"dynamic-tool"===e.type?"string"==typeof e.state?e.state:"input-available":e.type.startsWith("tool-")?"string"==typeof e.state?e.state:"string"==typeof e.errorText&&e.errorText.trim()?"error":"result"in e||"output"in e?"output-available":"input-available":null}function cg(e){return!!((null==e?void 0:e.role)==="assistant"&&e.parts.some(e=>ch(e)))}function cy(e){if(!e||"assistant"!==e.role)return!1;let t=cx(e.parts);return -1===t?cg(e):e.parts.slice(t+1).some(e=>ch(e))}function cb(e){return cu.some(t=>e.startsWith(t))}function cj(e){let{state:t}=e;return"loading"===t?(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"animate-spin",children:(0,n.jsx)("path",{d:"M21 12a9 9 0 1 1-9-9"})}):"playing"===t?(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("rect",{x:"6",y:"5",width:"4",height:"14",rx:"1"}),(0,n.jsx)("rect",{x:"14",y:"5",width:"4",height:"14",rx:"1"})]}):(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)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("path",{d:"M15.5 8.5a5 5 0 0 1 0 7"}),(0,n.jsx)("path",{d:"M19 5a10 10 0 0 1 0 14"})]})}function ck(e){let{text:t}=e,[r,l]=(0,o.useState)("idle"),a=(0,o.useRef)(null),s=(0,o.useRef)(null);(0,o.useEffect)(()=>()=>{var e;null==(e=a.current)||e.pause(),s.current&&URL.revokeObjectURL(s.current)},[]);let i=()=>{var e;null==(e=a.current)||e.pause(),a.current=null,s.current&&(URL.revokeObjectURL(s.current),s.current=null),l("idle")},c=async()=>{if("loading"!==r){if("playing"===r)return void i();l("loading");try{let e=await fetch("/api/voice/speech",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t})});if(!e.ok)throw Error("Failed to generate audio.");s.current&&URL.revokeObjectURL(s.current);let r=URL.createObjectURL(await e.blob());s.current=r;let n=new Audio(r);a.current=n,n.addEventListener("ended",i,{once:!0}),await n.play(),l("playing")}catch(e){l("error"),window.setTimeout(()=>l("idle"),2e3)}}};return(0,n.jsx)("button",{type:"button",onClick:()=>void c(),className:"p-1 rounded-md transition-colors",style:{color:"error"===r?"var(--color-error, #ef4444)":"var(--color-text-muted)"},title:"playing"===r?"Stop voice playback":"Play voice","aria-label":"playing"===r?"Stop voice playback":"Play voice",children:(0,n.jsx)(cj,{state:r})})}let cw=null,cN=["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 cC(e){let{code:t,lang:r}=e,[l,a]=(0,o.useState)(null);return((0,o.useEffect)(()=>{let e=!1;return(!cw&&(cw=(0,lE.O_)({themes:["github-dark","github-light"],langs:cN})),cw).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})}function cS(e,t){let r=e.get(t);return"string"==typeof r&&r.trim().length>0?r.trim():null}function cM(e){let t,r=e.trim();if(!r)return null;try{t=new URL(r)}catch(e){return null}if("dench:"!==t.protocol||"composio"!==t.hostname)return null;let n=t.pathname.replace(/^\/+|\/+$/g,"");return"connect"!==n&&"reconnect"!==n?null:{action:n,toolkitSlug:cS(t.searchParams,"toolkit"),toolkitName:cS(t.searchParams,"name")}}var cT=r(71803);let cL=new Map;function cI(e){return"string"==typeof e&&e.trim().length>0?e.trim():null}function c_(e,t,r){var n,o;let l=iy(t),a=null!=(n=null==r?void 0:r.trim().toLowerCase())?n:"";return null!=(o=e.find(e=>iy(e.slug)===l||a.length>0&&e.name.trim().toLowerCase()===a))?o:null}async function cR(e){var t,r;let n=new URLSearchParams({search:e.query,limit:"24"}),o=await fetch("/api/composio/toolkits?".concat(n.toString()));if(!o.ok)return null;let l=c_(iC(await o.json()).items,null!=(r=null!=(t=e.toolkitSlug)?t:e.toolkitName)?r:"",e.toolkitName);return l?{logo:cI(l.logo),name:l.name}:null}async function cE(e){var t,r,n,o;let l=(null==(t=e.toolkitSlug)?void 0:t.trim())?"slug:".concat(iy(e.toolkitSlug)):(null==(r=e.toolkitName)?void 0:r.trim())?"name:".concat(e.toolkitName.trim().toLowerCase()):null,a=function(e){let t=new Set,r=[];for(let n of e){if("string"!=typeof n||0===n.trim().length)continue;let e=n.trim(),o=e.toLowerCase();t.has(o)||(t.add(o),r.push(e))}return r}([null!=(o=e.toolkitName)?o:null,...(null==(n=e.toolkitSlug)?void 0:n.trim())?function(e){var t;let r=iy(e);return null!=(t=iv[r])?t:[r]}(e.toolkitSlug):[]]);if(!l||0===a.length)return null;let s=Date.now(),i=cL.get(l);if(i&&i.expiresAt>s)return"value"in i?i.value:i.promise;let c=(async()=>{for(let t of a){let r=await cR({query:t,toolkitSlug:e.toolkitSlug,toolkitName:e.toolkitName});if(r)return r}return null})();cL.set(l,{expiresAt:s+3e5,promise:c});try{let e=await c;return cL.set(l,{expiresAt:Date.now()+3e5,value:e}),e}catch(e){throw cL.delete(l),e}}function cD(e){var t,r;let n=cI(e.initialLogo),l=null!=(r=null==(t=e.toolkitName)?void 0:t.trim())?r:null,[a,s]=(0,o.useState)({logo:n,name:l});return(0,o.useEffect)(()=>{s({logo:n,name:l})},[n,l]),(0,o.useEffect)(()=>{var t,r;if(n||!(null==(t=e.toolkitSlug)?void 0:t.trim())&&!(null==(r=e.toolkitName)?void 0:r.trim()))return;let o=!1;return cE({toolkitSlug:e.toolkitSlug,toolkitName:e.toolkitName}).then(e=>{!o&&e&&s(t=>{var r,n;return{logo:null!=(r=t.logo)?r:e.logo,name:null!=(n=t.name)?n:e.name}})}).catch(()=>{}),()=>{o=!0}},[n,e.toolkitName,e.toolkitSlug]),a}let cA=(0,li.default)(()=>r.e(45477).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)"}})}),cF="NO_REPLY";function cP(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return"output-error"===e||"error"===e?"error":"output-available"!==e||t?"running":"done"}function cB(e){if(e&&"object"==typeof e&&!Array.isArray(e))return e}function cW(e){let t="[Attached files: ",r=e.indexOf(t);if(-1===r)return null;let n=r+t.length,o=e.indexOf("]",n);if(-1===o)return null;let l=e.slice(o+1).trim();return{paths:e.slice(n,o).split(", ").map(e=>e.trim()).filter(Boolean),message:l}}async function cO(e){var t;if("undefined"!=typeof navigator&&(null==(t=navigator.clipboard)?void 0:t.writeText))return void await navigator.clipboard.writeText(e);if("undefined"==typeof document)throw Error("Clipboard is unavailable");let r=document.createElement("textarea");r.value=e,r.setAttribute("readonly","true"),r.style.position="fixed",r.style.opacity="0",document.body.appendChild(r),r.focus(),r.select();let n=document.execCommand("copy");if(document.body.removeChild(r),!n)throw Error("Clipboard copy failed")}function cz(e){let{paths:t}=e,[r,l]=(0,o.useState)(null);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex flex-wrap gap-1.5 mb-2 justify-end",children:t.map((e,t)=>{var r,o,a;let s=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),i="image"===s?"/api/workspace/raw-file?path=".concat(encodeURIComponent(e)):"/api/workspace/thumbnail?path=".concat(encodeURIComponent(e),"&size=200"),c=null!=(o=e.split("/").pop())?o:"",d=null!=(a=null==(r=e.split(".").pop())?void 0:r.toUpperCase())?a:"";return(0,n.jsx)("div",{className:"relative rounded-xl overflow-hidden shrink-0",children:"image"===s?(0,n.jsx)("button",{type:"button",className:"block cursor-zoom-in transition-all duration-200 hover:opacity-95","aria-label":"Open image ".concat(c),onClick:()=>l({src:i,alt:c}),children:(0,n.jsx)("img",{src:i,alt:c,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"}})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("img",{src:i,alt:c,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"}}),(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:d})]})},t)})}),(0,n.jsx)(cT.lG,{open:null!==r,onOpenChange:e=>{e||l(null)},children:(0,n.jsxs)(cT.Cf,{"aria-label":r?"Image preview ".concat(r.alt):"Image preview",className:"!max-w-[90vw] !w-auto !p-0 !rounded-2xl !bg-transparent !border-none !shadow-[0_0_120px_rgba(0,0,0,0.4)]",showCloseButton:!1,children:[(0,n.jsx)("button",{type:"button","aria-label":"Close image preview",onClick:()=>l(null),className:"absolute top-3 right-3 z-10 w-7 h-7 rounded-full flex items-center justify-center cursor-pointer outline-none transition-all hover:opacity-85",style:{background:"rgba(0,0,0,0.55)",color:"white",backdropFilter:"blur(4px)",boxShadow:"0 2px 8px rgba(0,0,0,0.3)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})}),r&&(0,n.jsx)("img",{src:r.src,alt:r.alt,className:"block rounded-xl",style:{maxHeight:"80vh",maxWidth:"85vw",objectFit:"contain"}})]})})]})}function cU(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 cH(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 cV(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 cK(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 cH(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 cJ(e){let{src:t,alt:r,...l}=e,[a,s]=(0,o.useState)(!1);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("img",{src:t,alt:null!=r?r:"",loading:"lazy",className:"cursor-pointer transition-all duration-200 hover:opacity-95",onClick:()=>s(!0),...l}),(0,n.jsx)(cT.lG,{open:a,onOpenChange:s,children:(0,n.jsxs)(cT.Cf,{className:"!max-w-[90vw] !w-auto !p-0 !rounded-2xl !bg-transparent !border-none !shadow-[0_0_120px_rgba(0,0,0,0.4)]",showCloseButton:!1,children:[(0,n.jsx)("button",{type:"button",onClick:()=>s(!1),className:"absolute top-3 right-3 z-10 w-7 h-7 rounded-full flex items-center justify-center cursor-pointer outline-none transition-all hover:opacity-85",style:{background:"rgba(0,0,0,0.55)",color:"white",backdropFilter:"blur(4px)",boxShadow:"0 2px 8px rgba(0,0,0,0.3)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})}),t&&(0,n.jsx)("img",{src:t,alt:null!=r?r:"Preview",className:"block rounded-xl",style:{maxHeight:"80vh",maxWidth:"85vw",objectFit:"contain"}})]})})]})}function cq(e){var t,r,o,l,a;let{action:s,children:i,onPress:c}=e,d=cD({toolkitSlug:null!=(l=s.toolkitSlug)?l:null,toolkitName:null!=(a=s.toolkitName)?a:null}),u=(null==(t=d.name)?void 0:t.trim())||(null==(r=s.toolkitName)?void 0:r.trim())||(null==(o=s.toolkitSlug)?void 0:o.trim().replace(/-/g," "))||"app",p=d.logo,h=u.split(/\s+/).filter(Boolean).slice(0,2).map(e=>e.charAt(0)).join("").toUpperCase()||"AP",m="connect"===s.action;return(0,n.jsxs)("button",{type:"button",className:"not-prose my-1 inline-flex items-center gap-1.5 rounded-lg px-1 py-0.5 pr-2.5 text-xs font-semibold whitespace-nowrap transition-colors",style:{background:"color-mix(in srgb, var(--color-accent) 10%, transparent)",color:"var(--color-accent)",border:"none"},onMouseEnter:e=>{e.currentTarget.style.background="color-mix(in srgb, var(--color-accent) 15%, transparent)"},onMouseLeave:e=>{e.currentTarget.style.background="color-mix(in srgb, var(--color-accent) 10%, transparent)"},onClick:()=>null==c?void 0:c(s),children:[(0,n.jsx)("span",{className:"flex h-5 w-5 shrink-0 items-center justify-center overflow-hidden rounded","aria-hidden":"true",style:m?{background:"rgba(255, 255, 255, 0.16)",color:"#fff"}:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:p?(0,n.jsx)("img",{src:p,alt:"",className:"h-4 w-4 object-contain",loading:"lazy",decoding:"async"}):(0,n.jsx)("span",{className:"text-[10px] font-bold uppercase",children:h})}),(0,n.jsx)("span",{className:"leading-none",children:i})]})}let cG="phc_Nt8s1Ny8062TY9aKT8LWiB4nBuoHNYQXRU9MypWfQCW";function c$(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=iF.Ay.get_distinct_id)?void 0:r.call(iF.Ay)})}).catch(()=>{})},[]),{respond:a,response:s,triggerRef:i}=(0,iP.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",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"})]})})]})}function cY(e){let{text:t}=e,[r,l]=(0,o.useState)(!1),a=(0,o.useRef)(null);(0,o.useEffect)(()=>()=>{null!==a.current&&window.clearTimeout(a.current)},[]);let s=(0,o.useCallback)(async()=>{try{await cO(t),l(!0),null!==a.current&&window.clearTimeout(a.current),a.current=window.setTimeout(()=>{l(!1),a.current=null},1500)}catch(e){l(!1)}},[t]);return(0,n.jsx)("button",{type:"button",onClick:()=>{s()},className:"p-1 rounded-md transition-colors",style:{color:r?"var(--color-accent)":"var(--color-text-muted)"},title:r?"Copied":"Copy message","aria-label":r?"Copied":"Copy message",children:r?(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-11 11-5-5"})}):(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:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})}let cZ=(0,o.memo)(function(e){let{message:t,isStreaming:r,onSubagentClick:l,onFilePathClick:a,onComposioAction:s,sessionId:i,voicePlaybackEnabled:c=!1,userHtmlMap:d,copyable:u=!1}=e,p="user"===t.role,h=(0,o.useMemo)(()=>(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 p of e)if("text"===p.type){let e=p.text;if(function(e){let t=e.trim();return!!t&&!!(new RegExp("^".concat(cF,"\\W*$")).test(t)||cF.startsWith(t)&&t.length>=2&&t.length<cF.length)}(e))continue;if(n(!0),ld(e))t.push(...lc(e));else if(lp(e))for(let r of lu(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"===p.type)cb(p.text)||r.push({kind:"reasoning",text:p.text,isStreaming:"streaming"===p.state});else if("dynamic-tool"===p.type)if("sessions_spawn"===p.toolName){n(!0);let e=cB(p.input),r=cB(p.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:cP(p.state,!0===p.preliminary)})}else{let e=cB(p.output),t=cP(p.state,!0===p.preliminary);r.push({kind:"tool",toolName:p.toolName,toolCallId:p.toolCallId,status:t,args:cB(p.input),output:e,errorText:"error"===t&&"string"==typeof(null==e?void 0:e.error)?e.error:void 0})}else if(p.type.startsWith("tool-")){var o,l,a,s,i,c,d,u;let e=null!=(l=null!=(o=p.title)?o:p.toolName)?l:p.type.replace("tool-","");if("sessions_spawn"===e){n(!0);let e=null!=(a=cB(p.input))?a:cB(p.args),r=null!=(s=cB(p.output))?s:cB(p.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=p.state)?i:p.errorText?"output-error":"result"in p||"output"in p?"output-available":"input-available";t.push({type:"subagent-card",task:o,label:l,sessionKey:c,status:cP(d,!0===p.preliminary)})}else{let t=null!=(c=p.state)?c:p.errorText?"output-error":"result"in p||"output"in p?"output-available":"input-available";r.push({kind:"tool",toolName:e,toolCallId:p.toolCallId,status:cP(t,!0===p.preliminary),args:null!=(d=cB(p.input))?d:cB(p.args),output:null!=(u=cB(p.output))?u:cB(p.result),errorText:p.errorText})}}return n(),t})(t.parts),[t.parts]),m=(0,o.useMemo)(()=>h.filter(e=>"text"===e.type).map(e=>e.text).join("\n\n").replace(/```[\s\S]*?```/g," Code block omitted. ").replace(/`([^`]+)`/g,"$1").replace(/\[([^\]]+)\]\(([^)]+)\)/g,"$1").replace(/^#{1,6}\s+/gm,"").replace(/[*_~]/g,"").replace(/\n{3,}/g,"\n\n").replace(/\s+/g," ").trim(),[h]),x=(0,o.useMemo)(()=>(function(e,t){if("user"===e){let e=t.filter(e=>"text"===e.type).map(e=>e.text).join("\n").trim(),r=cW(e);return r?[r.message,r.paths.length>0?"Attached files:\n".concat(r.paths.join("\n")):""].filter(Boolean).join("\n\n").trim():e}return t.map(e=>{switch(e.type){case"text":return e.text.trim();case"diff-artifact":return e.diff.trim();case"subagent-card":return(e.label||e.task).trim();default:return""}}).filter(Boolean).join("\n\n").trim()})(t.role,h),[t.role,h]),f=u&&!!x,v=(0,o.useMemo)(()=>({a:e=>{let{href:t,children:r,...o}=e,l="string"==typeof t?t:"",i=cM(l),c=cV(l),d=l&&(l.startsWith("http://")||l.startsWith("https://")||l.startsWith("//")),u=!(l.startsWith("/workspace")||l.startsWith("/?"))&&(!!l.startsWith("file://")||cU(c));return i?(0,n.jsx)(cq,{action:i,onPress:s,children:r}):(0,n.jsx)("a",{href:t,...d?{target:"_blank",rel:"noopener noreferrer"}:{},...o,onClick:e=>{u&&a&&(e.preventDefault(),a(c))},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)(cJ,{src:l,alt:null!=r?r:"",...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)(lf,{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)(cC,{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=cV("string"==typeof t?t:"");return l&&cU(l)?(0,n.jsx)(cK,{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)(cK,{path:o,onFilePathClick:a,children:t})}):(0,n.jsx)("strong",{...r,children:t})}}),[s,a]);if(p){var g,y,b,j;let e=h.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),r=cW(e),o=null!=(b=null!=(g=null==d?void 0:d.get(t.id))?g:null==d?void 0:d.get(e))?b:null==d?void 0:d.get(null!=(y=null==r?void 0:r.message)?y:""),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!=(j=null==r?void 0:r.message)?j:e});return r?(0,n.jsxs)("div",{className:"flex flex-col items-end gap-1.5 py-2 group",children:[(0,n.jsx)(cz,{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}),f&&(0,n.jsx)("div",{className:"flex items-center gap-1 self-end md:opacity-0 md:group-hover:opacity-100 transition-opacity",children:(0,n.jsx)(cY,{text:x})})]}):(0,n.jsxs)("div",{className:"flex flex-col items-end gap-1 py-2 group",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}),f&&(0,n.jsx)("div",{className:"flex items-center gap-1 md:opacity-0 md:group-hover:opacity-100 transition-opacity",children:(0,n.jsx)(cY,{text:x})})]})}return(0,n.jsxs)("div",{className:"py-3 space-y-2 min-w-0 overflow-hidden group",children:[(0,n.jsx)(iB.N,{initial:!1,children:h.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)(iW.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)(iO.oz,{remarkPlugins:[iz.A],components:v,urlTransform:e=>cM(e)?e:(0,iO.Lv)(e),children:e.text})},"text-".concat(t))}if("report-artifact"===e.type)return(0,n.jsx)(iW.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},children:(0,n.jsx)(cA,{config:e.config})},"report-".concat(t));if("diff-artifact"===e.type)return(0,n.jsx)(iW.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},children:(0,n.jsx)(lf,{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)(iW.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)(iW.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},children:(0,n.jsx)(i9,{parts:e.parts,isStreaming:r})},"chain-".concat(t))})}),!r&&(f||cG||c&&m)&&(0,n.jsxs)("div",{className:"flex items-center gap-1 mt-1 md:opacity-0 md:group-hover:opacity-100 transition-opacity",children:[f&&(0,n.jsx)(cY,{text:x}),c&&m&&(0,n.jsx)(ck,{text:m}),cG&&(0,n.jsx)(c$,{messageId:t.id,sessionId:i})]})]})});var cQ=r(48997),cX=r(79534);let c0=new(r(63550)).hs("chatFileMention"),c1=cX.bP.create({name:"chatFileMention",group:"inline",inline:!0,atom:!0,selectable:!0,draggable:!0,addAttributes:()=>({label:{default:""},path:{default:""},mentionType:{default:"file"},objectName:{default:""},defaultView:{default:""}}),parseHTML:()=>[{tag:"span[data-chat-file-mention]"}],renderHTML(e){let{HTMLAttributes:t}=e,r=t.label||"file",n=t.mentionType||"file",o=t.defaultView||"",l={bg:"rgba(120, 113, 108, 0.1)",fg:"inherit"},a="object"===n?(0,M.PV)(r):r;return["span",(0,cX.KV)({"data-chat-file-mention":"","data-mention-type":n,...o?{"data-default-view":o}:{},class:"chat-file-mention",style:"--mention-bg: ".concat(l.bg,"; --mention-fg: ").concat(l.fg,";"),title:t.path||""},t),a]}});var c2=r(20617),c4=r(14868),c5=r(90236),c3=r(25298),c6=r(8870),c8=r(99252);function c7(e){let{category:t,defaultView:r}=e,o={flexShrink:0};switch(t){case"folder":return(0,n.jsx)(y.A,{size:18,style:{...o,color:"#60a5fa"}});case"image":return(0,n.jsx)(c2.A,{size:18,style:{...o,color:"#10b981"}});case"video":return(0,n.jsx)(c4.A,{size:18,style:{...o,color:"#8b5cf6"}});case"audio":return(0,n.jsx)(c5.A,{size:18,style:{...o,color:"#f59e0b"}});case"pdf":return(0,n.jsx)(b.A,{size:18,style:{...o,color:"#ef4444"}});case"code":return(0,n.jsx)(c3.A,{size:18,style:{...o,color:"#3b82f6"}});case"database":return(0,n.jsx)(j.A,{size:18,style:o});case"object":return"kanban"===r?(0,n.jsx)(c6.A,{size:18,style:{...o,color:"#8b7cf6"}}):(0,n.jsx)(L.A,{size:18,style:{...o,color:"#42a97a"}});case"entry":return(0,n.jsx)(c8.A,{size:18,style:{...o,color:"#22c55e"}});default:return(0,n.jsx)(b.A,{size:18,style:{...o,opacity:.7}})}}let c9=(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]);(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)}}));let u="bg-neutral-100/[0.67] dark:bg-neutral-900/[0.67] border border-white dark:border-white/10 backdrop-blur-md shadow-[0_0_25px_0_rgba(0,0,0,0.16)]";return a?(0,n.jsx)("div",{className:"rounded-3xl p-3 ".concat(u),style:{minWidth:280,maxWidth:400},children:(0,n.jsx)("span",{className:"text-xs animate-pulse",style:{color:"var(--color-text-muted)"},children:"Searching..."})}):0===r.length?(0,n.jsx)("div",{className:"rounded-3xl p-3 text-center ".concat(u),style:{minWidth:280,maxWidth:400},children:(0,n.jsx)("span",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"No results found"})}):(0,n.jsx)("div",{ref:c,className:"rounded-3xl p-1 overflow-y-auto thin-scrollbar ".concat(u),style:{minWidth:280,maxWidth:400,maxHeight:300},children:r.map((e,t)=>{let r=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","sh","bash","sql","swift","kt"].includes(o)?"code":"document"===t?"document":"other"}(e.name,e.type),o=e.icon&&RegExp("\\p{Emoji_Presentation}","u").test(e.icon),l="object"===e.type||"entry"===e.type,a="object"===e.type?(0,M.PV)(e.name):e.name,c="entry"===e.type&&e.objectName?(0,M.A3)(e.objectName):l?"kanban"===e.defaultView?"Board":"Table":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-2.5 py-1.5 text-left transition-all rounded-2xl select-none ".concat(t===s?"bg-neutral-400/15":""),style:{color:"var(--color-text)"},onClick:()=>d(t),onMouseEnter:()=>i(t),children:[(0,n.jsx)("span",{className:"flex-shrink-0 flex items-center",style:{opacity:.55},children:o?(0,n.jsx)("span",{className:"text-[15px] leading-none",children:e.icon}):(0,n.jsx)(c7,{category:r,defaultView:e.defaultView})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"text-sm font-medium truncate",children:a}),(0,n.jsx)("div",{className:"text-xs truncate",style:{color:"var(--color-text-muted)"},title:l?c:e.path,children:c})]})]},e.path)})})});function de(e){let{items:t,command:r,clientRect:l,componentRef:a,loading:s}=e,i=(0,o.useRef)(null);return(0,o.useLayoutEffect)(()=>{if(!i.current||!l)return;let e=l();if(!e)return;let t=i.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,s]),(0,rR.createPortal)((0,n.jsx)("div",{ref:i,children:(0,n.jsx)(c9,{ref:a,items:t,command:r,loading:s})}),document.body)}function dt(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}}c9.displayName="FileMentionList";let dr=(0,o.forwardRef)(function(e,t){let{onSubmit:l,onChange:a,onNativeFileDrop:s,placeholder:i,disabled:c,compact:d,searchFn:u}=e,p=(0,o.useRef)(l);p.current=l;let h=(0,o.useRef)(s);h.current=s;let m=(0,o.useRef)(null!=u?u:null);m.current=null!=u?u:null;let x=(0,o.useRef)(null),f=(0,eT.hG)({immediatelyRender:!1,extensions:[eI.A.configure({heading:!1,codeBlock:!1,blockquote:!1,horizontalRule:!1,bulletList:!1,orderedList:!1,listItem:!1}),eW.A.configure({placeholder:null!=i?i:"Ask anything...",showOnlyWhenEditable:!1}),c1,cX.YY.create({name:"chatFileMentionSuggestion",addProseMirrorPlugins(){return[(0,cQ.Ay)({editor:this.editor,char:"@",pluginKey:c0,startOfLine:!1,allowSpaces:!0,command:e=>{var t,r;let{editor:n,range:o,props:l}=e,a="object"===l.type?"object":"entry"===l.type?"entry":"folder"===l.type?"folder":"file";n.chain().focus().deleteRange(o).insertContent([{type:"chatFileMention",attrs:{label:l.name,path:l.path,mentionType:a,objectName:null!=(t=l.objectName)?t:"",defaultView:null!=(r=l.defaultView)?r:""}},{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)(de,{items:a,command:c,clientRect:d,componentRef:o,loading:s}))}function p(e){var t,r,n;let o=null!=(t=e.path)?t:e.id,l=null!=(r=o.split("/").pop())?r:e.label;return{name:"object"===e.kind||"entry"===e.kind?e.label:l,path:o,type:"entry"===e.kind?"entry":"object"===e.kind?"object":null!=(n=e.nodeType)?n:"file",icon:e.icon,objectName:e.objectName,entryId:e.entryId,defaultView:e.defaultView}}function h(e){let t=null==m?void 0:m.current;return!!t&&(a=t(e,20).map(p),s=!1,u(),!0)}async function x(e){if(!h(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 f(e){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),f(l)})},onUpdate:e=>{var t;c=e.command,d=null!=(t=e.clientRect)?t:null,f(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)=>{if("Enter"===t.key&&!t.shiftKey&&!t.isComposing){let t=c0.getState(e.state);return null==t||!t.active}return!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=h.current)||o.call(h,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=()=>{let e=t.target instanceof HTMLElement?t.target.closest("[data-chat-drop-target]"):null;null==e||e.removeAttribute("data-drag-hover")},s=null==(r=t.dataTransfer)?void 0:r.getData("application/x-file-mention");if(s){t.preventDefault(),t.stopPropagation(),a();try{let{name:e,path:t}=JSON.parse(s);e&&t&&(null==(o=x.current)||o.chain().focus().insertContent([{type:"chatFileMention",attrs:{label:e,path:t}},{type:"text",text:" "}]).run())}catch(e){}return!0}let i=null==(n=t.dataTransfer)?void 0:n.files;return!!i&&i.length>0&&(t.preventDefault(),t.stopPropagation(),a(),null==(l=h.current)||l.call(h,i),!0)}}},onUpdate:e=>{let{editor:t}=e;null==a||a(t.isEmpty)}});return(0,o.useEffect)(()=>{x.current=null!=f?f:null},[f]),(0,o.useEffect)(()=>{if(!f)return;let e=e=>{if("Enter"===e.key&&!e.shiftKey&&!e.isComposing){let t=c0.getState(f.state);if(null==t?void 0:t.active)return;e.preventDefault();let{text:r,mentionedFiles:n}=dt(f),o=f.getHTML();p.current(r,n,o),(r.trim()||n.length>0)&&f.commands.clearContent(!0),requestAnimationFrame(()=>f.commands.focus())}},t=f.view.dom;return t.addEventListener("keydown",e),()=>t.removeEventListener("keydown",e)},[f]),(0,o.useEffect)(()=>{f&&f.setEditable(!c)},[f,c]),(0,o.useImperativeHandle)(t,()=>({insertFileMention:(e,t)=>{null==f||f.chain().focus().insertContent([{type:"chatFileMention",attrs:{label:e,path:t}},{type:"text",text:" "}]).run()},clear:()=>{null==f||f.commands.clearContent(!0)},focus:()=>{null==f||f.commands.focus()},isEmpty:()=>{var e;return null==(e=null==f?void 0:f.isEmpty)||e},submit:()=>{if(!f)return;let{text:e,mentionedFiles:t}=dt(f);if(e.trim()||t.length>0){let r=f.getHTML();p.current(e,t,r),f.commands.clearContent(!0),requestAnimationFrame(()=>f.commands.focus())}},setText:e=>{null==f||f.commands.setContent(e),null==f||f.commands.focus("end")},appendText:e=>{if(!f)return;let t=e.trim();if(!t)return;let{text:r}=dt(f),n=r.trim().length>0?" ":"";f.chain().focus("end").insertContent("".concat(n).concat(t)).run()}})),(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(eT.$Z,{editor:f}),(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 — inherits icon from global span[data-chat-file-mention]::before */\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(120, 113, 108, 0.1));\n color: inherit;\n font-size: 12px;\n font-weight: 500;\n line-height: 1.4;\n vertical-align: middle;\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]:hover {\n opacity: 0.85;\n }\n .chat-editor-content.chat-editor-compact {\n min-height: 16px;\n }\n ')})]})});function dn(e){let{state:t}=e;return"processing"===t?(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"animate-spin",children:(0,n.jsx)("path",{d:"M21 12a9 9 0 1 1-9-9"})}):"recording"===t||"listening"===t?(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("rect",{x:"7",y:"7",width:"10",height:"10",rx:"2"})}):(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 2a3 3 0 0 0-3 3v7a3 3 0 1 0 6 0V5a3 3 0 0 0-3-3Z"}),(0,n.jsx)("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),(0,n.jsx)("path",{d:"M12 19v3"})]})}function dl(e){let{compact:t,disabled:r=!1,preferServerTranscription:l,onTranscript:a}=e,[s,i]=(0,o.useState)("idle"),[c,d]=(0,o.useState)(!1),[u,p]=(0,o.useState)(!1),h=(0,o.useRef)(null),m=(0,o.useRef)(null),x=(0,o.useRef)(null);(0,o.useEffect)(()=>{var e;let t=window;d(!!(t.SpeechRecognition||t.webkitSpeechRecognition)),p("undefined"!=typeof navigator&&!!(null==(e=navigator.mediaDevices)?void 0:e.getUserMedia)&&"undefined"!=typeof MediaRecorder)},[]),(0,o.useEffect)(()=>()=>{var e,t,r;null==(e=x.current)||e.stop(),null==(t=h.current)||t.stop(),null==(r=m.current)||r.getTracks().forEach(e=>e.stop())},[]);let f=(0,o.useMemo)(()=>l&&u?"server":c?"browser":"unsupported",[c,l,u]),v=async()=>{let e=window,t=e.SpeechRecognition||e.webkitSpeechRecognition;if(!t){i("error"),window.setTimeout(()=>i("idle"),1500);return}let r=new t;x.current=r,r.continuous=!1,r.interimResults=!1,r.maxAlternatives=1,r.onresult=e=>{let t=Array.from(e.results).map(e=>{var t,r;return null!=(r=null==(t=e[0])?void 0:t.transcript)?r:""}).join(" ").trim();t&&a(t)},r.onerror=()=>{i("idle"),x.current=null},r.onend=()=>{i("idle"),x.current=null},r.start(),i("listening")},g=async()=>{try{let e=await navigator.mediaDevices.getUserMedia({audio:!0});m.current=e;let t=[],r=new MediaRecorder(e);h.current=r,r.ondataavailable=e=>{e.data.size>0&&t.push(e.data)},r.onstop=async()=>{var e,n;try{i("processing");let n=new Blob(t,{type:r.mimeType||"audio/webm"}),o=new FormData;o.set("file",new File([n],"voice-input.webm",{type:n.type||"audio/webm"}));let l=await fetch("/api/voice/transcribe",{method:"POST",body:o});if(!l.ok)throw Error("Failed to transcribe audio.");let s=await l.json();(null==(e=s.text)?void 0:e.trim())&&a(s.text.trim()),i("idle")}catch(e){i("error"),window.setTimeout(()=>i("idle"),1500)}finally{h.current=null,null==(n=m.current)||n.getTracks().forEach(e=>e.stop()),m.current=null}},r.start(),i("recording")}catch(e){if(c)return void await v();i("error"),window.setTimeout(()=>i("idle"),1500)}},y=async()=>{if(!r&&"processing"!==s&&"unsupported"!==f){var e,t;if("server"===f)return"recording"===s?void(null==(e=h.current)||e.stop()):void await g();if("listening"===s)return void(null==(t=x.current)||t.stop(),x.current=null,i("idle"));await v()}},b="unsupported"===f?"Voice input is not supported in this browser":"processing"===s?"Transcribing...":"recording"===s||"listening"===s?"Stop voice input":"Start voice input";return(0,n.jsx)("button",{type:"button",onClick:()=>void y(),disabled:r||"unsupported"===f,className:"p-1.5 rounded-lg transition-opacity disabled:cursor-not-allowed disabled:opacity-40",style:{color:"error"===s?"var(--color-error, #ef4444)":"recording"===s||"listening"===s?"var(--color-accent)":"var(--color-text-muted)"},title:b,"aria-label":b,"data-compact":t?"true":"false",children:(0,n.jsx)(dn,{state:s})})}var da=r(395);let ds=new Set(["image/jpeg","image/png","image/gif","image/webp","image/bmp"]),di=new Set([".jpg",".jpeg",".png",".gif",".webp",".bmp"]),dc=new Set([...di,".svg",".ico",".heic",".heif",".tif",".tiff",".avif"]);function dd(e){let t=e.lastIndexOf(".");return t>=0?e.slice(t).toLowerCase():""}async function du(e){if("function"==typeof createImageBitmap){let t=await createImageBitmap(e);return{width:t.width,height:t.height,render:(e,r,n)=>{e.drawImage(t,0,0,r,n)},cleanup:()=>t.close()}}if("undefined"==typeof document)throw Error("Image conversion is unavailable in this environment.");let t=URL.createObjectURL(e);try{let e=await new Promise((e,r)=>{let n=new Image;n.onload=()=>e(n),n.onerror=()=>r(Error("The image could not be decoded.")),n.src=t});return{width:e.naturalWidth||e.width,height:e.naturalHeight||e.height,render:(t,r,n)=>{t.drawImage(e,0,0,r,n)},cleanup:()=>URL.revokeObjectURL(t)}}catch(e){throw URL.revokeObjectURL(t),e}}function dp(e,t){if("undefined"==typeof document)throw Error("Canvas is unavailable in this environment.");let r=document.createElement("canvas");return r.width=e,r.height=t,r}function dh(e,t,r){return new Promise(n=>{e.toBlob(e=>n(e),t,r)})}async function dm(e){var t,r,n,o;let l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(e.type.startsWith("image/")||dc.has(dd(e.name)))||e.size<=5242880&&(ds.has(e.type)||0===e.type.length&&di.has(dd(e.name))))return e;let a=null!=(t=l.loadImage)?t:du,s=null!=(r=l.createCanvas)?r:dp,i=null!=(n=l.canvasToBlob)?n:dh,c=[1,.85,.7,.55,.4,.28,.18],d=[.9,.8,.7,.58,.46],u=await a(e);try{let t=Math.max(1,u.width),r=Math.max(1,u.height);for(let n of function(e){let t=dd(e.name);return".png"===t||".svg"===t||".ico"===t?["image/png","image/jpeg"]:["image/jpeg","image/png"]}(e))for(let l of c){let a=Math.max(1,Math.round(t*l)),c=Math.max(1,Math.round(r*l)),p=s(a,c),h=p.getContext("2d");if(!h)throw Error("Canvas rendering is unavailable.");for(let t of("image/jpeg"===n&&(h.fillStyle="#ffffff",h.fillRect(0,0,a,c)),u.render(h,a,c),"image/png"===n?[void 0]:d)){let r=await i(p,n,t);if(r&&r.size<=5242880)return o=function(e,t){var r="image/png"===t?".png":".jpg";let n=e.lastIndexOf(".");return n<0?"".concat(e).concat(r):"".concat(e.slice(0,n)).concat(r)}(e.name,n),new File([r],o,{type:n,lastModified:Date.now()})}}}finally{u.cleanup()}throw Error("Please choose a smaller PNG or JPEG under 5 MB.")}async function dx(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=[],n=[];for(let o of Array.from(e))try{r.push(await dm(o,t))}catch(e){n.push(function(e,t){let r=t instanceof Error?t.message:"The image could not be processed.";return"".concat(e,": ").concat(r)}(o.name,e))}return{files:r,errors:n}}function df(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"auto";e.scrollTo({top:e.scrollHeight,behavior:t})}function dv(e){return!e||"object"!=typeof e||Array.isArray(e)?null:e}function dg(e){let t=dv(e);if(!t)return null;let r="string"==typeof t.stableId&&t.stableId.trim()?t.stableId.trim():null,n="string"==typeof t.displayName&&t.displayName.trim()?t.displayName.trim():null,o="string"==typeof t.provider&&t.provider.trim()?t.provider.trim():null;if(!r||!n||!o)return null;let l="string"==typeof t.id&&t.id.trim()?t.id.trim():null,a=l&&l!==r?l:void 0;return{stableId:r,...a?{catalogId:a}:{},displayName:n,provider:o,reasoning:!!t.reasoning}}function dy(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 db={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 dj(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 dk(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),p=(0,o.useRef)(null),h=()=>{let e=p.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=p.current)||e.focus();let o=null!=(n=null==(t=p.current)?void 0:t.value.length)?n:0;null==(r=p.current)||r.setSelectionRange(o,o),h()}},[i]);let m=()=>{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:p,className:"font-bookerly flex-1 text-[14px] leading-[1.5] 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:m,onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),m()),"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"===dy(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:"font-bookerly text-[14px] leading-[1.5] 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 md:opacity-0 md: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 dw(e){let{files:t,compact:r,onRemove:l,onClearAll:a}=e,[s,i]=(0,o.useState)(null);return 0===t.length?null:(0,n.jsxs)("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=dy(e.name),o=null!=(t=db[r])?t:db.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:()=>l(e.id),className:"absolute top-1 right-1 z-10 w-[18px] h-[18px] rounded-full flex items-center justify-center md:opacity-0 md: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 cursor-pointer transition-all duration-200 hover:opacity-95",style:{height:80,width:"auto",minWidth:60,maxWidth:140,opacity:e.uploading?.6:1,background:"var(--color-bg-secondary)"},onClick:()=>{i(e.localUrl||"/api/workspace/raw-file?path=".concat(encodeURIComponent(e.path)))},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:o.bg,color:o.fg},children:(0,n.jsx)(dj,{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)})}),(0,n.jsx)(cT.lG,{open:null!==s,onOpenChange:e=>{e||i(null)},children:(0,n.jsxs)(cT.Cf,{className:"!max-w-[90vw] !w-auto !p-0 !rounded-2xl !bg-transparent !border-none !shadow-[0_0_120px_rgba(0,0,0,0.4)]",showCloseButton:!1,children:[(0,n.jsx)("button",{type:"button",onClick:()=>i(null),className:"absolute top-3 right-3 z-10 w-7 h-7 rounded-full flex items-center justify-center cursor-pointer outline-none transition-all hover:opacity-85",style:{background:"rgba(0,0,0,0.55)",color:"white",backdropFilter:"blur(4px)",boxShadow:"0 2px 8px rgba(0,0,0,0.3)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})}),s&&(0,n.jsx)("img",{src:s,alt:"Preview",className:"block rounded-xl",style:{maxHeight:"80vh",maxWidth:"85vw",objectFit:"contain"}})]})})]})}let dN=(0,o.forwardRef)(function(e,t){var r,l,a;let{fileContext:s,compact:i,sessionTitle:c,initialSessionId:d,onFileChanged:u,onActiveSessionChange:p,onSessionsChange:h,onSubagentSpawned:m,onSubagentClick:x,onFilePathClick:f,onComposioAction:v,onDeleteSession:g,onRenameSession:y,sessionKey:b,subagentTask:j,subagentLabel:k,onBack:w,hideHeaderActions:N,headerLeftSlot:C,headerRightSlot:S,onRuntimeStateChange:M,onConversationActivity:T,gatewaySessionKey:L,gatewaySessionId:I,gatewayChannel:_,visible:R,searchFn:E,onNewChatSession:D}=e,A=!!b,F=!!L,P=(0,o.useRef)(null),[B,W]=(0,o.useState)(!0),[O,z]=(0,o.useState)(null),[U,H]=(0,o.useState)(!1),[V,K]=(0,o.useState)([]),J=(0,o.useRef)(null),[q,G]=(0,o.useState)(!1);(0,o.useEffect)(()=>{G(!0)},[]),(0,o.useEffect)(()=>{if(!1===R)return;let e=setTimeout(()=>{var e;null==(e=P.current)||e.focus()},150);return()=>clearTimeout(e)},[R]);let[$,Y]=(0,o.useState)(!1),Z=(0,o.useRef)(null),[Q,X]=(0,o.useState)(null),[ee,et]=(0,o.useState)(null),er=(0,o.useRef)(new Set),en=(0,o.useRef)(!1),eo=(0,o.useRef)(null),el=(0,o.useRef)(new Map),ea=(0,o.useRef)(null),es=(0,o.useRef)(null),[ei,ec]=(0,o.useState)([]),ed=(0,o.useRef)([]);(0,o.useEffect)(()=>{ed.current=ei},[ei]);let eu=(0,o.useRef)(null),ep=(0,o.useRef)(null),eh=(0,o.useRef)(!1),[em,ex]=(0,o.useState)(!1),[ef,ev]=(0,o.useState)(null),eg="What can I help with?",ey=(0,o.useCallback)(e=>{var t;null==(t=P.current)||t.setText(e),W(!1)},[]),eb=(0,o.useCallback)(e=>{var t;null==(t=P.current)||t.appendText(e),W(!1)},[]),ej=null!=(r=null==s?void 0:s.path)?r:null,ek=(0,o.useRef)(null);(0,o.useEffect)(()=>{ek.current=O},[O]);let ew=(0,o.useRef)(b);(0,o.useEffect)(()=>{ew.current=b},[b]);let eN=(0,o.useMemo)(()=>new s7.rL({api:"/api/chat",body:()=>{let e={},t=ew.current;t&&(e.sessionKey=t);let r=ek.current;return r&&(e.sessionId=r),ea.current&&(e.userHtml=ea.current,ea.current=null),es.current&&(e.workspaceContext=es.current,es.current=null),e},prepareSendMessagesRequest:e=>{let{messages:t,body:r}=e,n=t.filter(e=>"user"===e.role).pop();return{body:{...r,messages:n?[n]:[],hasAssistantHistory:t.some(e=>"assistant"===e.role)}}}}),[]),{messages:eC,sendMessage:eS,status:eM,stop:eT,error:eL,setMessages:eI}=(0,s8.Y_)({transport:eN}),[e_,eR]=(0,o.useState)(null);(0,o.useEffect)(()=>{eC.length>0&&null!==e_&&eR(null)},[eC.length,e_]);let eE="streaming"===eM||"submitted"===eM||$;(0,o.useEffect)(()=>{eh.current=eE},[eE]),(0,o.useEffect)(()=>{if("ready"!==eM)return;let e=!1,t=new AbortController;return(async()=>{try{let r=await fetch("/api/settings/cloud",{cache:"no-store",signal:t.signal});if(!r.ok)return;let n=await r.json(),o=function(e){let t=dv(e);if(!t)return null;let r=Array.isArray(t.models)?t.models.map(dg).filter(e=>null!==e):[];return{status:"no_key"===t.status||"invalid_key"===t.status||"valid"===t.status?t.status:"no_key",isDenchPrimary:!!t.isDenchPrimary,elevenLabsEnabled:!!t.elevenLabsEnabled,selectedDenchModel:"string"==typeof t.selectedDenchModel&&t.selectedDenchModel.trim()?t.selectedDenchModel.trim():null,models:r}}(n);!e&&o&&ev(o)}catch(e){}})(),()=>{e=!0,t.abort()}},[eM,eC.length,O]);let eD=!!((null==ef?void 0:ef.status)==="valid"&&ef.elevenLabsEnabled),eA=!!((null==ef?void 0:ef.status)==="valid"&&ef.elevenLabsEnabled),eF=(0,o.useRef)(M);eF.current=M,(0,o.useEffect)(()=>{var e;null==(e=eF.current)||e.call(eF,{sessionId:O,sessionKey:null!=b?b:null,isStreaming:eE,status:eM,isReconnecting:$,loadingSession:U})},[O,b,eE,eM,$,U]);let eP=(0,o.useRef)(null);(0,o.useEffect)(()=>(eP.current&&(clearTimeout(eP.current),eP.current=null),"submitted"===eM&&(eP.current=setTimeout(()=>{eP.current=null,"submitted"===eM&&(X("Request timed out — no response from agent. Try again or check the gateway."),eT())},9e4)),()=>{eP.current&&(clearTimeout(eP.current),eP.current=null)}),[eM,eT]);let eB=(0,o.useRef)(null),eW=(0,o.useRef)(!0),eO=(0,o.useRef)(!1),ez=(0,o.useRef)(null),eU=(0,o.useRef)(0),[eH,eV]=(0,o.useState)(!1),eK=(0,o.useCallback)(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"smooth",t=eB.current;t&&(eW.current=!0,eV(!1),df(t,e))},[]);(0,o.useEffect)(()=>{let e=eB.current;if(!e)return;let t=()=>{eO.current=!0,ez.current&&clearTimeout(ez.current),ez.current=setTimeout(()=>{eO.current=!1},200)},r=()=>{if(!eO.current)return;let t=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:80;return function(e){let{clientHeight:t,scrollHeight:r,scrollTop:n}=e;return r-n-t}(e)>t}(e);eW.current=!t,eV(t)};return e.addEventListener("wheel",t,{passive:!0}),e.addEventListener("touchstart",t,{passive:!0}),e.addEventListener("touchmove",t,{passive:!0}),e.addEventListener("pointerdown",t,{passive:!0}),e.addEventListener("keydown",t),e.addEventListener("scroll",r,{passive:!0}),()=>{ez.current&&clearTimeout(ez.current),e.removeEventListener("wheel",t),e.removeEventListener("touchstart",t),e.removeEventListener("touchmove",t),e.removeEventListener("pointerdown",t),e.removeEventListener("keydown",t),e.removeEventListener("scroll",r)}},[]),(0,o.useEffect)(()=>{let e=eB.current;if(!e)return;let t=new ResizeObserver(()=>{eU.current||(eU.current=requestAnimationFrame(()=>{eU.current=0;let e=eB.current;e&&eW.current&&(eO.current||df(e,"auto"))}))});t.observe(e);let r=e.firstElementChild;return r instanceof HTMLElement&&t.observe(r),()=>{eU.current&&(cancelAnimationFrame(eU.current),eU.current=0),t.disconnect()}},[]),(0,o.useEffect)(()=>{eW.current&&(eU.current||(eU.current=requestAnimationFrame(()=>{eU.current=0,eK("auto")})))},[eC,eK]);let eJ=(0,o.useCallback)(async e=>{let t=await fetch("/api/web-sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:e})});return(await t.json()).session.id},[]),eq=(0,o.useCallback)(async(e,t,r)=>{let n=new AbortController;Z.current=n;try{let o=null==r?void 0:r.sessionKey,l=!o||o.includes(":subagent:")||o.includes(":web:")?o?"/api/chat/stream?sessionKey=".concat(encodeURIComponent(o)):"/api/chat/stream?sessionId=".concat(encodeURIComponent(e)):"/api/gateway/chat/stream?sessionKey=".concat(encodeURIComponent(o)),a=await fetch(l,{signal:n.signal});if(!a.ok||!a.body)return!1;if("false"===a.headers.get("X-Run-Active"))return a.body.cancel(),!1;Y(!0);let s=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":for(let t=e.length-1;t>=0;t--){let r=e[t];if("dynamic-tool"===r.type&&r.toolCallId===n.toolCallId){r.toolName=n.toolName,r.state="input-available",r.input||(r.input={});return}}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.preliminary=!0,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){!0===n.preliminary?(r.preliminary=!0,r.state="input-available"):(delete r.preliminary,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}))}}(),i=a.body.getReader(),c=new TextDecoder,d="reconnect-".concat(e),u="",p=!1,h=()=>{if(n.signal.aborted)return;let e={id:d,role:"assistant",parts:s.getParts()};eI([...t,e])};for(;;){let e,{done:t,value:r}=await i.read();if(t)break;for(u+=c.decode(r,{stream:!0});-1!==(e=u.indexOf("\n\n"));){let t=u.slice(0,e);if(u=u.slice(e+2),t.startsWith("data: "))try{let e=JSON.parse(t.slice(6));s.processEvent(e)}catch(e){}}p||(p=!0,requestAnimationFrame(()=>{p=!1,h()}))}if(h(),!n.signal.aborted){for(let e of t)er.current.add(e.id);er.current.add(d)}return Y(!1),Z.current=null,!0}catch(e){return"AbortError"!==e.name&&console.error("Reconnection error:",e),Y(!1),Z.current=null,!1}},[eI]),eG=(0,o.useRef)(!1),e$=(0,o.useRef)(null);(0,o.useEffect)(()=>{!A&&!F&&d&&(eG.current&&d===e$.current||(eG.current=!0,e$.current=d,e5(d)))},[d]),(0,o.useEffect)(()=>{var e;if(!b||!j)return;let t=!1;null==(e=Z.current)||e.abort(),eT(),er.current.clear(),ec([]);let r={id:"task-".concat(b),role:"user",parts:[{type:"text",text:j}]};return eI([r]),(async()=>{if(t)return;let e=[r];try{let n=await fetch("/api/web-sessions/".concat(encodeURIComponent(b)));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&&el.current.set(e.id,e.html);let n=l.map(e=>{var t;return er.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||eI(e)}}}catch(e){}t||await eq(b,e,{sessionKey:b})})(),()=>{var e;t=!0,null==(e=Z.current)||e.abort()}},[b,j,eq]),(0,o.useEffect)(()=>{var e;if(!L||!I)return;let t=!1;return null==(e=Z.current)||e.abort(),eT(),er.current.clear(),ec([]),H(!0),(async()=>{let e=[];try{let r=await fetch("/api/gateway/sessions/".concat(encodeURIComponent(I)));if(t)return;r.ok&&(e=((await r.json()).messages||[]).map(e=>{var t;return er.current.add(e.id),{id:e.id,role:e.role,parts:null!=(t=e.parts)?t:[{type:"text",text:e.content}]}}),t||eI(e))}catch(e){}t||(H(!1),await eq(L,e,{sessionKey:L}))})(),()=>{var e;t=!0,null==(e=Z.current)||e.abort()}},[L,I,eq]);let[eY,eZ]=(0,o.useState)(!1);(0,o.useEffect)(()=>{if(!O||!m)return;let e=!1,t=async()=>{try{var t;let r=await fetch("/api/chat/subagents?sessionId=".concat(encodeURIComponent(O)));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),m({childSessionKey:e.sessionKey,runId:e.runId,task:e.task,label:e.label,parentSessionId:O,status:e.status});e||eZ(o)}catch(e){}};t();let r=setInterval(t,3e3);return()=>{e=!0,clearInterval(r)}},[O,m]);let eQ=(0,o.useRef)(eM),eX=eQ.current;(0,o.useEffect)(()=>{let e="ready"===eM;if(("streaming"===eX||"submitted"===eX)&&e&&O){for(let e of eC)er.current.add(e.id);ej&&u&&fetch("/api/workspace/file?path=".concat(encodeURIComponent(ej))).then(e=>e.json()).then(e=>{e.content&&u(e.content)}).catch(()=>{}),null==h||h()}},[eX,eM,eC,O,ej,u,h]);let e0=(0,o.useRef)(null);(0,o.useEffect)(()=>{e0.current&&(clearTimeout(e0.current),e0.current=null);let e="ready"===eM;return("streaming"===eX||"submitted"===eX)&&e&&(e0.current=setTimeout(()=>{var e;e0.current=null;let t=eC[eC.length-1],r=!!((null==(e=null!=t?t:null)?void 0:e.role)==="assistant"&&e.parts.some(e=>"reasoning"===e.type||"dynamic-tool"===e.type||e.type.startsWith("tool-")||"tool-invocation"===e.type)),n=r?cy(null!=t?t:null):cg(null!=t?t:null),o=function(e){if(!e||"assistant"!==e.role||-1===cx(e.parts)||cy(e))return null;if(function(e){if(!e)return!1;if("error"===cv(e))return!0;if("tool-invocation"===e.type){let t=e.result;if(t&&"object"==typeof t){let e="string"==typeof t.status?t.status.toLowerCase():null;if("error"===e||"failed"===e)return!0}}return!1}(function(e){for(let t=e.length-1;t>=0;t--){let r=e[t];if(cm(r))return r}return null}(e.parts)))return"Tool execution failed and the agent stopped without summarizing the failure.";let t=e.parts.filter(e=>cm(e)).map(e=>cf(e)).filter(e=>!!e);return t.includes("composio_search_tools")&&!t.includes("composio_call_tool")?"Search completed but the agent never followed through with the tool call.":"Agent finished tool activity but did not send a final text reply."}(null!=t?t:null);n||r||eL?n||!r||eL?X(null):X(null!=o?o:"Agent finished tool activity but did not send a final text reply."):X("No response received from agent.")},50)),"submitted"===eM&&X(null),()=>{e0.current&&(clearTimeout(e0.current),e0.current=null)}},[eX,eM,eC,eL]),(0,o.useEffect)(()=>{eQ.current=eM},[eM]);let e1=(0,o.useRef)(()=>{}),e2=(0,o.useCallback)(async(e,t,r,n)=>{let o=e.trim().length>0,l=t.length>0,a=n?n.filter(e=>!e.uploading&&e.path):V.filter(e=>!e.uploading&&e.path),i=a.length>0;if(!o&&!l&&!i){if(eE&&ed.current.length>0){let[e,...t]=ed.current;ec(t),(async()=>{var t,r;await (null==(t=eu.current)?void 0:t.call(eu));let n=Date.now()+2e3;for(;Date.now()<n&&eh.current;)await new Promise(e=>setTimeout(e,30));await (null==(r=ep.current)?void 0:r.call(ep,e.text,e.mentionedFiles,e.html,e.attachedFiles))})()}return}let c=e.trim(),d=[...a];if("/new"===c.toLowerCase()){for(let e of V)e.localUrl&&URL.revokeObjectURL(e.localUrl);K([]),e1.current();return}if(null==T||T(),eE){n||K([]),ec(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 V)e.localUrl&&URL.revokeObjectURL(e.localUrl);K([])}let u=O;if(!u&&!A&&!F){let e=c||"File attachment",t=e.length>60?e.slice(0,60)+"...":e;c&&eR(c),z(u=await eJ(t)),ek.current=u,null==p||p(u),null==h||h()}let m=[...t.map(e=>e.path),...d.map(e=>e.path)],x=c;if(m.length>0){let e="[Attached files: ".concat(m.join(", "),"]");x=x?"".concat(e,"\n\n").concat(x):e}let f=!!s&&eo.current!==s.path,v={};if(f&&s&&(v.filePath=s.path,v.isDirectory=s.isDirectory),(null==s?void 0:s.tableSelection)&&(v.tableSelection=s.tableSelection),f&&s&&(eo.current=s.path),ea.current=r,eW.current=!0,L){let e=x;if(f&&s){let t=s.isDirectory?"directory":"file";e="[Context: workspace ".concat(t," '").concat(s.path,"']\n\n").concat(e)}(null==s?void 0:s.tableSelection)&&(e="".concat(function(e){var t,r;if("rows"===e.kind){let r=null!=(t=e.rows)?t:[],n=r.slice(0,10).map(t=>{let r=e.columns.map(e=>{var r;return"".concat(e,": ").concat(null!=(r=t.values[e])?r:"")}).join("; ");return"- row ".concat(t.rowIndex+1," (").concat(t.entryId,"): ").concat(r)}),o=r.length>n.length?"\n- ...".concat(r.length-n.length," more selected rows"):"";return["[Selected table rows: ".concat(e.objectName,"]"),"".concat(e.rowCount," row").concat(1===e.rowCount?"":"s"," selected."),"Columns: ".concat(e.columns.join(", ")),...n].join("\n")+o}let n=null!=(r=e.cells)?r:[],o=n.slice(0,30).map(e=>"- row ".concat(e.rowIndex+1," (").concat(e.entryId,"), ").concat(e.fieldName,": ").concat(e.value)),l=n.length>o.length?"\n- ...".concat(n.length-o.length," more selected cells"):"";return["[Selected table cells: ".concat(e.objectName,"]"),"".concat(e.rowCount," row").concat(1===e.rowCount?"":"s"," x ").concat(e.columnCount," column").concat(1===e.columnCount?"":"s"," selected."),"Columns: ".concat(e.columns.join(", ")),...o].join("\n")+l}(s.tableSelection),"\n\n").concat(e)),el.current.set(e,r);let t={id:"user-".concat(Date.now()),role:"user",parts:[{type:"text",text:e}]};eI(e=>[...e,t]);try{let t=await fetch("/api/gateway/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionKey:L,message:e})});if(t.ok&&t.body)X(null),await eq(L,[],{sessionKey:L});else{let e=await t.text().catch(()=>"");X(e||"Failed to send message.")}}catch(e){X("Failed to send message.")}}else el.current.set(x,r),Object.keys(v).length>0&&(es.current=v),eS({text:x});setTimeout(()=>{var e;null==(e=P.current)||e.focus()},200)},[V,eE,O,eJ,p,h,s,eS,L,eq,T,A,eI]);(0,o.useEffect)(()=>{ep.current=e2},[e2]);let e4=(0,o.useRef)(eM);(0,o.useEffect)(()=>{let e="streaming"===e4.current||"submitted"===e4.current,t="ready"===eM;if(e4.current=eM,e&&t&&ei.length>0){let[e,...t]=ei;for(let r of(ec(t),e.attachedFiles))r.localUrl&&URL.revokeObjectURL(r.localUrl);queueMicrotask(()=>{e2(e.text,e.mentionedFiles,e.html,e.attachedFiles)})}},[eM,ei,e2]);let e5=(0,o.useCallback)(async e=>{var t;if(e!==O){null==(t=Z.current)||t.abort(),eT(),H(!0),z(e),ek.current=e,null==p||p(e),er.current.clear(),eo.current=null,ec([]);try{let t=await fetch("/api/web-sessions/".concat(e));if(!t.ok){console.warn("Session ".concat(e," not found (").concat(t.status,"), starting fresh.")),eI([]),H(!1);return}let r=(await t.json()).messages||[],n=r.some(e=>e._streaming)?r.filter(e=>!e._streaming):r;for(let e of(el.current.clear(),n))"user"===e.role&&e.html&&el.current.set(e.id,e.html);let o=n.map(e=>{var t;return er.current.add(e.id),{id:e.id,role:e.role,parts:null!=(t=e.parts)?t:[{type:"text",text:e.content}]}});eI(o),H(!1),await eq(e,o)}catch(e){console.error("Error loading session:",e),H(!1)}}},[O,eI,p,eT,eq]),e3=(0,o.useCallback)(()=>{var e;null==(e=Z.current)||e.abort(),eT(),Y(!1),z(null),ek.current=null,null==p||p(null),eI([]),er.current.clear(),el.current.clear(),eo.current=null,en.current=!1,ec([]),requestAnimationFrame(()=>{var e;null==(e=P.current)||e.focus()})},[eI,p,eT]);e1.current=e3,(0,o.useImperativeHandle)(t,()=>({loadSession:e5,newSession:async()=>{e3()},sendNewMessage:async e=>{null==T||T(),e3();let t=e.length>60?e.slice(0,60)+"...":e,r=await eJ(t);z(r),ek.current=r,null==p||p(r),null==h||h(),eW.current=!0,eS({text:e})},insertFileMention:(e,t)=>{var r;null==(r=P.current)||r.insertFileMention(e,t)}}),[e5,e3,eJ,p,h,T,eS]);let e6=(0,o.useCallback)(async()=>{var e;null==(e=Z.current)||e.abort(),Y(!1);let t=ew.current,r=ek.current;if(t||r)try{await fetch("/api/chat/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t?{sessionKey:t}:{sessionId:r})})}catch(e){}eT()},[eT]);(0,o.useEffect)(()=>{eu.current=e6},[e6]);let e8=(0,o.useCallback)(e=>{ec(t=>t.filter(t=>t.id!==e))},[]),e7=(0,o.useCallback)((e,t)=>{ec(r=>r.map(r=>r.id===e?{...r,text:t}:r))},[]),e9=(0,o.useCallback)(async e=>{let t=ei.find(t=>t.id===e);t&&(ec(t=>t.filter(t=>t.id!==e)),await e6(),setTimeout(()=>{e2(t.text,t.mentionedFiles,t.html,t.attachedFiles)},100))},[ei,e6,e2]),te=(0,o.useCallback)(e=>{K(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)})},[]),tt=(0,o.useCallback)(()=>{K(e=>{for(let t of e)t.localUrl&&URL.revokeObjectURL(t.localUrl);return[]})},[]),tr=(0,o.useCallback)(async e=>{et(null);let{files:t,errors:r}=await dx(e);if(r.length>0&&et(1===r.length?r[0]:"".concat(r.length," images couldn't be prepared for vision. ").concat(r[0])),0===t.length)return;let n=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)}));K(e=>[...e,...n]);for(let e=0;e<t.length;e++){let r=t[e],o=n[e].id,l=n[e].localUrl,a=new FormData;a.append("file",r),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?K(t=>t.map(t=>t.id===o?{...t,path:e.path,uploading:!1}:t)):(K(e=>e.filter(e=>e.id!==o)),l&&URL.revokeObjectURL(l))}).catch(()=>{K(e=>e.filter(e=>e.id!==o)),l&&URL.revokeObjectURL(l)})}},[]),tn=function(e){let{loadingSession:t,isReconnecting:r,status:n,hasRunningSubagents:o,lastMessage:l}=e;if(t)return"Loading session...";if(r)return"Resuming stream...";if(o)return"Waiting for subagents...";if((null==l?void 0:l.role)==="assistant"){let e=function(e){for(let t=e.length-1;t>=0;t--){let r=e[t];if("reasoning"!==r.type)continue;let n="string"==typeof r.text?cp(r.text):"";if(n&&cb(n))return n}return null}(l.parts);if(e)return e;let t=function(e){for(let t=e.length-1;t>=0;t--){let r=e[t],n=cv(r);if(!n||"output-available"===n||"error"===n)continue;let o=cf(r);if(o){if("sessions_spawn"===o)return"Starting subagent...";return"Running ".concat(function(e){let t=e.replace(/^tool-/,"").replace(/[_-]+/g," ").trim();return t?t.replace(/\b\w/g,e=>e.toUpperCase()):"tool"}(o),"...")}}return null}(l.parts);if(t)return t}return"submitted"===n?"Thinking...":"streaming"===n?cg(l)?"Still streaming...":"Streaming...":null}({loadingSession:U,isReconnecting:$,status:eM,hasRunningSubagents:eY,lastMessage:eC.length>0?eC[eC.length-1]:null}),to=eE&&!!tn,tl=0===eC.length&&!A&&!U&&null===e_,ta=(0,n.jsxs)(n.Fragment,{children:[ei.length>0&&(0,n.jsx)("div",{className:i?"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 (",ei.length,")"]}),(0,n.jsx)("div",{className:"flex flex-col p-2",children:ei.map((e,t)=>(0,n.jsx)(dk,{msg:e,idx:t,onEdit:e7,onSendNow:e9,onRemove:e8},e.id))})]})}),!A&&(0,n.jsx)(dw,{files:V,compact:i,onRemove:te,onClearAll:tt}),(0,n.jsx)(dr,{ref:P,onSubmit:e2,onChange:e=>W(e),onNativeFileDrop:A?void 0:tr,placeholder:tl?"Build a workflow to automate your tasks":A?eE?"Type to queue a message...":"Type @ to mention files...":s?"Ask about ".concat(s.isDirectory?"this folder":s.filename,"..."):eE?"Type to queue a message...":V.length>0?"Add a message or send files...":"Type @ to mention files...",disabled:U,compact:i,searchFn:E}),(0,n.jsxs)("div",{className:"flex items-center justify-between ".concat(i?"px-2 pb-1.5":"px-3 pb-2.5"),children:[(0,n.jsx)("div",{className:"flex items-center gap-0.5",children:!A&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{ref:J,type:"file",multiple:!0,className:"hidden",onChange:e=>{e.target.files&&e.target.files.length>0&&tr(e.target.files),e.target.value=""}}),(0,n.jsx)("button",{type:"button",onClick:()=>{var e;return null==(e=J.current)?void 0:e.click()},className:"p-1.5 rounded-lg hover:opacity-80 transition-opacity",style:{color:V.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:[(0,n.jsx)(dl,{compact:i,disabled:U,preferServerTranscription:eD,onTranscript:eb}),eE?(0,n.jsx)("button",{type:"button",onClick:()=>e6(),className:"".concat(i?"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"})})}):(0,n.jsx)("button",{type:"button",onClick:()=>{var e;return null==(e=P.current)?void 0:e.submit()},disabled:B&&0===V.length||U,className:"".concat(i?"w-6 h-6":"w-7 h-7"," rounded-full flex items-center justify-center disabled:opacity-50 disabled:cursor-not-allowed"),style:{background:!B||V.length>0?"linear-gradient(to top, #0065A2, #0075AA)":"var(--color-text-muted)",color:!B||V.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"})]})})]})]})]}),ts=(e,t,r)=>(0,n.jsx)("div",{"data-chat-drop-target":"",className:"".concat(i?"rounded-2xl":"rounded-3xl"," overflow-hidden border shadow-[0_0_32px_rgba(0,0,0,0.07)] transition-[outline,box-shadow,border-color] duration-150 ease-out focus-within:border-[var(--color-border-strong)]! 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:"color-mix(in srgb, var(--color-surface) 75%, transparent)",backdropFilter:"blur(16px) saturate(180%)",WebkitBackdropFilter:"blur(16px) saturate(180%)",borderColor:"var(--color-border)"},onDragOver:e,onDragLeave:t,onDrop:r,children:ta}),ti=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",""))},tc=e=>{e.currentTarget.contains(e.relatedTarget)||e.currentTarget.removeAttribute("data-drag-hover")},td=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=P.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(),tr(l))};return(0,n.jsxs)("div",{className:"@container relative h-full min-h-0 flex flex-col overflow-hidden",style:{background:"var(--color-main-bg)"},children:[(0,n.jsxs)("header",{className:"".concat("pl-4 pr-2"," h-10 flex shrink-0 items-center gap-2 ").concat(A?"":"justify-between"," z-20"),children:[C&&(0,n.jsx)("div",{className:"flex items-center shrink-0",children:C}),A?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:w,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:k||(j&&j.length>60?j.slice(0,60)+"...":j)}),(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:eE?(0,n.jsx)(da.V,{name:"braille"}):"Completed"})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"min-w-0 flex-1",children:O?(0,n.jsx)("h2",{className:"text-sm font-semibold truncate",style:{color:"var(--color-text)"},title:c||"Chat Session",children:c||"Chat Session"}):null}),!N&&(0,n.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[D&&(0,n.jsx)("button",{type:"button",onClick:D,className:"p-1.5 rounded-lg cursor-pointer transition-colors",style:{color:"var(--color-text-muted)"},title:"New chat","aria-label":"New chat",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:(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:"M5 12h14"}),(0,n.jsx)("path",{d:"M12 5v14"})]})}),O&&g&&(0,n.jsxs)(tG.rI,{children:[(0,n.jsx)(tG.ty,{className:"p-1.5 rounded-lg cursor-pointer transition-colors",style:{color:"var(--color-text-muted)"},title:"More options","aria-label":"More options",onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},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)(tG.SQ,{align:"end",side:"bottom",children:(0,n.jsxs)(tG._2,{variant:"destructive",onSelect:()=>g(O),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 this chat"]})})]})]})]}),S&&(0,n.jsx)("div",{className:"flex items-center shrink-0",children:S})]}),(0,n.jsxs)("div",{ref:eB,className:"min-h-0 min-w-0 flex-1 overflow-y-auto",style:{scrollbarGutter:"stable",paddingBottom:140*!tl},children:[(0,n.jsx)("div",{className:i?"px-3":"px-6",children:U?(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)(da.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..."})]})}):tl&&!q?(0,n.jsx)("div",{className:"flex items-center justify-center h-full ".concat(i?"min-h-[40vh]":"min-h-[60vh]")}):tl?(0,n.jsxs)("div",{className:"relative flex flex-col items-center justify-center py-8 md:py-12 ".concat(i?"min-h-[60vh]":"min-h-[75vh]"),children:[eg&&(0,n.jsx)("h1",{className:"font-bookerly font-medium mb-2 md:mb-3 text-center px-4",style:{color:"var(--color-text)",fontSize:"clamp(1.5rem, 3.5cqw + 0.85rem, 3rem)",letterSpacing:"-0.03em"},children:eg}),(0,n.jsx)("div",{className:"w-full max-w-[720px] mx-auto px-3 md:px-4",children:ts(ti,tc,td)}),(0,n.jsx)(im,{compact:!!i,onPromptClick:ey}),(0,n.jsx)(iA,{className:"absolute inset-x-0 bottom-6 md:bottom-10"})]}):null!==e_&&0===eC.length?(0,n.jsxs)("div",{className:"".concat(i?"":"max-w-2xl mx-auto"," py-3"),children:[(0,n.jsx)("div",{className:"flex justify-end py-2",children:(0,n.jsx)("div",{className:"max-w-[85%] rounded-2xl px-4 py-2 text-sm whitespace-pre-wrap break-words",style:{background:"var(--color-surface-hover)",color:"var(--color-text)"},children:e_})}),(0,n.jsx)("div",{className:"py-3 min-w-0",children:(0,n.jsxs)("div",{className:"inline-flex max-w-full items-center gap-1.5 px-1 py-1.5 dench-shimmer",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)("img",{src:"/dench-workspace-icon.png",alt:"",width:14,height:14,className:"rounded-sm"}),(0,n.jsx)("span",{className:"text-xs truncate",children:"Preparing response…"})]})})]}):0===eC.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(i?"":"max-w-2xl mx-auto"," py-3"),children:[em?(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(eC,null,2)}):(()=>{let e=new Set,t=[];for(let r=eC.length-1;r>=0;r--){let n=eC[r];e.has(n.id)||(e.add(n.id),t.unshift(n))}return t.map((e,r)=>(0,n.jsx)(cZ,{message:e,isStreaming:eE&&r===t.length-1,onSubagentClick:x,onFilePathClick:f,onComposioAction:v,sessionId:O,voicePlaybackEnabled:eA,userHtmlMap:el.current,copyable:!0},e.id))})(),to&&(0,n.jsx)("div",{className:"py-3 min-w-0",children:(0,n.jsxs)("div",{className:"inline-flex max-w-full items-center gap-1.5 px-1 py-1.5 dench-shimmer",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)("img",{src:"/dench-workspace-icon.png",alt:"",width:14,height:14,className:"rounded-sm"}),(0,n.jsx)("span",{className:"text-xs truncate",children:tn})]})})]})}),(eL||Q||ee)&&(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!=(a=null!=(l=null==eL?void 0:eL.message)?l:Q)?a:ee})]})]}),!tl&&(0,n.jsx)("div",{className:"absolute inset-x-0 bottom-0 pointer-events-none z-10",style:{height:140,background:"linear-gradient(to top, var(--color-main-bg) 0%, var(--color-main-bg) 35%, color-mix(in srgb, var(--color-main-bg) 60%, transparent) 70%, transparent 100%)"}}),!tl&&(0,n.jsx)("div",{className:"".concat(i?"px-3 py-2":"px-3 pb-3 pt-3 @md:px-6 @md:pb-5"," absolute inset-x-0 bottom-0 z-20 pointer-events-none"),children:(0,n.jsxs)("div",{className:"".concat(i?"":"max-w-[720px] mx-auto"," pointer-events-auto relative"),children:[eH&&(0,n.jsx)("div",{className:"absolute inset-x-0 -top-10 flex justify-center pointer-events-none z-30",children:(0,n.jsx)("button",{type:"button",onClick:()=>eK(),className:"pointer-events-auto w-8 h-8 rounded-full flex items-center justify-center shadow-md border transition-colors",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",color:"var(--color-text-muted)"},title:"Scroll to bottom",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:"m19 12-7 7-7-7"})]})})}),ts(ti,tc,td)]})})]})});var dC=r(52597);function dS(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 dM=["created_at","Created","createdAt","created"],dT=["updated_at","Updated","updatedAt","updated"],dL=[{value:"text",label:"Text"},{value:"number",label:"Number"},{value:"email",label:"Email"},{value:"phone",label:"Phone"},{value:"date",label:"Date"},{value:"boolean",label:"Boolean"},{value:"enum",label:"Select"},{value:"tags",label:"Tags"},{value:"url",label:"URL"},{value:"richtext",label:"Rich Text"},{value:"action",label:"Action"}];function dI(e,t){for(let r of t){let t=e[r];if(null!=t&&""!==t)return t}}function d_(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 dR(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-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:"text-sm",children:null!=(r=null==s?void 0:s.name)?r:a})]})}function dE(e){let{value:t,field:r,relationLabels:o,relationFaviconUrls:l,onNavigateEntry:a}=e,s=null==o?void 0:o[r.name],i=null==l?void 0:l[r.name],c=null==t?[]: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===c.length?(0,n.jsx)(dF,{}):(0,n.jsx)("span",{className:"flex items-center gap-x-3 gap-y-1 flex-wrap",children:c.map(e=>{var t;let o=null!=(t=null==s?void 0:s[e])?t:e,l=r.related_object_name&&a?t=>{t.stopPropagation(),a(r.related_object_name,e,r.related_object_id)}:void 0;return(0,n.jsx)(nh,{label:o,faviconUrl:null==i?void 0:i[e],onClick:l,maxLabelWidth:220},e)})})}function dD(e){let{value:t}=e,r=rq(t);if(0===r.length)return(0,n.jsx)(dF,{});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 flex-wrap",children:r.map(e=>{let t=rL(e),r="link"===t.kind&&t.href,l="url"===t.linkType&&!!t.faviconUrl,a="url"===t.linkType||"file"===t.linkType;if(r){let r=(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-xs font-medium max-w-[240px]",style:{...o,color:"var(--color-accent)"},children:[l&&(0,n.jsx)(t$,{src:t.faviconUrl,className:"w-3.5 h-3.5 rounded-[3px] shrink-0"}),(0,n.jsx)("span",{className:"min-w-0 truncate",children:t.text}),(0,n.jsx)(r_,{href:t.href,openInNewTab:a,className:"inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-sm hover:bg-black/5"})]});return"url"===t.linkType?(0,n.jsx)(rU,{href:t.href,children:r},e):(0,n.jsx)("span",{children:r},e)}return(0,n.jsx)("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium",style:{...o,color:"var(--color-text-muted)"},children:e},e)})})}function dA(e){let{value:t,onChange:r,autoFocus:l}=e,a=rq(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.5rem]",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:"9",height:"9",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-[60px] text-xs outline-none bg-transparent",style:{color:"var(--color-text)"}})]})}function dF(){return(0,n.jsx)("span",{style:{color:"var(--color-text-muted)",opacity:.5},className:"text-sm",children:"Empty"})}function dP(e){let{value:t,field:r,members:o,relationLabels:l,relationFaviconUrls:a,onNavigateEntry:s}=e;if(null==t||""===t)return(0,n.jsx)(dF,{});switch(r.type){case"enum":return(0,n.jsx)(d_,{value:dS(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)(dR,{value:t,members:o});case"relation":return(0,n.jsx)(dE,{value:t,field:r,relationLabels:l,relationFaviconUrls:a,onNavigateEntry:s});case"tags":return(0,n.jsx)(dD,{value:t});default:return(0,n.jsx)(rJ,{value:t,fieldType:r.type,mode:"detail",showUrlFavicon:!0,linkInteractionMode:"button"})}}function dB(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-[11px] font-medium uppercase tracking-wider mb-1",style:{color:"var(--color-text-muted)"},children:[(0,n.jsxs)("svg",{width:"9",height:"9",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",{children:(0,M.PV)(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 flex-wrap text-sm min-h-[1.5rem]",children:[o.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>null==r?void 0:r(t.sourceObjectName,e.id,t.sourceObjectId),className:"inline-flex items-center gap-1 px-2 py-0.5 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((0,M.PV)(t.sourceObjectName)),children:[(0,n.jsxs)("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",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-[180px]",children:e.label})]},e.id)),l>0&&(0,n.jsxs)("span",{className:"text-xs px-1 py-0.5 rounded",style:{color:"var(--color-text-muted)"},children:["+",l," more"]})]})]})}function dW(e){let{objectName:t,onCreated:r,onCancel:l}=e,[a,s]=(0,o.useState)(""),[i,c]=(0,o.useState)("text"),[d,u]=(0,o.useState)(""),[p,h]=(0,o.useState)(!1),[m,x]=(0,o.useState)(null),f=(0,o.useRef)(null);(0,o.useEffect)(()=>{var e;null==(e=f.current)||e.focus()},[]);let v=async e=>{if(e.preventDefault(),!a.trim())return;let n={name:a.trim(),type:i};if("enum"===i){let e=d.split(",").map(e=>e.trim()).filter(Boolean);if(0===e.length)return void x("Add at least one option");n.enum_values=e}h(!0),x(null);try{let e=await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/fields"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!e.ok){var o;let t=await e.json().catch(()=>({error:"Failed"}));x(null!=(o=t.error)?o:"Failed to create field");return}r()}catch(e){x("Network error")}finally{h(!1)}};return(0,n.jsxs)("form",{onSubmit:v,className:"flex flex-col gap-2 p-3 rounded-lg",style:{background:"var(--color-surface-hover)",border:"1px solid var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{ref:f,type:"text",value:a,onChange:e=>s(e.target.value),placeholder:"Property name",className:"flex-1 px-2 py-1 text-sm rounded-md outline-none",style:{background:"var(--color-bg)",color:"var(--color-text)",border:"1px solid var(--color-border)"}}),(0,n.jsx)("select",{value:i,onChange:e=>c(e.target.value),className:"px-2 py-1 text-sm rounded-md outline-none",style:{background:"var(--color-bg)",color:"var(--color-text)",border:"1px solid var(--color-border)"},children:dL.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))})]}),"enum"===i&&(0,n.jsx)("input",{type:"text",value:d,onChange:e=>u(e.target.value),placeholder:"Options (comma-separated)",className:"px-2 py-1 text-sm rounded-md outline-none",style:{background:"var(--color-bg)",color:"var(--color-text)",border:"1px solid var(--color-border)"}}),m&&(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-error)"},children:m}),(0,n.jsxs)("div",{className:"flex items-center gap-2 justify-end",children:[(0,n.jsx)("button",{type:"button",onClick:l,className:"px-2 py-1 text-xs rounded-md",style:{color:"var(--color-text-muted)"},children:"Cancel"}),(0,n.jsx)("button",{type:"submit",disabled:p||!a.trim(),className:"px-3 py-1 text-xs rounded-md font-medium disabled:opacity-50",style:{background:"var(--color-accent)",color:"white"},children:p?"Adding...":"Add"})]})]})}function dO(){return(0,n.jsx)("div",{className:"space-y-3",children:[1,2,3,4].map(e=>(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("div",{className:"w-24 h-3 rounded animate-pulse",style:{background:"var(--color-surface-hover)"}}),(0,n.jsx)("div",{className:"flex-1 h-4 rounded animate-pulse",style:{background:"var(--color-surface-hover)"}})]},e))})}function dz(e){let{objectName:t,entryId:r,members:l,tree:a,searchFn:s,onClose:i,onNavigateEntry:c,onNavigateObject:d,onRefresh:u,onNavigate:p}=e,[h,m]=(0,o.useState)(null),[x,f]=(0,o.useState)(!0),[v,g]=(0,o.useState)(null),[y,b]=(0,o.useState)(null),[j,k]=(0,o.useState)(""),[w,N]=(0,o.useState)(!1),[C,S]=(0,o.useState)(!1),[T,L]=(0,o.useState)(!1),I=r3(),[_,R]=(0,o.useState)(""),[E,D]=(0,o.useState)("".concat(t,"/").concat(r,".md")),[A,F]=(0,o.useState)(!0);(0,o.useEffect)(()=>{let e=!1;return f(!0),g(null),(async()=>{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;g(null!=(n=t.error)?n:"Failed to load entry"),f(!1)}return}let l=await o.json();e||(m(l),f(!1))}catch(t){e||(g("Network error"),f(!1))}})(),()=>{e=!0}},[t,r]),(0,o.useEffect)(()=>{let e=!1;return F(!0),(async()=>{try{let o=await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/entries/").concat(encodeURIComponent(r),"/content"));if(o.ok){let t=await o.json();if(!e){var n;R(null!=(n=t.content)?n:""),t.path&&D(t.path)}}}catch(e){}finally{e||F(!1)}})(),()=>{e=!0}},[t,r]),(0,o.useEffect)(()=>{let e=e=>{"Escape"!==e.key||y||T||i()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[i,y,T]);let P=(0,o.useCallback)(async(e,n)=>{N(!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&&(m(t=>t?{...t,entry:{...t.entry,[e]:n}}:t),b(null),null==u||u())}catch(e){}finally{N(!1)}},[t,r,u]),[B,W]=(0,o.useState)(null),O=(0,o.useCallback)(()=>{W({open:!0,title:"Delete this entry?",message:"This action cannot be undone. The entry will be permanently removed.",variant:"destructive",confirmLabel:"Delete",onConfirm:async()=>{W(null),S(!0);try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/entries/").concat(encodeURIComponent(r)),{method:"DELETE"}),null==u||u(),i()}catch(e){}finally{S(!1)}}})},[t,r,u,i]),z=(0,o.useCallback)(()=>{L(!1),f(!0),(async()=>{try{let e=await fetch("/api/workspace/objects/".concat(encodeURIComponent(t),"/entries/").concat(encodeURIComponent(r)));if(e.ok){let t=await e.json();m(t)}}catch(e){}finally{f(!1)}})(),null==u||u()},[t,r,u]),U=null==h?void 0:h.effectiveDisplayField,H=(0,M.A3)(String(t)),V=U&&(null==h?void 0:h.entry[U])?dS(h.entry[U]):"".concat(H," entry"),K=h?dI(h.entry,dM):void 0,J=h?dI(h.entry,dT):void 0,[q,G]=(0,o.useState)(!1),$=(0,o.useMemo)(()=>{var e;return null!=(e=null==h?void 0:h.fields.filter(e=>"action"!==e.type))?e:[]},[null==h?void 0:h.fields]),Y=(0,o.useMemo)(()=>{var e;return null!=(e=null==h?void 0:h.fields.filter(e=>"action"===e.type))?e:[]},[null==h?void 0:h.fields]);return(0,n.jsxs)("div",{className:"flex flex-col h-full min-h-0 overflow-hidden",style:{background:"var(--color-bg)"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b flex-shrink-0",style:{borderColor:"var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>void(null==d||d(t)),className:"flex items-center gap-1 px-2 py-0.5 rounded-md text-[11px] font-medium 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(H),children:[(0,n.jsxs)("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:"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"})]}),H]}),(0,n.jsx)("h2",{className:"text-sm font-semibold truncate",style:{color:"var(--color-text)"},children:x?"":V})]}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[(0,n.jsx)("button",{type:"button",onClick:()=>void O(),disabled:C,className:"p-1 rounded-md flex-shrink-0 hover:opacity-80",style:{color:"var(--color-error)"},title:"Delete entry",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"})]})}),(0,n.jsx)("button",{type:"button",onClick:i,className:"p-1 rounded-md flex-shrink-0 hover:opacity-80",style:{color:"var(--color-text-muted)"},title:"Close (Esc)",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:"M18 6 6 18"}),(0,n.jsx)("path",{d:"m6 6 12 12"})]})})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto overflow-x-hidden min-h-0",children:[(0,n.jsxs)("div",{className:"px-5 pt-4 pb-2",children:[x&&(0,n.jsx)(dO,{}),v&&(0,n.jsx)("div",{className:"py-8 text-center",children:(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:v})}),h&&!x&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{type:"button",onClick:()=>G(e=>!e),className:"flex items-center gap-1.5 mb-2 text-[11px] font-medium uppercase tracking-wider hover:opacity-70 transition-opacity",style:{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",className:"transition-transform",style:{transform:q?"rotate(-90deg)":"rotate(0deg)"},children:(0,n.jsx)("path",{d:"m6 9 6 6 6-6"})}),"Properties"]}),!q&&(0,n.jsxs)("div",{className:"space-y-0.5 mb-2",children:[$.map(e=>{let t=h.entry[e.name];return(0,n.jsxs)("div",{className:"entry-detail-row",children:[(0,n.jsx)("div",{className:"entry-detail-label",title:e.name,children:e.name}),(0,n.jsx)("div",{className:"entry-detail-value",children:y===e.name?"tags"===e.type?(0,n.jsxs)("div",{className:"flex items-center gap-1 w-full",children:[(0,n.jsx)("div",{className:"flex-1 px-2 py-0.5 rounded-md",style:{background:"var(--color-surface-hover)",border:"2px solid var(--color-accent)"},children:(0,n.jsx)(dA,{value:dS(t),onChange:t=>{P(e.name,t)},autoFocus:!0})}),(0,n.jsx)("button",{type:"button",onClick:()=>b(null),className:"px-1.5 py-0.5 text-xs rounded-md 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-1 w-full",children:[(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(re,{relatedObjectName:e.related_object_name,value:dS(t),multiple:"many_to_many"===e.relationship_type,onChange:t=>{P(e.name,t)},autoFocus:!0})}),(0,n.jsx)("button",{type:"button",onClick:()=>b(null),className:"px-1.5 py-0.5 text-xs rounded-md 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(),P(e.name,j)},className:"flex items-center gap-1 w-full",children:["enum"===e.type&&e.enum_values?(0,n.jsxs)("select",{value:j,onChange:t=>{k(t.target.value),P(e.name,t.target.value)},autoFocus:!0,className:"flex-1 min-w-0 px-2 py-0.5 text-sm rounded-md 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:j,onChange:t=>{k(t.target.value),P(e.name,t.target.value)},autoFocus:!0,className:"flex-1 min-w-0 px-2 py-0.5 text-sm rounded-md 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:j,onChange:e=>k(e.target.value),autoFocus:!0,className:"flex-1 min-w-0 px-2 py-0.5 text-sm rounded-md 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:w,className:"px-1.5 py-0.5 text-xs rounded-md font-medium flex-shrink-0",style:{background:"var(--color-accent)",color:"white"},children:w?"...":"Save"})]}),(0,n.jsx)("button",{type:"button",onClick:()=>b(null),className:"px-1.5 py-0.5 text-xs rounded-md flex-shrink-0",style:{color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:"Cancel"})]}):(0,n.jsx)("div",{className:"py-0.5 px-1.5 -mx-1.5 rounded-md transition-colors ".concat(["user"].includes(e.type)?"":"cursor-pointer hover:bg-[var(--color-surface-hover)]"),onClick:()=>{["user"].includes(e.type)||(b(e.name),k(dS(t)))},title:["user"].includes(e.type)?void 0:"Click to edit",children:(0,n.jsx)(dP,{value:t,field:e,members:l,relationLabels:h.relationLabels,relationFaviconUrls:h.relationFaviconUrls,onNavigateEntry:c})})})]},e.id)}),T?(0,n.jsx)(dW,{objectName:t,onCreated:z,onCancel:()=>L(!1)}):(0,n.jsxs)("button",{type:"button",onClick:()=>L(!0),className:"flex items-center gap-1.5 text-xs py-1.5 px-1 rounded-md hover:bg-[var(--color-surface-hover)] transition-colors mt-1",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",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 5v14"}),(0,n.jsx)("path",{d:"M5 12h14"})]}),"Add a property"]}),Y.length>0&&(0,n.jsxs)("div",{className:"mt-3 pt-3",style:{borderTop:"1px solid var(--color-border)"},children:[(0,n.jsx)("div",{className:"text-[11px] font-medium uppercase tracking-wider mb-2",style:{color:"var(--color-text-muted)"},children:"Actions"}),(0,n.jsx)("div",{className:"flex flex-wrap gap-2",children:Y.map(e=>(function(e){if(!e)return[];try{let t=JSON.parse(e);if(t&&Array.isArray(t.actions))return t.actions}catch(e){}return[]})(e.default_value).map(o=>(0,n.jsx)(rX,{action:o,entryId:r,objectName:t,fieldId:e.id,onToast:I,onRequestConfirm:(e,t,r)=>{var n;W({open:!0,title:e.label,message:null!=(n=e.confirmMessage)?n:'Run "'.concat(e.label,'" on this entry?'),variant:"destructive"===e.variant?"destructive":"default",confirmLabel:e.label,onConfirm:()=>{W(null),r()}})}},"".concat(e.id,"_").concat(o.id))))})]})]}),!q&&h.reverseRelations&&h.reverseRelations.length>0&&(0,n.jsxs)("div",{className:"pb-2 space-y-2",children:[(0,n.jsx)("div",{className:"text-[10px] font-medium uppercase tracking-widest",style:{color:"var(--color-text-muted)",opacity:.6},children:"Linked from"}),h.reverseRelations.map(e=>(0,n.jsx)(dB,{relation:e,onNavigateEntry:c},"".concat(e.sourceObjectName,"_").concat(e.fieldName)))]}),(null!=K||null!=J)&&(0,n.jsxs)("div",{className:"pb-2 text-[11px] flex gap-3 flex-wrap",style:{color:"var(--color-text-muted)"},children:[null!=K&&(0,n.jsxs)("span",{children:["Created: ",(0,n.jsx)(rJ,{value:K,fieldType:"date",mode:"detail",className:"inline"})]}),null!=J&&(0,n.jsxs)("span",{children:["Updated: ",(0,n.jsx)(rJ,{value:J,fieldType:"date",mode:"detail",className:"inline"})]})]})]})]}),!x&&!v&&(0,n.jsx)("div",{className:"entry-detail-editor",children:A?(0,n.jsx)("div",{className:"px-5 py-6",children:(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)("div",{className:"h-3 w-3/4 rounded animate-pulse",style:{background:"var(--color-surface-hover)"}}),(0,n.jsx)("div",{className:"h-3 w-1/2 rounded animate-pulse",style:{background:"var(--color-surface-hover)"}})]})}):(0,n.jsx)(dC.MarkdownEditor,{content:_,filePath:E,tree:a,onSave:u,onNavigate:p,searchFn:s})})]}),B&&(0,n.jsx)(r0,{open:B.open,title:B.title,message:B.message,variant:B.variant,confirmLabel:B.confirmLabel,onConfirm:B.onConfirm,onCancel:()=>W(null)})]})}var dU=r(91365);let dH={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},dV={contentTabs:[],chatTabs:[],activeContentId:null,activeChatId:null};function dK(e,t,r){var n,o,l;switch(e){case"crm-person":return"crm-person:".concat(null!=(n=null==r?void 0:r.entryId)?n:t);case"crm-company":return"crm-company:".concat(null!=(o=null==r?void 0:r.entryId)?o:t);case"browse":return"browse:".concat(null!=(l=null==r?void 0:r.browsePath)?l:t);default:return t}}function dJ(e){var t,r,n;let o=null!=(t=e.id)?t:dK(e.kind,e.path,e.meta),l=null==(r=e.preview)||r,a=null!=(n=e.pinned)&&n;return{id:o,kind:e.kind,path:e.path,title:e.title,icon:e.icon,meta:e.meta,preview:!a&&l,pinned:a}}function dq(e,t){var r;return"draft"===e?"draft:".concat(null!=(r=t.draftId)?r:dG()):("subagent"===e||"gateway"===e)&&t.sessionKey?t.sessionKey:t.sessionId?t.sessionId:"draft:".concat(dG())}function dG(){return Math.random().toString(36).slice(2,10)}function d$(e){var t,r,n;let o=null!=(t=e.id)?t:dq(e.variant,{sessionId:e.sessionId,sessionKey:e.sessionKey}),l=null==(r=e.preview)||r,a=null!=(n=e.pinned)&&n;return{id:o,variant:e.variant,title:e.title,preview:!a&&l,pinned:a,sessionId:e.sessionId,sessionKey:e.sessionKey,parentSessionId:e.parentSessionId,channel:e.channel}}function dY(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"New Chat";return d$({id:dq("draft",{draftId:dG()}),variant:"draft",title:e,preview:!0})}function dZ(e,t){return t||("~cron"===e?"Cron":e.startsWith("~cron/")?e.slice(6)||"Cron Job":"~skills"===e?"Skills":"~integrations"===e?"Integrations":"~cloud"===e?"Cloud":"~crm/inbox"===e?"Inbox":"~crm/calendar"===e?"Calendar":e.split("/").pop()||e)}function dQ(e){var t;return e.activeContentId&&null!=(t=e.contentTabs.find(t=>t.id===e.activeContentId))?t:null}function dX(e,t){let r=dJ(t),n=e.contentTabs.findIndex(e=>e.id===r.id);if(-1!==n){var o,l;let t=e.contentTabs,a=e.contentTabs[n];return((a.kind!==r.kind||a.path!==r.path||JSON.stringify(null!=(o=a.meta)?o:{})!==JSON.stringify(null!=(l=r.meta)?l:{}))&&((t=[...e.contentTabs])[n]={...t[n],kind:r.kind,path:r.path,meta:r.meta}),!r.preview&&e.contentTabs[n].preview&&(t===e.contentTabs&&(t=[...e.contentTabs]),t[n]={...t[n],preview:!1}),t===e.contentTabs&&e.activeContentId===r.id)?e:{...e,contentTabs:t,activeContentId:r.id}}if(r.preview){let t=function(e,t){if(t){let r=e.findIndex(e=>e.id===t&&e.preview);if(-1!==r)return r}return e.findIndex(e=>e.preview)}(e.contentTabs,e.activeContentId);if(-1!==t){let n=[...e.contentTabs];return n[t]=r,{...e,contentTabs:n,activeContentId:r.id}}}return{...e,contentTabs:[...e.contentTabs,r],activeContentId:r.id}}function d0(e,t){let r=!1,n=e.contentTabs.map(e=>e.id===t&&e.preview?(r=!0,{...e,preview:!1}):e);return r?{...e,contentTabs:n}:e}function d1(e){if(e.chatTabs.length>0)return e.activeChatId&&e.chatTabs.some(t=>t.id===e.activeChatId)?e:{...e,activeChatId:e.chatTabs[0].id};let t=dY();return{...e,chatTabs:[t],activeChatId:t.id}}function d2(e){return"".concat("dench:workspace-tabs",":").concat(e||"default")}function d4(e){return!!e&&"object"==typeof e&&"string"==typeof e.id&&"string"==typeof e.path&&"string"==typeof e.title&&"string"==typeof e.kind}function d5(e){return!!e&&"object"==typeof e&&"string"==typeof e.id&&"string"==typeof e.title&&"string"==typeof e.variant}function d3(e){return{id:e.id,kind:e.kind,path:e.path,title:e.title,icon:e.icon,meta:e.meta,preview:e.preview,pinned:e.pinned}}function d6(e){return{id:e.id,variant:e.variant,title:e.title,sessionId:e.sessionId,sessionKey:e.sessionKey,parentSessionId:e.parentSessionId,channel:e.channel,preview:e.preview,pinned:e.pinned}}function d8(e,t){switch(t.type){case"openContent":return dX(e,t.tab);case"closeContent":return function(e,t){let r=e.contentTabs.findIndex(e=>e.id===t);if(-1===r||e.contentTabs[r].pinned)return e;let n=e.contentTabs.filter(e=>e.id!==t),o=e.activeContentId;return o===t&&(o=0===n.length?null:r<n.length?n[r].id:n[n.length-1].id),{...e,contentTabs:n,activeContentId:o}}(e,t.id);case"closeOtherContent":var r,n,o=t.id;let l=e.contentTabs.filter(e=>e.id===o||e.pinned);return{...e,contentTabs:l,activeContentId:o};case"closeContentToRight":return function(e,t){let r=e.contentTabs.findIndex(e=>e.id===t);if(-1===r)return e;let n=e.contentTabs.filter((e,t)=>t<=r||e.pinned),o=n.some(t=>t.id===e.activeContentId);return{...e,contentTabs:n,activeContentId:o?e.activeContentId:t}}(e,t.id);case"closeAllContent":let a=e.contentTabs.filter(e=>e.pinned),s=a.some(t=>t.id===e.activeContentId);return{...e,contentTabs:a,activeContentId:s?e.activeContentId:null};case"activateContent":return r=t.id,null===r||e.contentTabs.some(e=>e.id===r)?e.activeContentId===r?e:{...e,activeContentId:r}:{...e,activeContentId:null};case"promoteContent":return d0(e,t.id);case"promoteContentByPath":var i=t.path;let c=e.contentTabs.find(e=>e.path===i);return c?d0(e,c.id):e;case"togglePinContent":var d=t.id;let u=!1,p=e.contentTabs.map(e=>{if(e.id!==d)return e;u=!0;let t=!e.pinned;return{...e,pinned:t,preview:!t&&e.preview}});return u?{...e,contentTabs:p}:e;case"updateContentMeta":return function(e,t,r){let n=!1,o=e.contentTabs.map(e=>{var o,l;if(e.id!==t)return e;let a={...null!=(o=e.meta)?o:{},...r};return JSON.stringify(null!=(l=e.meta)?l:{})===JSON.stringify(a)?e:(n=!0,{...e,meta:a})});return n?{...e,contentTabs:o}:e}(e,t.id,t.meta);case"reorderContent":return function(e,t,r){let n=e.contentTabs.findIndex(e=>e.id===t);if(-1===n||n===r)return e;let o=Math.max(0,Math.min(e.contentTabs.length-1,r)),l=[...e.contentTabs],[a]=l.splice(n,1);return l.splice(o,0,a),{...e,contentTabs:l}}(e,t.id,t.toIndex);case"renameContent":return function(e,t,r){let n=!1,o=e.contentTabs.map(e=>e.id!==t||e.title===r?e:(n=!0,{...e,title:r}));return n?{...e,contentTabs:o}:e}(e,t.id,t.title);case"openChat":return function(e,t){let r=d$(t),n=e.chatTabs.findIndex(e=>e.id===r.id);if(-1===n&&"session"===r.variant&&r.sessionId&&(n=e.chatTabs.findIndex(e=>"session"===e.variant&&e.sessionId===r.sessionId)),-1!==n){let t=e.chatTabs[n],o=e.chatTabs;return(!r.preview&&t.preview&&((o=[...e.chatTabs])[n]={...o[n],preview:!1}),o===e.chatTabs&&e.activeChatId===t.id)?e:{...e,chatTabs:o,activeChatId:t.id}}return{...e,chatTabs:[...e.chatTabs,r],activeChatId:r.id}}(e,t.tab);case"closeChat":return function(e,t){let r=e.chatTabs.findIndex(e=>e.id===t);if(-1===r||e.chatTabs[r].pinned)return e;let n=e.chatTabs.filter(e=>e.id!==t),o=e.activeChatId;return o===t&&(o=0===n.length?null:r<n.length?n[r].id:n[n.length-1].id),d1({...e,chatTabs:n,activeChatId:o})}(e,t.id);case"closeChatsForSession":return function(e,t){var r,n;let o=e.chatTabs.filter(e=>!!e.pinned||e.sessionId!==t&&e.parentSessionId!==t);if(o.length===e.chatTabs.length)return e;let l=o.some(t=>t.id===e.activeChatId)?e.activeChatId:null!=(n=null==(r=o[o.length-1])?void 0:r.id)?n:null;return d1({...e,chatTabs:o,activeChatId:l})}(e,t.sessionId);case"activateChat":return n=t.id,null===n||e.chatTabs.some(e=>e.id===n)?e.activeChatId===n?e:{...e,activeChatId:n}:{...e,activeChatId:null};case"promoteChat":var h=t.id;let m=!1,x=e.chatTabs.map(e=>e.id===h&&e.preview?(m=!0,{...e,preview:!1}):e);return m?{...e,chatTabs:x}:e;case"togglePinChat":var f=t.id;let v=!1,g=e.chatTabs.map(e=>{if(e.id!==f)return e;v=!0;let t=!e.pinned;return{...e,pinned:t,preview:!t&&e.preview}});return v?{...e,chatTabs:g}:e;case"renameChat":return function(e,t,r){let n=!1,o=e.chatTabs.map(e=>e.id!==t||e.title===r?e:(n=!0,{...e,title:r}));return n?{...e,chatTabs:o}:e}(e,t.id,t.title);case"bindChatSession":return function(e,t,r){let n=e.chatTabs.find(e=>e.id===t);if(!n)return e;if(r){let o=e.chatTabs.find(e=>e.id!==t&&"session"===e.variant&&e.sessionId===r);if(o){let r=n.pinned?e.chatTabs:e.chatTabs.filter(e=>e.id!==t);return d1({...e,chatTabs:r,activeChatId:o.id})}}let o=null!=r?r:void 0;if(n.sessionId===o&&(null==r||"session"===n.variant))return e;let l={...n,sessionId:o,variant:r?"session":"draft",id:n.id},a=e.chatTabs.map(e=>e.id===t?l:e),s=e.activeChatId===t?l.id:e.activeChatId;return{...e,chatTabs:a,activeChatId:s}}(e,t.tabId,t.sessionId);case"syncChatTitles":return function(e,t,r){let n=new Map(t.map(e=>[e.id,e.title])),o=new Map(r.map(e=>[e.childSessionKey,e.label||e.task])),l=!1,a=e.chatTabs.map(e=>{if("session"===e.variant&&e.sessionId){let t=n.get(e.sessionId);if(t&&t!==e.title)return l=!0,{...e,title:t}}if("subagent"===e.variant&&e.sessionKey){let t=o.get(e.sessionKey);if(t&&t!==e.title)return l=!0,{...e,title:t}}return e});return l?{...e,chatTabs:a}:e}(e,t.sessions,t.subagents);case"ensureChatPresent":return d1(e);case"applyUrl":return function(e,t,r){let n=e;if(t.entry){let e="people"===t.entry.objectName,r="company"===t.entry.objectName||"companies"===t.entry.objectName;if(e||r){let r=e?"crm-person":"crm-company",o=e?"people":"company";return dX(n,{id:dK(r,o,{entryId:t.entry.entryId}),kind:r,path:o,title:e?"Person":"Company",meta:{entryId:t.entry.entryId,...t.profileTab?{profileTab:t.profileTab}:{}},preview:!0})}}let o=function(e,t){var r,n;if(!e.path)return"people"===e.crm?dJ({kind:"object",path:"people",title:"People",preview:!1}):"companies"===e.crm?dJ({kind:"object",path:"company",title:"Companies",preview:!1}):"inbox"===e.crm?dJ({kind:"crm-inbox",path:"~crm/inbox",title:"Inbox",preview:!1}):"calendar"===e.crm?dJ({kind:"crm-calendar",path:"~crm/calendar",title:"Calendar",preview:!1}):null;let o=e.path;return"companies"===o?dJ({kind:"object",path:"company",title:"Companies",preview:!0}):dJ({kind:null!=(n=null==(r=t.resolveKind)?void 0:r.call(t,o))?n:"~cron"===o?"cron-dashboard":o.startsWith("~cron/")?"cron-job":"~skills"===o?"skills":"~integrations"===o?"integrations":"~cloud"===o?"cloud":"~crm/inbox"===o?"crm-inbox":"~crm/calendar"===o?"crm-calendar":"file",path:o,title:dZ(o),preview:!0})}(t,r);return o?n=dX(n,o):t.chat||(n={...n,activeContentId:null}),n}(e,t.url,t.shell);case"replace":return t.state}}let d7={people:"seed_obj_people_00000000000000",company:"seed_obj_company_0000000000000"};function d9(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 ue(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 ut(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 ur(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)?d9(e-t):null}let un=[{id:"overview",label:"Overview"},{id:"calendar",label:"Calendar"},{id:"insights",label:"Insights"}];function uo(e){let{onSelectJob:t,onSendCommand:r,activeView:l="overview",onViewChange:a,calendarMode:s="month",onCalendarModeChange:i,calendarDate:c,onCalendarDateChange:d}=e,[u,p]=(0,o.useState)([]),[h,m]=(0,o.useState)({intervalMs:864e5,nextDueEstimateMs:null}),[x,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();p(null!=(e=l.jobs)?e:[]),m(null!=(t=l.heartbeat)?t:{intervalMs:864e5,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=ur(h.nextDueEstimateMs),w=ur(x.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:un.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)(ul,{jobs:u,enabledJobs:N,disabledJobs:C,heartbeatCountdown:k,heartbeat:h,cronWakeCountdown:w,onSelectJob:t,onSendCommand:r,onRefresh:()=>void j()}),"calendar"===l&&(0,n.jsx)(up,{jobs:u,allRuns:y,mode:s,onModeChange:i,dateAnchor:c,onDateChange:d,onSelectJob:t}),"insights"===l&&(0,n.jsx)(uv,{jobs:u,allRuns:y,onSelectJob:t})]})}function ul(e){let{jobs:t,enabledJobs:r,disabledJobs:o,heartbeatCountdown:l,heartbeat:a,cronWakeCountdown:s,onSelectJob:i,onSendCommand:c,onRefresh:d}=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)(uj,{heartbeat:a,heartbeatCountdown:l,onSaved:d}),(0,n.jsx)(uk,{title:"Cron Scheduler",icon:(0,n.jsx)(uM,{}),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)(uk,{title:"Active Runs",icon:(0,n.jsx)(uT,{}),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)(uw,{jobs:r}),(0,n.jsx)(uN,{jobs:[...r,...o],onSelectJob:i,onSendCommand:c})]})}function ua(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function us(e){let t=ua(e);return t.setDate(t.getDate()-t.getDay()),t}function ui(e,t){let r=ua(e);return r.setDate(r.getDate()+t),r}function uc(e){return"".concat(e.getFullYear(),"-").concat(String(e.getMonth()+1).padStart(2,"0"),"-").concat(String(e.getDate()).padStart(2,"0"))}function ud(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 uu(e){var t,r,o,l,a;let{ev:s,onSelectJob:i}=e,c=new Date(s.at).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});if("scheduled"===s.kind)return(0,n.jsxs)("button",{type:"button",onClick:()=>i(s.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(s.job.name," at ").concat(c),children:[c," ",s.job.name]});let d="ok"===s.run.status?"var(--color-success, #22c55e)":"error"===s.run.status?"var(--color-error, #ef4444)":"var(--color-text-muted)";return(0,n.jsxs)("button",{type:"button",onClick:()=>s.job&&i(s.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(d," 10%, transparent)"),color:d},title:"".concat(null!=(o=s.run.status)?o:"finished",": ").concat(null!=(l=null==(t=s.job)?void 0:t.name)?l:s.run.jobId," at ").concat(c),children:[(0,n.jsx)("span",{className:"w-1 h-1 rounded-full flex-shrink-0",style:{background:d}}),(0,n.jsxs)("span",{className:"truncate",children:[c," ",null!=(a=null==(r=s.job)?void 0:r.name)?a:s.run.jobId.slice(0,8)]})]})}function up(e){var t;let{jobs:r,allRuns:l,mode:a="month",onModeChange:s,dateAnchor:i,onDateChange:c,onSelectJob:d}=e,u=null!=(t=function(e){if(!e)return null;let t=e.match(/^(\d{4})-(\d{2})-(\d{2})$/);if(t)return new Date(Number(t[1]),Number(t[2])-1,Number(t[3]));let r=new Date(e);return Number.isNaN(r.getTime())?null:ua(r)}(i))?t:ua(new Date),p=e=>{let t="month"===a?function(e,t){let r=new Date(e.getFullYear(),e.getMonth(),1);r.setMonth(r.getMonth()+t);let n=new Date(r.getFullYear(),r.getMonth()+1,0).getDate();return r.setDate(Math.min(e.getDate(),n)),r}(u,e):"week"===a?ui(u,7*e):"day"===a?ui(u,e):function(e,t){let r=new Date(e.getFullYear()+t,e.getMonth(),1),n=new Date(r.getFullYear(),r.getMonth()+1,0).getDate();return r.setDate(Math.min(e.getDate(),n)),r}(u,e);null==c||c(uc(t))},h=(0,o.useMemo)(()=>{let e=new Map;for(let t of r)e.set(t.id,t);return e},[r]),{rangeFrom:m,rangeTo:x}=(0,o.useMemo)(()=>{let e=u.getFullYear(),t=u.getMonth();if("day"===a){let r=new Date(e,t,u.getDate());return{rangeFrom:r.getTime(),rangeTo:ui(r,1).getTime()}}if("week"===a){let e=us(u);return{rangeFrom:e.getTime(),rangeTo:ui(e,7).getTime()}}if("year"===a)return{rangeFrom:new Date(e,0,1).getTime(),rangeTo:new Date(e+1,0,1).getTime()};let r=us(new Date(e,t,1));return{rangeFrom:r.getTime(),rangeTo:ui(r,42).getTime()}},[u,a]),f=(0,o.useMemo)(()=>(function(e,t,r,n,o){var l,a,s;let i=new Map,c=Date.now();for(let t of e){let e=null!=(l=t.runAtMs)?l:t.ts;if(e<n||e>=o)continue;let s=uc(new Date(e)),c=null!=(a=i.get(s))?a:[];c.push({kind:"run",run:t,job:r.get(t.jobId),at:e}),i.set(s,c)}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=ud(o[0],0,59),a=ud(o[1],0,23),s=ud(o[2],1,31),i=ud(o[3],1,12),c=ud(o[4],0,6),d="*"===o[2],u="*"===o[4],p=[],h=new Date(t);h.setSeconds(0,0);let m=0;for(;h.getTime()<r&&m++<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&&p.push(o)}h.setDate(h.getDate()+1),h.setHours(0,0,0,0)}return p}(n.expr,t,r,n.tz);default:return[]}}(e,n,o)){if(t<c)continue;let r=uc(new Date(t)),n=null!=(s=i.get(r))?s:[];n.push({kind:"scheduled",job:e,at:t}),i.set(r,n)}for(let e of i.values())e.sort((e,t)=>{var r,n,o,l;if(e.at!==t.at)return e.at-t.at;let a="run"===e.kind?null!=(o=null==(r=e.job)?void 0:r.name)?o:e.run.jobId:e.job.name,s="run"===t.kind?null!=(l=null==(n=t.job)?void 0:n.name)?l:t.run.jobId:t.job.name;return a.localeCompare(s)});return i})(l,r,h,m,x),[l,r,h,m,x]),v=(0,o.useMemo)(()=>{if("day"===a)return u.toLocaleDateString(void 0,{weekday:"long",month:"long",day:"numeric",year:"numeric"});if("week"===a){let e=us(u),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"===a?String(u.getFullYear()):u.toLocaleDateString(void 0,{month:"long",year:"numeric"})},[u,a]),g=uc(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:()=>p(-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:v}),(0,n.jsx)("button",{type:"button",onClick:()=>p(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==c?void 0:c(uc(new Date)),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==s?void 0:s(e),className:"px-3 py-1 rounded-md text-xs font-medium cursor-pointer",style:{background:a===e?"var(--color-surface)":"transparent",color:a===e?"var(--color-text)":"var(--color-text-muted)"},children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]}),"day"===a&&(0,n.jsx)(uh,{anchor:u,eventsByDay:f,todayStr:g,onSelectJob:d}),"week"===a&&(0,n.jsx)(um,{anchor:u,eventsByDay:f,todayStr:g,onSelectJob:d,onDateChange:c,onModeChange:s}),"month"===a&&(0,n.jsx)(ux,{anchor:u,eventsByDay:f,todayStr:g,onSelectJob:d}),"year"===a&&(0,n.jsx)(uf,{anchor:u,eventsByDay:f,todayStr:g,onDateChange:c,onModeChange:s})]})}function uh(e){var t;let{anchor:r,eventsByDay:l,todayStr:a,onSelectJob:s}=e,i=uc(r),c=null!=(t=l.get(i))?t:[],d=i===a,u=Array.from({length:24},(e,t)=>t),p=(0,o.useMemo)(()=>{let e=new Map;for(let r of c){var t;let n=new Date(r.at).getHours(),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=p.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)(uu,{ev:e,onSelectJob:s},t))})]},e)})})}function um(e){let{anchor:t,eventsByDay:r,todayStr:o,onSelectJob:l,onDateChange:a,onModeChange:s}=e,i=us(t),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=uc(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=uc(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)(uu,{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 ux(e){let{anchor:t,eventsByDay:r,todayStr:l,onSelectJob:a}=e,s=(0,o.useMemo)(()=>{let e=us(new Date(t.getFullYear(),t.getMonth(),1)),r=[];for(let t=0;t<6;t++){let n=[];for(let r=0;r<7;r++){let o=new Date(e);o.setDate(o.getDate()+7*t+r),n.push(o)}r.push(n)}return r},[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=uc(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)(uu,{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 uf(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(uc(t)),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,p=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:p?"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 uv(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)(ug,{label:"Total Runs",value:String(a.total)}),(0,n.jsx)(ug,{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)(ug,{label:"Errors",value:String(a.errors),accent:a.errors>0?"var(--color-error, #ef4444)":void 0}),(0,n.jsx)(ug,{label:"Avg Duration",value:ue(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 ",ue(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 ug(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})]})}let uy=[{value:"m",label:"min"},{value:"h",label:"hr"},{value:"d",label:"day"}];function ub(e){let t=function(e){if(!e)return null;let t=e.match(/^(\d+)(m|h|d)$/);return t?{value:Number(t[1]),unit:t[2]}:null}(e.every);return t||(e.intervalMs>0&&e.intervalMs%864e5==0?{value:e.intervalMs/864e5,unit:"d"}:e.intervalMs>0&&e.intervalMs%36e5==0?{value:e.intervalMs/36e5,unit:"h"}:{value:Math.max(1,Math.round(e.intervalMs/6e4)),unit:"m"})}function uj(e){var t;let{heartbeat:r,heartbeatCountdown:l,onSaved:a}=e,s=ub(r),[i,c]=(0,o.useState)(s.value),[d,u]=(0,o.useState)(s.unit),[p,h]=(0,o.useState)(!1),[m,x]=(0,o.useState)(null),f=null!=(t=r.every)?t:"interval:".concat(r.intervalMs),v=(0,o.useRef)(f);(0,o.useEffect)(()=>{if(f!==v.current){v.current=f;let e=ub(r);c(e.value),u(e.unit)}},[f,r.every,r.intervalMs]);let g="".concat(s.value).concat(s.unit)!=="".concat(i).concat(d),y=(0,o.useCallback)(async()=>{if(g&&!p){h(!0),x(null);try{let t=await fetch("/api/cron/heartbeat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({value:i,unit:d})}),r=await t.json();if(!t.ok){var e;x(null!=(e=r.error)?e:"Failed to save.");return}v.current=r.raw,a()}catch(e){x("Network error.")}finally{h(!1)}}},[i,d,g,p,a]);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:(0,n.jsx)(uS,{})}),(0,n.jsx)("span",{className:"text-xs font-medium uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:"Heartbeat"})]}),(0,n.jsx)("div",{className:"text-lg font-semibold mb-1",style:{color:"var(--color-text)"},children:l?"in ".concat(l):"unknown"}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mt-2",children:[(0,n.jsx)("span",{className:"text-[11px] shrink-0",style:{color:"var(--color-text-muted)"},children:"Every"}),(0,n.jsx)("input",{type:"number",min:1,value:i,onChange:e=>{let t=parseInt(e.target.value,10);Number.isFinite(t)&&t>0&&c(t)},className:"w-14 rounded-md px-1.5 py-0.5 text-xs text-center tabular-nums",style:{background:"var(--color-surface-hover)",color:"var(--color-text)",border:"1px solid var(--color-border)"},"aria-label":"Heartbeat interval value"}),(0,n.jsx)("div",{className:"flex rounded-md overflow-hidden",style:{border:"1px solid var(--color-border)"},children:uy.map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>u(e.value),className:"px-2 py-0.5 text-[11px] font-medium transition-colors cursor-pointer",style:{background:d===e.value?"var(--color-accent)":"var(--color-surface-hover)",color:d===e.value?"white":"var(--color-text-muted)"},"aria-label":"Unit: ".concat(e.label),"aria-pressed":d===e.value,children:e.label},e.value))}),g&&(0,n.jsx)("button",{type:"button",onClick:()=>void y(),disabled:p,className:"px-2 py-0.5 text-[11px] font-medium rounded-md transition-colors cursor-pointer disabled:opacity-50",style:{background:"var(--color-accent)",color:"white"},children:p?"...":"Save"})]}),m&&(0,n.jsx)("div",{className:"text-[10px] mt-1",style:{color:"var(--color-error, #ef4444)"},children:m})]})}function uk(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 uw(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 ",d9((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 uN(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)(uC,{job:e,onClick:()=>r(e.id),onSendCommand:o},e.id))})]})})]})}function uC(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=ut(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(d9(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:ut(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(ue(r.state.lastDurationMs),")"):""):"-"})]})}),(0,n.jsx)("td",{className:"px-4 py-3",children:(0,n.jsxs)("div",{className:"flex items-center gap-1 md:opacity-0 md: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 uS(){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 uM(){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 uT(){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 uL(e){var t;return null!=(t=e.split("/")[0])?t:e}function uI(e){let{source:t,size:r=36,emoji:l,isManaged:a}=e,[s,i]=(0,o.useState)(!1),c="".concat(r,"px");return a?(0,n.jsx)("img",{src:"/dench-workspace-icon.png",alt:"DenchClaw",width:r,height:r,className:"rounded-xl shrink-0",style:{width:c,height:c,objectFit:"cover"},loading:"lazy"}):l&&!s?(0,n.jsx)("div",{className:"flex items-center justify-center rounded-xl shrink-0",style:{width:c,height:c,background:"var(--color-surface-hover)",fontSize:"".concat(Math.round(.5*r),"px")},children:l}):"workspace"===t?(0,n.jsx)("img",{src:"/icons/folder.png",alt:"",width:r,height:r,className:"rounded-xl shrink-0",style:{width:c,height:c,objectFit:"cover"},loading:"lazy"}):s?(0,n.jsx)("div",{className:"flex items-center justify-center rounded-xl shrink-0",style:{width:c,height:c,background:"var(--color-surface-hover)",color:"var(--color-text-muted)",fontSize:"".concat(Math.round(.35*r),"px"),fontWeight:600},children:uL(t).slice(0,2).toUpperCase()}):(0,n.jsx)("img",{src:function(e){let t=uL(e);return"https://github.com/".concat(t,".png?size=80")}(t),alt:"",width:r,height:r,className:"rounded-xl shrink-0",style:{width:c,height:c,objectFit:"cover"},onError:()=>i(!0),loading:"lazy"})}function u_(){return(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{display:"inline",verticalAlign:"middle"},children:[(0,n.jsx)("polyline",{points:"23 6 13.5 15.5 8.5 10.5 1 18"}),(0,n.jsx)("polyline",{points:"17 6 23 6 23 12"})]})}function uR(){return(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{display:"inline",verticalAlign:"middle"},children:[(0,n.jsx)("line",{x1:"7",y1:"17",x2:"17",y2:"7"}),(0,n.jsx)("polyline",{points:"7 7 17 7 17 17"})]})}function uE(){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",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 uD(){return(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{display:"inline",verticalAlign:"middle"},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",y1:"15",x2:"12",y2:"3"})]})}function uA(e){let{skill:t,removingSlug:r,confirmRemove:o,onConfirmRemove:l,onRemove:a,onClick:s}=e;return(0,n.jsxs)("div",{className:"group rounded-2xl p-4 flex flex-col gap-2.5 transition-colors cursor-pointer",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},role:"button",tabIndex:0,onClick:s,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(null==s||s())},children:[(0,n.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,n.jsx)(uI,{source:t.source,emoji:t.emoji,size:36,isManaged:t.protected||"managed"===t.source}),(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:t.name}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mt-0.5",children:[(0,n.jsx)("span",{className:"text-[10px] truncate",style:{color:"var(--color-text-muted)"},children:"managed"===t.source?"DenchClaw":uL(t.source)}),(0,n.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full shrink-0",style:{background:"managed"===t.source?"color-mix(in srgb, var(--color-accent) 12%, transparent)":"var(--color-surface-hover)",color:"managed"===t.source?"var(--color-accent)":"var(--color-text-muted)"},children:"managed"===t.source?"built-in":t.source}),t.protected&&(0,n.jsxs)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full flex items-center gap-1 shrink-0",style:{background:"color-mix(in srgb, var(--color-warning, #f59e0b) 12%, transparent)",color:"var(--color-warning, #f59e0b)"},title:"Required by DenchClaw",children:[(0,n.jsx)(uE,{}),"protected"]})]})]})]}),!t.protected&&(0,n.jsx)("div",{className:"flex-shrink-0",onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:o===t.slug?(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{type:"button",onClick:()=>a(t.slug),disabled:r===t.slug,className:"text-[11px] px-2 py-1 rounded-lg cursor-pointer transition-colors",style:{background:"color-mix(in srgb, var(--color-error, #ef4444) 12%, transparent)",color:"var(--color-error, #ef4444)"},children:r===t.slug?(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-current rounded-full animate-spin",style:{borderTopColor:"transparent"}}),"Removing..."]}):"Confirm"}),(0,n.jsx)("button",{type:"button",onClick:()=>l(null),className:"text-[11px] px-2 py-1 rounded-lg cursor-pointer",style:{color:"var(--color-text-muted)"},children:"Cancel"})]}):(0,n.jsx)("button",{type:"button",onClick:()=>l(t.slug),className:"text-[11px] px-2 py-1 rounded-lg cursor-pointer transition-opacity opacity-0 group-hover:opacity-100",style:{color:"var(--color-text-muted)"},children:"Remove"})})]}),t.description&&(0,n.jsx)("p",{className:"text-xs leading-relaxed line-clamp-2",style:{color:"var(--color-text-muted)"},children:t.description})]})}function uF(e){var t;let{skill:r,isInstalled:o,installStatus:l,onInstall:a,featured:s=!1}=e,i=(null==l?void 0:l.phase)==="installing"||(null==l?void 0:l.phase)==="refreshing",c=r.installs>=5e4;return(0,n.jsxs)("div",{className:"group rounded-2xl p-4 flex flex-col gap-2.5",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,n.jsx)(uI,{source:r.source,size:s?40:36}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("div",{className:"font-medium truncate ".concat("text-sm"),style:{color:"var(--color-text)"},children:r.displayName}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mt-0.5",children:[(0,n.jsx)("span",{className:"text-[10px] truncate",style:{color:"var(--color-text-muted)"},children:uL(r.source)}),r.installs>0&&(0,n.jsxs)("span",{className:"text-[10px] flex items-center gap-0.5 shrink-0",style:{color:c?"var(--color-accent)":"var(--color-text-muted)"},children:[c?(0,n.jsx)(u_,{}):(0,n.jsx)(uD,{})," ",(t=r.installs)>=1e6?"".concat((t/1e6).toFixed(1),"M"):t>=1e3?"".concat((t/1e3).toFixed(t>=1e4?0:1),"K"):String(t)]})]})]})]}),(0,n.jsx)("div",{className:"flex-shrink-0",children:o?(0,n.jsx)("span",{className:"text-[11px] px-2.5 py-1 rounded-lg",style:{background:"color-mix(in srgb, var(--color-success, #22c55e) 12%, transparent)",color:"var(--color-success, #22c55e)"},children:"Installed"}):i?(0,n.jsxs)("span",{className:"text-[11px] px-2.5 py-1 rounded-lg flex items-center gap-1",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-current rounded-full animate-spin",style:{borderTopColor:"transparent"}}),(null==l?void 0:l.phase)==="installing"?"Installing...":"Syncing..."]}):(0,n.jsxs)("button",{type:"button",onClick:a,className:"text-[11px] px-2.5 py-1 rounded-lg cursor-pointer transition-opacity opacity-0 group-hover:opacity-100 flex items-center gap-1",style:{background:"var(--color-surface-hover)",color:"var(--color-text)"},children:[(0,n.jsx)(uR,{})," Install"]})})]}),r.summary&&!l&&(0,n.jsx)("p",{className:"text-xs leading-relaxed line-clamp-2",style:{color:"var(--color-text-muted)"},children:r.summary}),l&&(0,n.jsx)("p",{className:"text-[11px]",style:{color:"error"===l.phase?"var(--color-error, #ef4444)":"var(--color-text-muted)"},children:l.message})]})}function uP(e){let{tone:t,children:r}=e;return(0,n.jsx)("div",{className:"rounded-xl px-3 py-2 text-sm",style:{info:{background:"color-mix(in srgb, var(--color-accent) 10%, transparent)",color:"var(--color-text)",border:"1px solid color-mix(in srgb, var(--color-accent) 30%, transparent)"},success:{background:"color-mix(in srgb, var(--color-success, #22c55e) 12%, transparent)",color:"var(--color-success, #22c55e)",border:"1px solid color-mix(in srgb, var(--color-success, #22c55e) 28%, transparent)"},error:{background:"color-mix(in srgb, var(--color-error, #ef4444) 12%, transparent)",color:"var(--color-error, #ef4444)",border:"1px solid color-mix(in srgb, var(--color-error, #ef4444) 28%, transparent)"}}[t],children:r})}let uB=[{id:"installed",label:"Installed",icon:function(){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:"m7.5 4.27 9 5.15"}),(0,n.jsx)("path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z"}),(0,n.jsx)("path",{d:"m3.3 7 8.7 5 8.7-5"}),(0,n.jsx)("path",{d:"M12 22V12"})]})}},{id:"browse",label:"Browse",icon:function(){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:"10"}),(0,n.jsx)("polygon",{points:"16.24 7.76 14.12 14.12 7.76 16.24 9.88 9.88 16.24 7.76"})]})}}];function uW(){let{embedded:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},[t,r]=(0,o.useState)("installed"),[l,a]=(0,o.useState)([]),[s,i]=(0,o.useState)({}),[c,d]=(0,o.useState)(!0),[u,p]=(0,o.useState)(!1),[h,m]=(0,o.useState)(null),[x,f]=(0,o.useState)(""),[v,g]=(0,o.useState)(null),[y,b]=(0,o.useState)(null),[j,k]=(0,o.useState)([]),[w,N]=(0,o.useState)(!1),[C,S]=(0,o.useState)(null),[M,T]=(0,o.useState)(""),L=(0,o.useRef)(void 0),I=(0,o.useRef)(null),_=(0,o.useRef)(!1),[R,E]=(0,o.useState)({}),[D,A]=(0,o.useState)(null),[F,P]=(0,o.useState)([]),B=(0,o.useRef)(!1),[W,O]=(0,o.useState)(!1),[z,U]=(0,o.useState)([]),[H,V]=(0,o.useState)(null),[K,J]=(0,o.useState)(null),[q,G]=(0,o.useState)(null),[$,Y]=(0,o.useState)(!1),Z=(0,o.useMemo)(()=>{let e=new Map;for(let t of l)e.set(t.slug,t);for(let t of Object.values(s))e.has(t.slug)||e.set(t.slug,t);return Array.from(e.values()).sort((e,t)=>e.name.localeCompare(t.name))},[s,l]),Q=(0,o.useMemo)(()=>new Set(Z.map(e=>e.slug)),[Z]),X=(0,o.useCallback)(async function(){let{showSpinner:e=!1}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e?d(!0):p(!0),m(null);try{var t;let e=await fetch("/api/skills");if(!e.ok)throw Error("Failed to load installed skills (".concat(e.status,")"));let r=null!=(t=(await e.json()).skills)?t:[];return a(r),i(e=>{if(0===Object.keys(e).length)return e;let t={...e};for(let e of r)delete t[e.slug];return t}),!0}catch(e){return m(e instanceof Error?e.message:"Failed to load installed skills"),!1}finally{e&&d(!1),p(!1)}},[]);(0,o.useEffect)(()=>{X({showSpinner:!0})},[X]);let ee=(0,o.useCallback)(async(e,t)=>{var r,n;null==(r=I.current)||r.abort();let o=new AbortController;I.current=o,N(!0),S(null);try{let r=new URLSearchParams;(null==e?void 0:e.trim())?r.set("q",e.trim()):t&&r.set("category",t);let l=await fetch("/api/skills/browse?".concat(r.toString()),{signal:o.signal}),a=await l.json();if(o.signal.aborted)return;a.error&&S(a.error),k(null!=(n=a.skills)?n:[]),a.categories&&U(a.categories)}catch(e){if(o.signal.aborted)return;S(e instanceof Error?e.message:"Failed to load skills"),k([])}finally{o.signal.aborted||N(!1)}},[]),et=(0,o.useCallback)(async()=>{O(!0);try{var e;let t=await fetch("/api/skills/browse?featured=true"),r=await t.json();P(null!=(e=r.skills)?e:[]),r.categories&&U(r.categories)}catch(e){P([])}finally{O(!1)}},[]);(0,o.useEffect)(()=>{"browse"!==t||B.current||W||(B.current=!0,et()),"browse"!==t||_.current||w||(_.current=!0,ee())},[t,W,w,ee,et]);let er=(0,o.useCallback)(e=>{T(e),clearTimeout(L.current),L.current=setTimeout(()=>{ee(e,H)},300)},[ee,H]),en=(0,o.useCallback)(e=>{V(e),T(""),ee("",e)},[ee]),eo=(0,o.useCallback)(async e=>{g(e),A(null);try{let r=await fetch("/api/skills/".concat(encodeURIComponent(e)),{method:"DELETE"}),n=await r.json();if(n.ok)a(t=>t.filter(t=>t.slug!==e)),i(t=>{if(!(e in t))return t;let r={...t};return delete r[e],r}),E(t=>{if(!(e in t))return t;let r={...t};return delete r[e],r}),A({tone:"success",text:"Removed ".concat(e,".")}),(null==K?void 0:K.slug)===e&&J(null);else{var t;A({tone:"error",text:null!=(t=n.error)?t:"Failed to remove ".concat(e,".")})}}catch(t){A({tone:"error",text:t instanceof Error?t.message:"Failed to remove ".concat(e,".")})}finally{g(null),b(null)}},[null==K?void 0:K.slug]),el=(0,o.useCallback)(async e=>{A({tone:"info",text:"Installing ".concat(e.displayName,"...")}),E(t=>({...t,[e.slug]:{phase:"installing",message:"Installing ".concat(e.displayName,"...")}}));try{var t,r;let n=await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({slug:e.slug,source:e.source})}),o=await n.json();if(!n.ok||!o.ok)throw Error(null!=(t=o.error)?t:"Failed to install ".concat(e.displayName));let l=null!=(r=o.skill)?r:{name:e.displayName,slug:e.slug,description:e.summary,source:"skills.sh",filePath:"",protected:!1};i(e=>({...e,[l.slug]:l})),E(t=>({...t,[e.slug]:{phase:"refreshing",message:"Refreshing installed skills..."}})),A({tone:"info",text:"Installed ".concat(e.displayName,". Refreshing the Installed list...")}),await X()?(E(t=>({...t,[e.slug]:{phase:"success",message:"".concat(e.displayName," installed successfully.")}})),A({tone:"success",text:"".concat(e.displayName," is now installed.")})):(E(t=>({...t,[e.slug]:{phase:"success",message:"".concat(e.displayName," was installed, but the Installed list could not be refreshed.")}})),A({tone:"info",text:"".concat(e.displayName," was installed, but we could not refresh the Installed list automatically.")}))}catch(r){let t=r instanceof Error?r.message:"Failed to install ".concat(e.displayName);E(r=>({...r,[e.slug]:{phase:"error",message:t}})),A({tone:"error",text:t})}},[X]),ea=(0,o.useCallback)(async e=>{J(e),G(null),Y(!0);try{let r=await fetch("/api/skills/".concat(encodeURIComponent(e.slug),"/content"));if(r.ok){var t;let e=await r.json();G(null!=(t=e.content)?t:null)}}catch(e){}finally{Y(!1)}},[]),es=(0,o.useMemo)(()=>{if(!x.trim())return Z;let e=x.toLowerCase();return Z.filter(t=>t.name.toLowerCase().includes(e)||t.description.toLowerCase().includes(e))},[Z,x]),ei="browse"===t&&!M.trim()&&!H,ec=(0,o.useMemo)(()=>F.slice(0,6),[F]);return(0,n.jsxs)("div",{className:e?"":"p-6 max-w-5xl mx-auto",children:[!e&&(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:"Skill Store"}),(0,n.jsxs)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:[Z.length," skill",1!==Z.length?"s":""," installed"]})]})}),(0,n.jsx)("div",{className:"flex w-fit items-center gap-1 mb-6 rounded-xl p-1",style:{background:"var(--color-surface-hover)"},children:uB.map(e=>{let o=e.icon;return(0,n.jsxs)("button",{type:"button",onClick:()=>r(e.id),className:"px-4 py-1.5 rounded-lg text-sm font-medium transition-all cursor-pointer flex items-center gap-1.5",style:{background:t===e.id?"var(--color-surface)":"transparent",color:t===e.id?"var(--color-text)":"var(--color-text-muted)",boxShadow:t===e.id?"var(--shadow-sm)":"none"},children:[(0,n.jsx)(o,{}),e.label]},e.id)})}),(0,n.jsx)("div",{className:"mb-4",children:(0,n.jsx)("input",{type:"text",value:"installed"===t?x:M,onChange:e=>"installed"===t?f(e.target.value):er(e.target.value),placeholder:"installed"===t?"Filter installed skills...":"Search skills...",className:"w-full px-3 py-2 rounded-xl text-sm outline-none",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",color:"var(--color-text)"}})}),"browse"===t&&z.length>0&&(0,n.jsxs)("div",{className:"mb-4 flex flex-wrap gap-1.5",children:[(0,n.jsx)("button",{type:"button",onClick:()=>en(null),className:"rounded-full px-2.5 py-1 text-[11px] font-medium transition-colors cursor-pointer",style:{background:H?"var(--color-surface)":"var(--color-accent)",color:H?"var(--color-text-muted)":"var(--color-bg, #fff)",border:H?"1px solid var(--color-border)":"none"},children:"All"}),z.map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>en(H===e?null:e),className:"rounded-full px-2.5 py-1 text-[11px] font-medium transition-colors cursor-pointer",style:{background:H===e?"var(--color-accent)":"var(--color-surface)",color:H===e?"var(--color-bg, #fff)":"var(--color-text-muted)",border:H===e?"none":"1px solid var(--color-border)"},children:e},e))]}),(D||u||h)&&(0,n.jsxs)("div",{className:"mb-4 space-y-2",children:[D&&(0,n.jsx)(uP,{tone:D.tone,children:D.text}),u&&(0,n.jsx)(uP,{tone:"info",children:"Refreshing installed skills..."}),h&&(0,n.jsx)(uP,{tone:"error",children:h})]}),"installed"===t&&(0,n.jsx)(uO,{skills:es,loading:c,error:h,removingSlug:v,confirmRemove:y,onConfirmRemove:b,onRemove:eo,onRetry:()=>void X({showSpinner:!0}),onSkillClick:ea}),"browse"===t&&(0,n.jsx)(uz,{skills:j,loading:w,error:C,installedSlugs:Q,installStatuses:R,onInstall:el,onRetry:()=>void ee(M,H),showFeatured:ei,featuredSkills:ec,featuredLoading:W}),K&&(0,n.jsx)(uU,{skill:K,content:q,loading:$,onClose:()=>J(null),onRemove:e=>{J(null),b(null),eo(e)}})]})}function uO(e){let{skills:t,loading:r,error:o,removingSlug:l,confirmRemove:a,onConfirmRemove:s,onRemove:i,onRetry:c,onSkillClick:d}=e;return r?(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)"}})}):o&&0===t.length?(0,n.jsxs)("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 mb-3",style:{color:"var(--color-text-muted)"},children:"Could not load installed skills"}),(0,n.jsx)("p",{className:"text-xs mb-4",style:{color:"var(--color-text-muted)"},children:o}),(0,n.jsx)("button",{type:"button",onClick:c,className:"text-xs px-3 py-1.5 rounded-lg cursor-pointer",style:{background:"var(--color-accent)",color:"var(--color-bg)"},children:"Retry"})]}):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 installed skills found."})}):(0,n.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:t.map(e=>(0,n.jsx)(uA,{skill:e,removingSlug:l,confirmRemove:a,onConfirmRemove:s,onRemove:i,onClick:()=>d(e)},e.slug))})}function uz(e){let{skills:t,loading:r,error:o,installedSlugs:l,installStatuses:a,onInstall:s,onRetry:i,showFeatured:c,featuredSkills:d,featuredLoading:u}=e;return r&&0===t.length&&0===d.length?(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)"}})}):o&&0===t.length&&0===d.length?(0,n.jsxs)("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 mb-3",style:{color:"var(--color-text-muted)"},children:"Could not load skills"}),(0,n.jsx)("p",{className:"text-xs mb-4",style:{color:"var(--color-text-muted)"},children:o}),(0,n.jsx)("button",{type:"button",onClick:i,className:"text-xs px-3 py-1.5 rounded-lg cursor-pointer",style:{background:"var(--color-accent)",color:"var(--color-bg)"},children:"Retry"})]}):c||0!==t.length?(0,n.jsxs)("div",{className:"space-y-6",children:[c&&d.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-xs font-semibold uppercase tracking-wider mb-3",style:{color:"var(--color-text-muted)"},children:"Popular Skills"}),u?(0,n.jsx)("div",{className:"flex items-center justify-center py-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,n.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:d.map(e=>(0,n.jsx)(uF,{skill:e,isInstalled:l.has(e.slug),installStatus:a[e.slug],onInstall:()=>s(e),featured:!0},e.slug))})]}),t.length>0&&(0,n.jsxs)("div",{children:[c&&(0,n.jsx)("h2",{className:"text-xs font-semibold uppercase tracking-wider mb-3",style:{color:"var(--color-text-muted)"},children:"All Skills"}),r&&(0,n.jsx)("div",{className:"text-xs mb-2",style:{color:"var(--color-text-muted)"},children:"Loading skills..."}),(0,n.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:t.map(e=>(0,n.jsx)(uF,{skill:e,isInstalled:l.has(e.slug),installStatus:a[e.slug],onInstall:()=>s(e)},e.slug))})]})]}):(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 skills found."})})}function uU(e){let{skill:t,content:r,loading:l,onClose:a,onRemove:s}=e;return(0,o.useEffect)(()=>{let e=e=>{"Escape"===e.key&&a()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[a]),(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"fixed inset-0 z-40",style:{background:"rgba(0,0,0,0.4)"},onClick:a,role:"presentation"}),(0,n.jsxs)("div",{className:"fixed top-0 right-0 bottom-0 z-50 w-full max-w-lg flex flex-col overflow-hidden",style:{background:"var(--color-bg, #0a0a0a)",borderLeft:"1px solid var(--color-border)"},role:"dialog","aria-label":"".concat(t.name," details"),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 shrink-0",style:{borderBottom:"1px solid var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[t.emoji&&(0,n.jsx)("span",{className:"text-xl",children:t.emoji}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("h2",{className:"text-base font-semibold truncate",style:{color:"var(--color-text)"},children:t.name}),(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:t.source})]})]}),(0,n.jsx)("button",{type:"button",onClick:a,className:"p-1.5 rounded-lg cursor-pointer transition-colors",style:{color:"var(--color-text-muted)"},"aria-label":"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)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto px-6 py-5",children:[t.description&&(0,n.jsx)("p",{className:"text-sm mb-4 leading-relaxed",style:{color:"var(--color-text-muted)"},children:t.description}),l?(0,n.jsx)("div",{className:"flex items-center justify-center py-12",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)"}})}):r?(0,n.jsx)("div",{className:"prose prose-sm prose-invert max-w-none",children:(0,n.jsx)("pre",{className:"text-xs leading-relaxed whitespace-pre-wrap",style:{color:"var(--color-text)",background:"transparent",border:"none",padding:0},children:r})}):(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"No content available for this skill."})]}),!t.protected&&(0,n.jsx)("div",{className:"px-6 py-4 shrink-0",style:{borderTop:"1px solid var(--color-border)"},children:(0,n.jsx)("button",{type:"button",onClick:()=>s(t.slug),className:"text-sm px-4 py-2 rounded-xl cursor-pointer transition-colors w-full",style:{background:"color-mix(in srgb, var(--color-error, #ef4444) 12%, transparent)",color:"var(--color-error, #ef4444)",border:"1px solid color-mix(in srgb, var(--color-error, #ef4444) 28%, transparent)"},children:"Remove Skill"})})]})]})}function uH(e){var t;let{logo:r,name:l,slug:a}=e,[s,i]=(0,o.useState)(!1),c=cD({toolkitSlug:a,toolkitName:l,initialLogo:r}),d=c.logo&&!s;return(0,n.jsx)("div",{className:"flex h-12 w-12 shrink-0 items-center justify-center overflow-hidden",style:{background:"var(--color-surface-hover)",borderRadius:"13px",boxShadow:"inset 0 0 0 0.5px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.06)"},children:d?(0,n.jsx)("img",{src:null!=(t=c.logo)?t:void 0,alt:"",className:"h-7 w-7 object-contain",loading:"lazy",decoding:"async",onError:()=>i(!0)}):(0,n.jsx)("span",{className:"text-sm font-semibold uppercase",style:{color:"var(--color-text-muted)"},children:l.slice(0,2)})})}function uV(e){let{toolkit:t,activeConnections:r,totalConnections:o,mode:l="marketplace",onClick:a}=e,s=r>0;return(0,n.jsxs)("div",{className:"group rounded-2xl p-3.5 flex items-start gap-3.5 cursor-pointer transition-shadow duration-200 hover:shadow-md",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},onClick:a,role:"button",tabIndex:0,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&a()},"aria-label":"".concat(s?"Manage":"Get"," ").concat(t.name),children:[(0,n.jsx)(uH,{logo:t.logo,name:t.name,slug:t.slug}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 pt-0.5",children:[(0,n.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("div",{className:"text-[13px] font-semibold truncate leading-tight",style:{color:"var(--color-text)"},children:t.name}),(0,n.jsxs)("div",{className:"flex items-center gap-1 mt-0.5 text-[11px]",children:[s&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"font-medium",style:{color:"var(--color-success, #34C759)"},children:[r," account",1===r?"":"s"]}),(t.tools_count>0||"number"==typeof o&&o>r)&&(0,n.jsx)("span",{style:{color:"var(--color-text-muted)"},children:"\xb7"})]}),s&&"number"==typeof o&&o>r&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{style:{color:"var(--color-text-muted)"},children:[o," total"]}),t.tools_count>0&&(0,n.jsx)("span",{style:{color:"var(--color-text-muted)"},children:"\xb7"})]}),t.tools_count>0&&(0,n.jsxs)("span",{style:{color:"var(--color-text-muted)"},children:[t.tools_count," tool",1===t.tools_count?"":"s"]})]})]}),(0,n.jsx)("span",{className:"shrink-0 rounded-full px-3.5 py-1 text-[12px] font-bold mt-0.5",style:s?{background:"var(--color-surface-hover)",color:"var(--color-accent)"}:{background:"var(--color-accent)",color:"#fff"},children:s?"Connected":"Connect"})]}),t.description&&(0,n.jsx)("p",{className:"text-[11px] leading-relaxed line-clamp-2 mt-1.5",style:{color:"var(--color-text-muted)"},children:t.description})]})]})}function uK(e){var t;let{logo:r,name:l,slug:a}=e,[s,i]=(0,o.useState)(!1),c=cD({toolkitSlug:a,toolkitName:l,initialLogo:r}),d=c.logo&&!s;return(0,n.jsx)("div",{className:"flex h-12 w-12 items-center justify-center overflow-hidden rounded-xl",style:{background:"var(--color-surface-hover)",border:"1px solid var(--color-border)"},children:d?(0,n.jsx)("img",{src:null!=(t=c.logo)?t:void 0,alt:"",className:"h-8 w-8 object-contain",decoding:"async",onError:()=>i(!0)}):(0,n.jsx)("span",{className:"text-base font-semibold uppercase",style:{color:"var(--color-text-muted)"},children:l.slice(0,2)})})}function uJ(e){var t;return null!=(t=({OAUTH2:"OAuth 2.0",OAUTH1:"OAuth 1.0",API_KEY:"API Key",BASIC:"Basic Auth",BEARER_TOKEN:"Bearer Token",JWT:"JWT",NO_AUTH:"No Auth"})[e])?t:e.replace(/_/g," ")}function uq(e){let t=Date.parse(e);return Number.isFinite(t)?new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",year:"numeric"}).format(t):"Connected recently"}function uG(e){let{toolkit:t,connections:r,open:l,preferredAction:a,onOpenChange:s,onConnectionChange:i}=e,[c,d]=(0,o.useState)(!1),[u,p]=(0,o.useState)(null),[h,m]=(0,o.useState)(null),x=(0,o.useRef)(null),f=(0,o.useRef)(null),v=(0,o.useRef)(!1),g=(0,o.useMemo)(()=>i_(r),[r]),y=(0,o.useMemo)(()=>g.filter(e=>e.is_active),[g]),b=y.length>0,j=null!=a?a:g.length>0?"reconnect":"connect",k=(0,o.useCallback)(()=>{null!==f.current&&(window.clearInterval(f.current),f.current=null)},[]),w=(0,o.useCallback)(()=>{k(),x.current=null,v.current=!1},[k]);(0,o.useEffect)(()=>{l||(m(null),d(!1),p(null),w())},[w,l]),(0,o.useEffect)(()=>w,[w]),(0,o.useEffect)(()=>{function e(e){var r,n,o;(null==(r=e.data)?void 0:r.type)==="composio-callback"&&e.origin===window.location.origin&&(v.current=!0,k(),x.current=null,d(!1),"success"===e.data.status?(i({toolkit:t,connected:!0,connectedToolkitSlug:"string"==typeof e.data.connected_toolkit_slug?e.data.connected_toolkit_slug:null!=(n=null==t?void 0:t.slug)?n:null,connectedToolkitName:"string"==typeof e.data.connected_toolkit_name?e.data.connected_toolkit_name:null!=(o=null==t?void 0:t.name)?o:null,shouldProbeLiveAgent:!0}),s(!1)):m("Connection was not completed. Please try again."))}return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[i,s,k,t]);let N=(0,o.useCallback)(async()=>{if(t){if(b)return void m("Disconnect ".concat(t.name," before connecting a different account."));d(!0),m(null),w();try{var e,r,n,o,l;let a=await fetch("/api/composio/connect",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({toolkit:null!=(r=t.connect_slug)?r:t.slug})}),c=await a.json();if(!a.ok)throw Error(null!=(n=c.error)?n:"Failed to start connection.");let u=null!=(o=c.connected_account_id)?o:c.connection_id;if(c.already_connected&&u){i({toolkit:t,connected:!0,connectedToolkitSlug:"string"==typeof c.connected_toolkit_slug?c.connected_toolkit_slug:t.slug,connectedToolkitName:"string"==typeof c.connected_toolkit_name?c.connected_toolkit_name:t.name,shouldProbeLiveAgent:!0}),d(!1),s(!1);return}if(!c.redirect_url)throw Error(null!=(l=c.error)?l:"Failed to start connection.");let p=window.open(c.redirect_url,"_blank","popup=yes,width=560,height=720,resizable=yes,scrollbars=yes");if(!p)throw Error("Popup was blocked. Please allow popups and try again.");x.current=p,v.current=!1,null==(e=p.focus)||e.call(p),f.current=window.setInterval(()=>{let e=x.current;e&&e.closed&&(k(),x.current=null,d(!1),v.current||(i({toolkit:t}),s(!1)))},500)}catch(e){d(!1),m(e instanceof Error?e.message:"Failed to connect.")}}},[w,b,i,s,k,t]),C=(0,o.useCallback)(async e=>{p(e),m(null);try{let n=await fetch("/api/composio/disconnect",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({connection_id:e})}),o=await n.json();if(!n.ok){var r;throw Error(null!=(r=o.error)?r:"Failed to disconnect.")}i({toolkit:t,connected:!1})}catch(e){m(e instanceof Error?e.message:"Failed to disconnect.")}finally{p(null)}},[i]);if(!t)return null;let S=t.auth_schemes.length>0?t.auth_schemes.map(uJ).join(", "):null;return(0,n.jsx)(cT.lG,{open:l,onOpenChange:s,children:(0,n.jsxs)(cT.Cf,{className:"sm:max-w-lg p-0 gap-0 overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-6 pt-6 pb-4",style:{borderBottom:"1px solid var(--color-border)"},children:[(0,n.jsx)(cT.c7,{className:"space-y-0",children:(0,n.jsxs)("div",{className:"flex items-start gap-4",children:[(0,n.jsx)(uK,{logo:t.logo,name:t.name,slug:t.slug}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)(cT.L3,{className:"text-lg leading-tight",children:t.name}),t.description&&(0,n.jsx)(cT.rr,{className:"mt-1 text-[13px] leading-relaxed line-clamp-2",children:t.description})]})]})}),(0,n.jsxs)("div",{className:"mt-4 flex flex-wrap items-center gap-3",children:[t.tools_count>0&&(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1 text-xs font-medium",style:{background:"var(--color-surface-hover)",color:"var(--color-text)"},children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),t.tools_count," tool",1!==t.tools_count?"s":""]}),S&&(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1 text-xs font-medium",style:{background:"var(--color-surface-hover)",color:"var(--color-text)"},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)("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),S]}),b&&(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1 text-xs font-medium",style:{background:"rgba(16, 185, 129, 0.1)",color:"rgb(74 222 128)",border:"1px solid rgba(16, 185, 129, 0.2)"},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),y.length," connected"]})]}),t.categories.length>0&&(0,n.jsx)("div",{className:"mt-3 flex flex-wrap gap-1.5",children:t.categories.slice(0,5).map(e=>(0,n.jsx)("span",{className:"rounded-full px-2 py-0.5 text-[11px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:e},e))})]}),(0,n.jsxs)("div",{className:"px-6 py-4 space-y-3 max-h-[340px] overflow-y-auto",children:[h&&(0,n.jsx)("div",{className:"rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-[12px] text-red-300",children:h}),g.length>0?(0,n.jsxs)("div",{className:"space-y-2",children:[b&&(0,n.jsxs)("div",{className:"rounded-lg border px-3 py-2 text-[12px]",style:{borderColor:"var(--color-border)",background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:["One ",t.name," account can be connected at a time. Disconnect the current connection before connecting a different account."]}),(0,n.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,n.jsx)("h4",{className:"text-xs font-semibold uppercase tracking-[0.14em] text-muted-foreground",children:"Connections"}),(0,n.jsxs)("span",{className:"text-[11px] text-muted-foreground",children:[g.length," total"]})]}),g.map((e,t)=>{let r=e.is_active?"Disconnect":"Remove",o=e.is_same_account_reconnect,l="gateway_stable_id"!==e.account_identity_source;return(0,n.jsx)("div",{className:"rounded-xl border px-3 py-3",style:{borderColor:e.is_active?"rgba(16, 185, 129, 0.22)":"var(--color-border)",background:e.is_active?"rgba(16, 185, 129, 0.05)":"var(--color-surface-hover)"},children:(0,n.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,n.jsx)("p",{className:"truncate text-sm font-medium text-foreground",children:e.display_label}),(0,n.jsx)("span",{className:"inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium",style:{background:e.is_active?"rgba(16, 185, 129, 0.15)":"var(--color-background)",color:e.is_active?"rgb(74 222 128)":"var(--color-text-muted)",border:e.is_active?"1px solid rgba(16, 185, 129, 0.24)":"1px solid var(--color-border)"},children:e.normalized_status})]}),(0,n.jsx)("p",{className:"mt-1 text-[11px] text-muted-foreground",children:e.account_email||e.account_name||e.account_label?"Added ".concat(uq(e.created_at)):"Connection ".concat(t+1," \xb7 Added ").concat(uq(e.created_at))}),(o||l)&&(0,n.jsxs)("div",{className:"mt-2 flex flex-wrap gap-1.5",children:[o&&(0,n.jsx)("span",{className:"inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium",style:{background:"rgba(96, 165, 250, 0.12)",color:"rgb(147 197 253)",border:"1px solid rgba(96, 165, 250, 0.2)"},children:"Same account reconnected"}),l&&(0,n.jsx)("span",{className:"inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium",style:{background:"var(--color-background)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:"Identity inferred"})]})]}),(0,n.jsx)(sS.$,{variant:"outline",size:"sm",onClick:()=>void C(e.id),disabled:u===e.id,children:u===e.id?"".concat(r,"..."):r})]})},e.id)})]}):(0,n.jsxs)("div",{className:"px-3 py-5 text-center text-sm",style:{color:"#a3a3a3"},children:["No accounts connected yet. Connect your ",t.name," account to get started."]})]}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-6 py-4",style:{borderTop:"1px solid var(--color-border)"},children:[(0,n.jsx)("button",{type:"button",className:"rounded-full px-4 py-1.5 text-sm font-medium transition-all bg-stone-100 hover:bg-stone-200/50",style:{color:"#57534e"},onClick:()=>s(!1),children:"Close"}),!b&&(0,n.jsx)("button",{type:"button",className:"rounded-full px-4 py-1.5 text-sm font-medium",style:{background:"var(--color-accent)",color:"#fff"},onClick:()=>void N(),disabled:c,children:c?"Waiting for authorization...":"reconnect"===j?"Reconnect ".concat(t.name):"Connect ".concat(t.name)})]})]})})}let u$=["gmail","slack","github","notion","google-calendar","linear","airtable","hubspot","salesforce","jira","asana","discord"];function uY(){return(0,n.jsxs)("svg",{className:"absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none",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)"},children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}let uZ=null,uQ="composio-connected-apps-snapshot";function uX(e){let t=new Map;for(let r of e)t.set(iy(r.slug),r);return Array.from(t.values())}function u0(){var e,t;return uZ||(uZ=function(){try{let e=localStorage.getItem(uQ);if(!e)return null;let t=JSON.parse(e);if(Array.isArray(null==t?void 0:t.connectedToolkits)&&Array.isArray(null==t?void 0:t.connections))return t}catch(e){}return null}()),{connectedToolkits:null!=(e=null==uZ?void 0:uZ.connectedToolkits)?e:[],marketplaceToolkits:[],marketplaceCursor:null,connections:null!=(t=null==uZ?void 0:uZ.connections)?t:[],categories:[],loading:null===uZ,marketplaceLoading:!1,marketplaceReady:!1,loadingMore:!1,error:null,connectionsError:null}}function u1(e){var t,r,l,a;let{eligible:s,lockBadge:i}=e,[c,d]=(0,o.useState)(u0),[u,p]=(0,o.useState)(""),[h,m]=(0,o.useState)(""),[x,f]=(0,o.useState)(null),[v,g]=(0,o.useState)(null),[y,b]=(0,o.useState)(!1),[j,k]=(0,o.useState)(null),[w,N]=(0,o.useState)(null),[C,S]=(0,o.useState)(!1),[M,T]=(0,o.useState)([]),L=(0,o.useRef)(!1),I=(0,o.useRef)(""),_=(0,o.useRef)(null),R=(0,o.useCallback)(async e=>{let t=new URLSearchParams;(null==e?void 0:e.search)&&t.set("search",e.search),(null==e?void 0:e.category)&&t.set("category",e.category),(null==e?void 0:e.cursor)&&t.set("cursor",e.cursor),(null==e?void 0:e.limit)&&t.set("limit",String(e.limit));let r=t.toString(),n=await fetch("/api/composio/toolkits".concat(r?"?".concat(r):""));if(!n.ok){var o;throw Error(null!=(o=(await n.json().catch(()=>({}))).error)?o:"Failed to load apps (".concat(n.status,")"))}return iC(await n.json())},[]),E=(0,o.useCallback)(async e=>{try{var t;let r=e?await fetch("/api/composio/status",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:e})}):await fetch("/api/composio/status");if(r.ok){k(await r.json()),N(null);return}k(null);let n=await r.json().catch(()=>({}));N(null!=(t=n.error)?t:iH("load",r.status))}catch(e){k(null),N(e instanceof Error?e.message:iH("load"))}},[]),D=(0,o.useCallback)(async e=>{d(e=>({...e,loading:0===e.connectedToolkits.length&&0===e.connections.length,error:null,connectionsError:null})),N(null),R({limit:24}).then(e=>{let t=new Set(u$),r=[...e.items.filter(e=>t.has(e.slug)).sort((e,t)=>u$.indexOf(e.slug)-u$.indexOf(t.slug)),...e.items.filter(e=>!t.has(e.slug))];d(t=>t.marketplaceReady?t:{...t,marketplaceToolkits:r,marketplaceCursor:e.cursor,categories:e.categories,marketplaceReady:!0,marketplaceLoading:!1}),I.current="::"}).catch(()=>{});try{let o=await fetch("/api/composio/connections?include_toolkits=1".concat((null==e?void 0:e.fresh)?"&fresh=1":"")),l={items:[]},a=null;o.ok?l=await o.json():a=null!=(t=(await o.json().catch(()=>({}))).error)?t:"Failed to load connections (".concat(o.status,")");let s=iS(l),i=uX(null!=(r=l.toolkits)?r:[]).sort((e,t)=>e.name.localeCompare(t.name));var t,r,n=uZ={connectedToolkits:i,connections:s};try{localStorage.setItem(uQ,JSON.stringify(n))}catch(e){}T(e=>e.filter(e=>!i.some(t=>iy(t.slug)===iy(e.slug)))),d(e=>({...e,connectedToolkits:i,connections:s,loading:!1,error:null,connectionsError:a})),window.setTimeout(()=>{E()},0)}catch(e){k(null),d(t=>({...t,loading:!1,error:t.connectedToolkits.length>0||t.connections.length>0?t.error:e instanceof Error?e.message:"Failed to load apps.",connectionsError:e instanceof Error?e.message:"Failed to load connections."}))}},[E,R]),A=(0,o.useCallback)(async e=>{var t;let r=null!=(t=null==e?void 0:e.reset)&&t,n=h.trim(),o="".concat(n.toLowerCase(),"::").concat(null!=x?x:""),l=r&&c.marketplaceReady;r?(I.current=o,d(e=>({...e,marketplaceToolkits:l?e.marketplaceToolkits:[],marketplaceCursor:null,categories:l?e.categories:[],marketplaceLoading:!0,marketplaceReady:l,loadingMore:!1,error:null}))):d(e=>({...e,loadingMore:!0}));try{let e=r?null:c.marketplaceCursor,t=await R({search:n||void 0,category:null!=x?x:void 0,cursor:e,limit:24});if(I.current!==o)return;d(e=>{let o=r?t.items:uX([...e.marketplaceToolkits,...t.items]),l=new Set(u$),a=n||x?o:[...o.filter(e=>l.has(e.slug)).sort((e,t)=>u$.indexOf(e.slug)-u$.indexOf(t.slug)),...o.filter(e=>!l.has(e.slug))];return{...e,marketplaceToolkits:a,marketplaceCursor:t.cursor,categories:t.categories,marketplaceLoading:!1,marketplaceReady:!0,loadingMore:!1,error:null}})}catch(e){if(I.current!==o)return;d(t=>({...t,marketplaceLoading:!1,marketplaceReady:!0,loadingMore:!1,error:e instanceof Error?e.message:"Failed to load apps."}))}},[x,h,R,c.marketplaceCursor,c.marketplaceReady]);(0,o.useEffect)(()=>{let e=window.setTimeout(()=>{m(u)},300);return()=>window.clearTimeout(e)},[u]),(0,o.useEffect)(()=>{s?L.current||(L.current=!0,D({fresh:!0})):(L.current=!1,d(e=>({...e,loading:!1})))},[s,D]),(0,o.useEffect)(()=>{if(!s||c.loading)return;let e="".concat(h.trim().toLowerCase(),"::").concat(null!=x?x:"");c.marketplaceReady&&I.current===e||A({reset:!0})},[x,s,A,h,c.loading,c.marketplaceReady]);let F=(0,o.useMemo)(()=>i_(c.connections),[c.connections]),P=(0,o.useMemo)(()=>{let e=new Map;for(let t of F){let r=e.get(t.normalized_toolkit_slug);r?r.push(t):e.set(t.normalized_toolkit_slug,[t])}return e},[F]),B=(0,o.useMemo)(()=>{let e=new Map;for(let[t,r]of P){let n=r.filter(e=>e.is_active);n.length>0&&e.set(t,n)}return e},[P]),W=(0,o.useMemo)(()=>{let e=new Map;for(let[t,r]of B){let n=new Map;for(let e of r)n.has(e.account_identity)||n.set(e.account_identity,e);e.set(t,Array.from(n.values()))}return e},[B]),O=(0,o.useMemo)(()=>new Set(M.map(e=>iy(e.slug))),[M]),z=(0,o.useMemo)(()=>uX([...c.connectedToolkits,...M]).filter(e=>{let t=iy(e.slug);return W.has(t)||O.has(t)}),[W,M,O,c.connectedToolkits]),U=(0,o.useMemo)(()=>{let e=h.trim().toLowerCase();return c.marketplaceToolkits.filter(t=>{let r=iy(t.slug);return!(W.has(r)||O.has(r))&&(!e||t.name.toLowerCase().includes(e)||t.slug.toLowerCase().includes(e)||t.description.toLowerCase().includes(e))})},[W,h,O,c.marketplaceToolkits]),H=(0,o.useMemo)(()=>c.categories.slice(0,6),[c.categories]),V=v?null!=(r=P.get(iy(v.slug)))?r:[]:null,K=(0,o.useCallback)(e=>{g(e),b(!0)},[]),J=(0,o.useCallback)(e=>{if((null==e?void 0:e.toolkit)&&!1===e.connected){let t=iy(e.toolkit.slug);T(e=>e.filter(e=>iy(e.slug)!==t))}if(null==e?void 0:e.connected){var t,r,n,o,l,a,s,i,d,u;let p=null!=(o=null!=(n=e.connectedToolkitSlug)?n:null==(t=e.toolkit)?void 0:t.slug)?o:null,h=null!=(a=null!=(l=e.connectedToolkitName)?l:null==(r=e.toolkit)?void 0:r.name)?a:null;if(p&&h){let t=iy(p),r=null!=(i=[e.toolkit,...c.connectedToolkits,...c.marketplaceToolkits].filter(e=>!!e).find(e=>iy(e.slug)===t))?i:null,n=r?{...r,slug:t,name:h}:(u=null!=(d=null==(s=e.toolkit)?void 0:s.connect_slug)?d:p,{slug:iy(t),connect_slug:null!=u?u:t,name:h,description:"",logo:null,categories:[],auth_schemes:[],tools_count:0});T(e=>uX([...e.filter(e=>iy(e.slug)!==t),n]))}}D({fresh:!0}),(null==e?void 0:e.connected)&&window.setTimeout(()=>{D({fresh:!0})},1500),(null==e?void 0:e.shouldProbeLiveAgent)&&window.setTimeout(()=>{E("probe_live_agent")},300),A({reset:!0})},[D,E,A,c.connectedToolkits,c.marketplaceToolkits]),q=(0,o.useCallback)(async()=>{S(!0),N(null);try{let t=await fetch("/api/composio/status",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"repair_mcp"})}),r=await t.json().catch(()=>({}));if(!t.ok){var e;N(null!=(e=r.error)?e:iH("update"));return}k(r)}catch(e){N(e instanceof Error?e.message:iH("update"))}finally{S(!1)}},[]);if((0,o.useEffect)(()=>{if(!s||c.loading||c.marketplaceLoading||c.loadingMore||!c.marketplaceReady||!c.marketplaceCursor||!_.current)return;let e=_.current,t=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&A()},{rootMargin:"160px 0px"});return t.observe(e),()=>t.disconnect()},[s,A,c.loading,c.loadingMore,c.marketplaceCursor,c.marketplaceLoading,c.marketplaceReady]),!s)return(0,n.jsx)("div",{children:(0,n.jsx)("div",{className:"flex items-center justify-center rounded-2xl px-6 py-10",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Available with Dench Cloud"}),i&&(0,n.jsx)("span",{className:"mt-2 inline-flex items-center rounded-full px-3 py-1 text-[11px] font-medium",style:{background:"var(--color-surface-hover)",color:"var(--color-text)",border:"1px solid var(--color-border)"},children:i})]})})});let G=h.trim();return(0,n.jsxs)("div",{children:[(w||j&&"healthy"!==j.summary.level)&&(0,n.jsxs)("div",{className:"mb-6 flex items-start justify-between gap-3 rounded-xl px-3 py-2 text-xs",style:{background:"color-mix(in srgb, var(--color-error, #ef4444) 8%, transparent)",color:"var(--color-error, #ef4444)",border:"1px solid color-mix(in srgb, var(--color-error, #ef4444) 20%, transparent)"},children:[(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("p",{className:"truncate",children:null!=(l=null!=w?w:null==j?void 0:j.summary.message)?l:iU.attentionLabel}),!w&&(null==j?void 0:j.liveAgent.detail)&&"healthy"!==j.summary.level&&(0,n.jsx)("p",{className:"mt-1 text-[11px] opacity-80",children:j.liveAgent.detail}),!w&&(null!=(a=null==j||null==(t=j.liveAgent.evidence)?void 0:t.length)?a:0)>0&&(0,n.jsxs)("p",{className:"mt-1 truncate text-[11px] opacity-70",children:["Evidence: ",null==j?void 0:j.liveAgent.evidence.slice(0,3).join(", ")]})]}),(0,n.jsx)("button",{type:"button",onClick:()=>void q(),disabled:C,className:"shrink-0 rounded-lg px-2 py-1 text-[11px] font-medium cursor-pointer transition-colors",style:{background:"color-mix(in srgb, var(--color-error, #ef4444) 15%, transparent)"},children:C?"Repairing...":"Repair"})]}),c.loading&&(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)"}})}),!c.loading&&c.error&&(0,n.jsxs)("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 mb-3",style:{color:"var(--color-text-muted)"},children:c.error}),(0,n.jsx)(sS.$,{type:"button",variant:"outline",size:"sm",onClick:()=>void D(),children:"Retry"})]}),!c.loading&&!c.error&&(0,n.jsxs)(n.Fragment,{children:[z.length>0&&(0,n.jsxs)("section",{className:"mb-10",children:[(0,n.jsxs)("div",{className:"flex items-baseline gap-2.5 mb-4",children:[(0,n.jsx)("h2",{className:"text-lg font-bold tracking-tight",style:{color:"var(--color-text)"},children:"Your Apps"}),(0,n.jsx)("span",{className:"text-[11px] font-medium rounded-full px-2 py-0.5",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:z.length})]}),(0,n.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:z.map(e=>{var t,r,o;let l=iy(e.slug),a=null!=(r=W.get(l))?r:[],s=null!=(o=null==(t=P.get(l))?void 0:t.length)?o:0;return(0,n.jsx)(uV,{toolkit:e,activeConnections:a.length,totalConnections:s,mode:"connected",onClick:()=>K(e)},e.slug)})})]}),(0,n.jsxs)("section",{children:[(0,n.jsx)("h2",{className:"text-lg font-bold tracking-tight mb-4",style:{color:"var(--color-text)"},children:"Discover"}),(0,n.jsxs)("div",{className:"relative mb-4",children:[(0,n.jsx)(uY,{}),(0,n.jsx)("input",{type:"text",value:u,onChange:e=>p(e.target.value),placeholder:"Search apps...",className:"w-full pl-9 pr-4 py-2.5 rounded-xl text-sm outline-none transition-shadow focus:shadow-[0_0_0_3px_rgba(0,122,255,0.12)]",style:{background:"var(--color-surface-hover)",color:"var(--color-text)"}})]}),H.length>0&&(0,n.jsxs)("div",{className:"mb-4 flex flex-wrap gap-1.5",children:[(0,n.jsx)("button",{type:"button",onClick:()=>f(null),className:"rounded-full px-3 py-1 text-[11px] font-medium transition-colors cursor-pointer",style:{background:x?"var(--color-surface)":"var(--color-accent)",color:x?"var(--color-text-muted)":"var(--color-bg, #fff)",border:"1px solid ".concat(x?"var(--color-border)":"var(--color-accent)")},children:"All"}),H.map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>f(x===e?null:e),className:"rounded-full px-3 py-1 text-[11px] font-medium transition-colors cursor-pointer",style:{background:x===e?"var(--color-accent)":"var(--color-surface)",color:x===e?"var(--color-bg, #fff)":"var(--color-text-muted)",border:"1px solid ".concat(x===e?"var(--color-accent)":"var(--color-border)")},children:e},e))]}),c.marketplaceLoading&&c.marketplaceReady&&(0,n.jsx)("div",{className:"mb-4 text-xs",style:{color:"var(--color-text-muted)"},children:"Searching..."}),!c.marketplaceReady&&!c.loading&&(0,n.jsx)("div",{className:"flex items-center justify-center py-12",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)"}})}),c.marketplaceReady&&U.length>0&&(0,n.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:U.map(e=>(0,n.jsx)(uV,{toolkit:e,activeConnections:0,mode:"marketplace",onClick:()=>K(e)},e.slug))}),c.marketplaceReady&&!c.marketplaceLoading&&0===U.length&&(0,n.jsxs)("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:G?'No apps found for "'.concat(G,'".'):x?'No apps found in "'.concat(x,'".'):"No apps found."}),(G||x)&&(0,n.jsx)("p",{className:"mt-2 text-xs",style:{color:"var(--color-text-muted)"},children:"Try clearing search or category filters."})]}),(!!c.marketplaceCursor||c.loadingMore)&&(0,n.jsx)("div",{ref:_,className:"flex items-center justify-center py-6 text-xs",style:{color:"var(--color-text-muted)"},children:c.loadingMore?"Loading more apps...":"Scroll to load more"})]})]}),(0,n.jsx)(uG,{toolkit:v,connections:null!=V?V:[],open:y,onOpenChange:b,onConnectionChange:J})]})}function u2(){let{embedded:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},[t,r]=(0,o.useState)(null),[l,a]=(0,o.useState)(!0),[s,i]=(0,o.useState)(null),c=(0,o.useCallback)(async()=>{a(!0),i(null);try{let e=await fetch("/api/integrations");if(!e.ok)throw Error("Failed to load integrations (".concat(e.status,")"));let t=await e.json();r(t)}catch(e){i(e instanceof Error?e.message:"Failed to load integrations")}finally{a(!1)}},[]);return(0,o.useEffect)(()=>{c()},[c]),(0,n.jsxs)("div",{className:"",children:[!e&&(0,n.jsxs)("div",{className:"mb-6 flex items-start justify-between gap-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h1",{className:"font-instrument text-3xl tracking-tight",style:{color:"var(--color-text)"},children:"Integrations"}),(0,n.jsx)("p",{className:"mt-1 text-sm",style:{color:"var(--color-text-muted)"},children:"Connect third-party apps to your Dench Cloud workspace."})]}),(0,n.jsxs)("a",{className:"flex shrink-0 items-center gap-1.5 rounded-full px-3 py-1.5 text-[11px] font-medium transition-opacity hover:opacity-80",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",color:"var(--color-text-muted)"},children:["Powered by",(0,n.jsx)("img",{src:"/logo/composio.webp",alt:"Composio",className:"h-10 w-auto dark:invert"})]})]}),l&&(0,n.jsx)("div",{className:"flex items-center justify-center py-16",children:(0,n.jsx)("div",{className:"h-6 w-6 animate-spin rounded-full border-2",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}})}),!l&&s&&(0,n.jsxs)("div",{className:"rounded-xl border px-4 py-6 text-center",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("p",{className:"text-sm mb-3",style:{color:"var(--color-text-muted)"},children:s}),(0,n.jsx)(sS.$,{type:"button",variant:"outline",onClick:()=>void c(),children:"Retry"})]}),!l&&!s&&t&&(0,n.jsx)(u1,{eligible:!!(t.denchCloud.hasKey&&t.denchCloud.isPrimaryProvider),lockBadge:t.denchCloud.hasKey?t.denchCloud.isPrimaryProvider?null:"Use Dench Cloud":"Get Dench Cloud API Key"})]})}async function u4(e,t){let r=iy(e),n=null,o=[],l=await fetch("/api/composio/connections?include_toolkits=1&fresh=1");if(l.ok){let e=await l.json();o=iS(e).filter(e=>iy(e.toolkit_slug)===r),n=c_(Array.isArray(e.toolkits)?e.toolkits:[],r,t)}if(!n){let e=new URLSearchParams({search:(null==t?void 0:t.trim())||r,limit:"24"}),o=await fetch("/api/composio/toolkits?".concat(e.toString()));o.ok&&(n=c_(iC(await o.json()).items,r,t))}return{toolkit:n,connections:o}}function u5(e){let{request:t,onRequestHandled:r,onFallbackToIntegrations:l}=e,[a,s]=(0,o.useState)(!1),[i,c]=(0,o.useState)(null),[d,u]=(0,o.useState)([]),[p,h]=(0,o.useState)("connect"),m=(0,o.useRef)(0),x=(0,o.useCallback)(async(e,t)=>{var r,n;let o=null==(r=e.toolkitSlug)?void 0:r.trim();if(!o){s(!1),c(null),u([]),l();return}let a=iy(o),i=function(e,t){var r;let n=iy(e),o=ib(void 0,n);return{slug:n,connect_slug:null!=(r=ig[iy(n)])?r:n.trim().toLowerCase(),name:"string"==typeof t&&t.trim().length>0?t.trim():o.includes("-")?o.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "):o.charAt(0).toUpperCase()+o.slice(1),description:"",logo:null,categories:[],auth_schemes:[],tools_count:0}}(a,e.toolkitName),d=m.current+1;m.current=d,h(e.action),(null==t?void 0:t.openModal)!==!1&&(c(i),u([]),s(!0));try{let t=await u4(a,e.toolkitName);if(d!==m.current)return;c(null!=(n=t.toolkit)?n:i),u(t.connections)}catch(e){if(d!==m.current)return;c(e=>null!=e?e:i)}},[l]);(0,o.useEffect)(()=>{t&&(null==r||r(),x(t))},[x,r,t]);let f=(0,o.useCallback)(e=>{var t,r,n,o,l,a,s,c;let d=null!=(l=null!=(o=null!=(n=null==e?void 0:e.connectedToolkitSlug)?n:null==e||null==(t=e.toolkit)?void 0:t.slug)?o:null==i?void 0:i.slug)?l:null;d&&x({action:p,toolkitSlug:d,toolkitName:null!=(c=null!=(s=null!=(a=null==e?void 0:e.connectedToolkitName)?a:null==e||null==(r=e.toolkit)?void 0:r.name)?s:null==i?void 0:i.name)?c:null},{openModal:!1})},[x,p,null==i?void 0:i.name,null==i?void 0:i.slug]);return(0,n.jsx)(uG,{toolkit:i,connections:d,open:a,preferredAction:p,onOpenChange:s,onConnectionChange:f})}var u3=r(82958),u6=r(96863),u8=r(47734);function u7(e){let{model:t,className:r}=e,o=t.provider.trim().toLowerCase(),l={color:"currentColor"};if("minimax"===o||"mini-max"===o)return(0,n.jsx)("img",{src:"/models/minimax.png",alt:"",className:r,draggable:!1,"data-provider-icon":"minimax"});if("deepseek"===o)return(0,n.jsx)("img",{src:"/models/deepseek.ico",alt:"",className:r,draggable:!1,"data-provider-icon":"deepseek"});if("kimi"===o||"moonshot"===o||"moonshotai"===o)return(0,n.jsx)("img",{src:"/models/kimi.png",alt:"",className:r,draggable:!1,"data-provider-icon":"kimi"});switch(o){case"anthropic":case"claude":return(0,n.jsx)(s9.phd,{className:r,style:l,"data-provider-icon":"claude"});case"openai":case"chatgpt":return(0,n.jsx)(s9.pz8,{className:r,style:l,"data-provider-icon":"openai"});case"google":return(0,n.jsx)(s9.UKz,{className:r,style:{color:"#4285F4"},"data-provider-icon":"google"});case"meta":return(0,n.jsx)(s9.awM,{className:r,style:{color:"#0668E1"},"data-provider-icon":"meta"});case"mistral":return(0,n.jsx)(s9.$7J,{className:r,style:{color:"#FF7000"},"data-provider-icon":"mistral"});case"perplexity":return(0,n.jsx)(s9.X_y,{className:r,style:{color:"#20B8CD"},"data-provider-icon":"perplexity"});default:return(0,n.jsx)("span",{className:r,style:{color:"var(--color-text-muted)",fontSize:"0.75rem",fontWeight:600,lineHeight:1},"aria-hidden":!0,"data-provider-icon":"fallback",children:t.provider.slice(0,1).toUpperCase()})}}function u9(e){var t,r,o,l,a;let{models:s,selectedModel:i,onSelect:c,disabled:d=!1,loading:u=!1,disabledHint:p,fallbackToFirst:m=!0,placeholder:x="Choose a model...",ariaLabel:f="Select chat model",triggerClassName:v}=e,g=null!=(r=function(e,t){let r="string"==typeof t?t.trim():"";if(r)return e.find(e=>e.stableId===r||"string"==typeof e.catalogId&&e.catalogId.trim()===r)}(s,i))?r:m&&null!=(t=s[0])?t:null;if(0===s.length)return null;let y=d&&u?"Switching model…":d&&(null==p?void 0:p.trim())?p.trim():null!=(o=null==g?void 0:g.displayName)?o:x;return(0,n.jsxs)(tG.rI,{children:[(0,n.jsxs)(tG.ty,{className:(0,h.cn)("inline-flex max-w-full items-center gap-1.5 rounded-lg p-0 text-sm font-medium transition-opacity hover:opacity-100 disabled:cursor-not-allowed disabled:opacity-60",v),style:{color:"var(--color-text-secondary)",opacity:.9},"aria-label":f,title:y,disabled:d,children:[g?(0,n.jsx)(u7,{model:g,className:"h-3.5 w-3.5 shrink-0"}):(0,n.jsx)("span",{className:"inline-block h-3.5 w-3.5 shrink-0 rounded-full",style:{background:"var(--color-surface-hover)"},"aria-hidden":!0}),(0,n.jsx)("span",{className:(0,h.cn)("max-w-[240px] truncate",!g&&"italic"),style:g?void 0:{color:"var(--color-text-muted)"},children:null!=(l=null==g?void 0:g.displayName)?l:x}),d&&u?(0,n.jsx)(u3.default,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):d?(0,n.jsx)(u8.default,{className:"h-3.5 w-3.5 shrink-0 opacity-70","aria-hidden":!0}):(0,n.jsx)(u6.default,{className:"h-3.5 w-3.5 shrink-0"})]}),(0,n.jsx)(tG.SQ,{align:"start",side:"bottom",sideOffset:8,className:"min-w-[15rem] max-w-[20rem] p-1.5",children:(0,n.jsx)(tG.Hr,{value:null!=(a=null==g?void 0:g.stableId)?a:"",onValueChange:e=>{d||c(e)},children:s.map(e=>(0,n.jsxs)(tG.Ht,{value:e.stableId,disabled:d,children:[(0,n.jsx)(u7,{model:e,className:"h-4 w-4 shrink-0"}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"truncate text-sm font-medium",style:{color:"var(--color-text)"},children:e.displayName}),(0,n.jsxs)("div",{className:"mt-0.5 flex flex-wrap items-center gap-1.5 text-[10px]",style:{color:"var(--color-text-muted)"},children:[(0,n.jsx)("span",{children:e.provider}),e.reasoning&&(0,n.jsx)("span",{children:"Reasoning"}),e.isRecommended&&(0,n.jsx)("span",{className:"rounded-full px-1.5 py-0.5",style:{background:"var(--color-surface-hover)",color:"var(--color-text)"},children:"Recommended"})]})]})]},e.stableId))})})]})}var pe=r(28594);let pt=o.forwardRef((e,t)=>{let{className:r,...o}=e;return(0,n.jsx)(pe.bL,{className:(0,h.cn)("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border border-zinc-300 bg-zinc-200 shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-zinc-900 data-[state=unchecked]:bg-zinc-200 dark:border-zinc-700 dark:data-[state=checked]:bg-zinc-50 dark:data-[state=unchecked]:bg-zinc-700",r),...o,ref:t,children:(0,n.jsx)(pe.zi,{className:(0,h.cn)("pointer-events-none block h-5 w-5 rounded-full bg-white shadow-md ring-1 ring-black/10 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0 dark:bg-zinc-900 dark:ring-white/10")})})});function pr(e){let{notice:t}=e,r="success"===t.tone?"border-emerald-500/30 bg-emerald-500/10 text-emerald-100":"border-amber-500/30 bg-amber-500/10 text-amber-100";return(0,n.jsx)("div",{className:"rounded-xl border px-4 py-3 text-sm ".concat(r),children:t.message})}function pn(e){var t=e.id,r=e.label;switch(t){case"apollo":return"Dench Enrichments";case"exa":return null!=r?r:"Exa";case"elevenlabs":return null!=r?r:"ElevenLabs"}}pt.displayName=pe.bL.displayName;let po={exa:"Search the web with Exa",apollo:"Enrich people and company data",elevenlabs:"Generate speech with ElevenLabs"};function pl(e){let{integration:t,isSaving:r,onToggle:o}=e,l=pn(t),a=po[t.id],s=r?"Saving...":t.locked?"Unavailable until Dench Cloud is ready":a;return(0,n.jsxs)("div",{className:"flex items-center justify-between gap-4 rounded-xl px-1 py-2",style:{background:"transparent"},children:[(0,n.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,n.jsx)("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg",style:{background:"var(--color-surface-hover)",color:"var(--color-text)"},children:function(e){switch(e){case"exa":return(0,n.jsx)("img",{src:"/integrations/exa-logomark.svg",alt:"",width:20,height:20,className:"h-5 w-5 shrink-0 object-contain",draggable:!1});case"apollo":return(0,n.jsx)("img",{src:"/dench-workspace-icon.png",alt:"",width:20,height:20,className:"h-5 w-5 shrink-0 rounded-md object-contain",draggable:!1});case"elevenlabs":return(0,n.jsx)(s9.AHR,{className:"h-5 w-5 shrink-0","aria-hidden":!0})}}(t.id)}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("div",{className:"truncate text-sm font-medium text-foreground",children:l}),(0,n.jsxs)("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-[11px] leading-4 text-muted-foreground",children:[(0,n.jsx)("span",{children:s}),t.lockBadge&&(0,n.jsx)("span",{className:"inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium",style:{background:"var(--color-surface-hover)",color:"var(--color-text)"},children:t.lockBadge})]})]})]}),(0,n.jsx)(pt,{"aria-label":"Toggle ".concat(l),checked:t.enabled,disabled:r||t.locked,onCheckedChange:e=>o(t,e)})]})}function pa(){var e,t,r,l,a,s;let i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},c=void 0!==i.data||void 0!==i.loading||void 0!==i.error||void 0!==i.onToggle,[d,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(!0),[m,x]=(0,o.useState)(null),[f,v]=(0,o.useState)(null),[g,y]=(0,o.useState)(!1),[b,j]=(0,o.useState)(null),k=(0,o.useCallback)(async()=>{h(!0),x(null);try{let e=await fetch("/api/integrations");if(!e.ok)throw Error("Failed to load integrations (".concat(e.status,")"));let t=await e.json();u(t)}catch(e){x(e instanceof Error?e.message:"Failed to load integrations")}finally{h(!1)}},[]);(0,o.useEffect)(()=>{c||k()},[c,k]);let w=c?null!=(e=i.data)?e:null:d,N=c?null!=(t=i.loading)&&t:p,C=c?null!=(r=i.error)?r:null:m,S=c?null!=(l=i.savingId)?l:null:f,M=c?null!=(a=i.repairing)&&a:g,T=c?null!=(s=i.notice)?s:null:b,L=(0,o.useMemo)(()=>{var e;return null!=(e=null==w?void 0:w.integrations)?e:[]},[w]),I=(0,o.useMemo)(()=>{var e;return L.some(e=>("exa"===e.id||"apollo"===e.id)&&e.health.pluginMissing)||(null!=(e=null==w?void 0:w.managedPlugins)?e:[]).some(e=>e.required&&e.health.pluginMissing)},[L,null==w?void 0:w.managedPlugins]),_=(0,o.useCallback)(e=>{c||u(e)},[c]),R=(0,o.useCallback)(async(e,t)=>{if(i.onToggle)return void i.onToggle(e,t);let r=pn(e);v(e.id),j(null);try{let o=await fetch("/api/integrations/".concat(e.id,"/toggle"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:t})}),l=await o.json();if(!o.ok)throw Error("error"in l&&l.error?l.error:"Failed to update ".concat(r));if(_(l),l.refresh.restarted)j({tone:"success",message:"".concat(r," updated and the ").concat(l.refresh.profile," gateway restarted successfully.")});else if(l.changed){var n;j({tone:"warning",message:"".concat(r," updated, but the gateway restart did not complete: ").concat(null!=(n=l.refresh.error)?n:"unknown error",".")})}else j({tone:"success",message:"".concat(r," was already in the requested state.")})}catch(e){j({tone:"warning",message:e instanceof Error?e.message:"Failed to update ".concat(r,".")})}finally{v(null)}},[_,i]),E=(0,o.useCallback)(async()=>{if(i.onRepair)return void i.onRepair();y(!0),j(null);try{let t=await fetch("/api/integrations/repair",{method:"POST"}),r=await t.json();if(!t.ok)throw Error("error"in r&&r.error?r.error:"Failed to repair integrations.");if(_(r),r.changed&&r.refresh.restarted){let e=r.repairedIds.length>0?r.repairedIds.map(e=>(function(e){switch(e){case"apollo":return"Dench Enrichments";case"exa":return"Exa";case"dench-ai-gateway":return"Dench AI Gateway";case"dench-identity":return"Dench Identity";case"posthog":return"PostHog"}})(e)).join(", "):"profiles";j({tone:"success",message:"Repair completed for ".concat(e," and the ").concat(r.refresh.profile," gateway restarted successfully.")})}else if(r.changed){var e;j({tone:"warning",message:"Repair updated the profile, but the gateway restart did not complete: ".concat(null!=(e=r.refresh.error)?e:"unknown error",".")})}else j({tone:"success",message:"No repair changes were needed for this profile."})}catch(e){j({tone:"warning",message:e instanceof Error?e.message:"Failed to repair integrations."})}finally{y(!1)}},[_,i]);return N?(0,n.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,n.jsx)("div",{className:"h-5 w-5 animate-spin rounded-full border-2",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}})}):C?(0,n.jsxs)("div",{className:"rounded-xl border px-4 py-4 text-center",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("p",{className:"text-sm mb-2",style:{color:"var(--color-text-muted)"},children:C}),(0,n.jsx)(sS.$,{type:"button",variant:"outline",size:"sm",onClick:()=>{if(i.onRetry)return void i.onRetry();k()},children:"Retry"})]}):w?(0,n.jsxs)("div",{className:"space-y-4",children:[T&&(0,n.jsx)(pr,{notice:T}),I&&(0,n.jsx)(sS.$,{type:"button",variant:"outline",size:"sm",onClick:()=>void E(),disabled:M,children:M?"Repairing...":"Repair older profiles"}),(0,n.jsx)("div",{className:"space-y-1",children:L.map(e=>(0,n.jsx)(pl,{integration:e,isSaving:S===e.id,onToggle:R},e.id))})]}):null}var ps=r(22618),pi=r(57057),pc=r(40648),pd=r(10622),pu=r(88840),pp=r(13142),ph=r(55436),pm=r(18729);function px(e){let{onAddAndConnect:t,disabled:r=!1}=e,[l,a]=(0,o.useState)(!1),[s,i]=(0,o.useState)(""),[c,d]=(0,o.useState)(""),[u,p]=(0,o.useState)(null),[h,m]=(0,o.useState)(!1),x=(0,o.useRef)(null);(0,o.useEffect)(()=>{l&&setTimeout(()=>{var e;return null==(e=x.current)?void 0:e.focus()},50)},[l]);let f=s.trim(),v=c.trim(),g=f.length>0&&v.length>0&&!h&&!r,y=()=>{a(!1),i(""),d(""),p(null),m(!1)},b=async()=>{if(g){m(!0),p(null);try{let e=await t({key:f,url:v});e.ok?y():p(e.error)}finally{m(!1)}}};return l?(0,n.jsx)("div",{className:"rounded-xl border px-4 py-4",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-lg",style:{background:"var(--color-surface-hover)",color:"var(--color-text)"},children:(0,n.jsx)(ps.default,{className:"h-5 w-5","aria-hidden":!0})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1 space-y-3",children:[(0,n.jsx)("div",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:"New MCP Server"}),(0,n.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{htmlFor:"mcp-inline-key",className:"mb-1 block text-[11px] uppercase tracking-wide",style:{color:"var(--color-text-muted)"},children:"Server name"}),(0,n.jsx)("input",{id:"mcp-inline-key",ref:x,type:"text",value:s,onChange:e=>{i(e.target.value),p(null)},onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),b()):"Escape"===e.key&&(e.preventDefault(),y())},placeholder:"e.g. stripe",disabled:h,className:"w-full rounded-lg px-3 py-2 text-sm 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)"},autoComplete:"off",spellCheck:!1})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{htmlFor:"mcp-inline-url",className:"mb-1 block text-[11px] uppercase tracking-wide",style:{color:"var(--color-text-muted)"},children:"Server URL"}),(0,n.jsx)("input",{id:"mcp-inline-url",type:"url",value:c,onChange:e=>{d(e.target.value),p(null)},onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),b()):"Escape"===e.key&&(e.preventDefault(),y())},placeholder:"https://mcp.example.com",disabled:h,className:"w-full rounded-lg px-3 py-2 text-sm 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)"},autoComplete:"off",spellCheck:!1})]})]}),u&&(0,n.jsx)("p",{className:"rounded-lg px-3 py-2 text-xs",style:{background:"rgba(220, 38, 38, 0.08)",color:"var(--color-error)"},children:u}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,n.jsx)(sS.$,{type:"button",variant:"ghost",size:"sm",className:"rounded-lg",onClick:y,disabled:h,style:{color:"var(--color-text-muted)",background:"transparent"},children:"Cancel"}),(0,n.jsx)(sS.$,{type:"button",size:"sm",className:"rounded-lg",onClick:()=>void b(),disabled:!g,style:{background:g?"var(--color-accent)":"var(--color-surface-hover)",color:g?"var(--color-bg)":"var(--color-text-muted)"},children:(0,n.jsxs)("span",{className:"inline-flex items-center gap-2",children:[h?(0,n.jsx)(u3.default,{className:"h-4 w-4 animate-spin","aria-hidden":!0}):null,(0,n.jsx)("span",{children:h?"Connecting…":"Connect"})]})})]})]})]})}):(0,n.jsxs)("button",{type:"button",onClick:()=>{r||a(!0)},disabled:r,className:"flex w-full items-center gap-3 rounded-xl border px-4 py-4 text-left transition-colors hover:bg-[var(--color-surface-hover)] disabled:opacity-50",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-lg",style:{background:"var(--color-surface-hover)",color:"var(--color-text)"},children:(0,n.jsx)(pm.default,{className:"h-5 w-5","aria-hidden":!0})}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:"New MCP Server"}),(0,n.jsx)("div",{className:"mt-0.5 text-xs leading-5",style:{color:"var(--color-text-muted)"},children:"Add a Custom MCP Server"})]})]})}function pf(e){let{open:t,onOpenChange:r,serverKey:l,serverUrl:a,onSubmit:s,hint:i}=e,c=(0,o.useRef)(null),[d,u]=(0,o.useState)(""),[p,h]=(0,o.useState)(null),[m,x]=(0,o.useState)(!1);(0,o.useEffect)(()=>{t&&(u(""),h(null),x(!1),setTimeout(()=>{var e;return null==(e=c.current)?void 0:e.focus()},100))},[t]);let f=async()=>{if(!d.trim())return void h("Please enter an access token.");x(!0),h(null);try{let e=await s({authToken:d.trim()});if(e)return void h(e);r(!1)}finally{x(!1)}};return(0,n.jsx)(cT.lG,{open:t,onOpenChange:r,children:(0,n.jsxs)(cT.Cf,{className:"sm:max-w-lg",children:[(0,n.jsxs)(cT.c7,{children:[(0,n.jsxs)(cT.L3,{children:["Connect to ",l]}),(0,n.jsxs)(cT.rr,{children:["Paste an access token for this MCP server. It will be sent as an",(0,n.jsx)("code",{className:"mx-1",children:"Authorization: Bearer ..."}),"header on every request."]})]}),(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsxs)("div",{className:"rounded-xl border px-3 py-2 text-xs leading-5",style:{borderColor:"var(--color-border)",background:"var(--color-surface)",color:"var(--color-text-muted)"},children:[(0,n.jsx)("div",{className:"text-[11px] uppercase tracking-wide",children:"Endpoint"}),(0,n.jsx)("div",{className:"mt-1 truncate",style:{color:"var(--color-text)"},title:a,children:a})]}),i?(0,n.jsxs)("p",{className:"rounded-lg px-3 py-2 text-xs leading-5",style:{background:"rgba(234, 179, 8, 0.08)",color:"var(--color-text-muted)"},children:["Server says: ",i]}):null,(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"mb-1.5 block text-sm font-medium",style:{color:"var(--color-text-secondary)"},children:"Access token"}),(0,n.jsx)("input",{ref:c,type:"password",value:d,onChange:e=>{u(e.target.value),h(null)},onKeyDown:e=>{"Enter"!==e.key||m||f()},placeholder:"sk-...",className:"w-full rounded-lg px-3 py-2 text-sm 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:"mt-1 text-xs",style:{color:"var(--color-text-muted)"},children:["The ",(0,n.jsx)("code",{children:"Bearer"})," prefix is added automatically."]})]}),p&&(0,n.jsx)("p",{className:"rounded-lg px-3 py-2 text-sm",style:{background:"rgba(220, 38, 38, 0.08)",color:"var(--color-error)"},children:p})]}),(0,n.jsxs)(cT.Es,{children:[(0,n.jsx)(sS.$,{type:"button",variant:"ghost",onClick:()=>r(!1),disabled:m,className:"rounded-lg px-4",style:{color:"var(--color-text-muted)",background:"transparent"},children:"Cancel"}),(0,n.jsx)(sS.$,{type:"button",onClick:()=>void f(),disabled:m||!d.trim(),className:"rounded-lg px-5",style:{background:"var(--color-accent)",color:"var(--color-bg)"},children:(0,n.jsxs)("span",{className:"inline-flex items-center gap-2",children:[m?(0,n.jsx)(u3.default,{className:"h-4 w-4 animate-spin","aria-hidden":!0}):null,(0,n.jsx)("span",{children:m?"Connecting...":"Connect"})]})})]})]})})}function pv(e){let{notice:t}=e,r="success"===t.tone?"border-emerald-500/30 bg-emerald-500/10 text-emerald-300":"border-red-500/30 bg-red-500/10 text-red-300";return(0,n.jsx)("div",{className:"rounded-xl border px-4 py-3 text-sm ".concat(r),children:t.message})}async function pg(e,t){try{let r=await e.json();return"string"==typeof r.error&&r.error.trim().length>0?r.error:t}catch(e){return t}}function py(e){return[...e].toSorted((e,t)=>e.key.localeCompare(t.key))}function pb(e,t){return py([...e.filter(e=>e.key!==t.key),t])}async function pj(e,t){return await new Promise(r=>{let n=!1,o=()=>{n||(n=!0,window.removeEventListener("message",l),clearInterval(a),clearTimeout(s),r())},l=r=>{if(r.source!==t)return;let n=r.data;if(n&&"denchclaw.mcp.connect"===n.source&&"string"==typeof n.serverKey&&n.serverKey===e){try{t.close()}catch(e){}o()}};window.addEventListener("message",l);let a=window.setInterval(()=>{t.closed&&o()},500),s=window.setTimeout(()=>{try{t.close()}catch(e){}o()},3e5)})}function pk(){let[e,t]=(0,o.useState)([]),[r,l]=(0,o.useState)(!0),[a,s]=(0,o.useState)(null),[i,c]=(0,o.useState)(null),[d,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),[m,x]=(0,o.useState)(null),f=(0,o.useRef)(new Set),v=(0,o.useCallback)(async()=>{l(!0),s(null);try{let e=await fetch("/api/settings/mcp");if(!e.ok)throw Error(await pg(e,"Failed to load MCP servers (".concat(e.status,").")));let r=await e.json();t(py(Array.isArray(r.servers)?r.servers:[]))}catch(e){s(e instanceof Error?e.message:"Failed to load MCP servers.")}finally{l(!1)}},[]);(0,o.useEffect)(()=>{v()},[v]);let g=(0,o.useCallback)(async e=>{x(e.key),c(null);try{let r=await fetch("/api/settings/mcp/probe",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:e.key})});if(!r.ok)throw Error(await pg(r,"Probe failed."));let n=await r.json();n.server&&t(e=>pb(e,n.server))}catch(e){c({tone:"error",message:e instanceof Error?e.message:"Probe failed."})}finally{x(null)}},[]),y=(0,o.useCallback)((e,t)=>{u({serverKey:e.key,serverUrl:e.url,hint:t})},[]),b=(0,o.useCallback)(async(e,r)=>{try{let n=await fetch("/api/settings/mcp/probe",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:e})});if(!n.ok)return;let o=await n.json();o.server&&(t(e=>pb(e,o.server)),(null==r?void 0:r.showSuccessNotice)!==!1&&"connected"===o.server.state&&c({tone:"success",message:"Connected '".concat(e,"'.")}))}catch(e){}},[]);(0,o.useEffect)(()=>{let t=new Set(e.map(e=>e.key));for(let e of f.current)t.has(e)||f.current.delete(e);if(!r&&0!==e.length)for(let t of e)f.current.has(t.key)||(f.current.add(t.key),b(t.key,{showSuccessNotice:!1}))},[r,b,e]);let j=(0,o.useCallback)(async e=>{x(e.key),c(null);try{let n=await fetch("/api/settings/mcp/connect/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:e.key})});if(!n.ok){let t=await pg(n,"Failed to start Connect.");y(e,t);return}let o=await n.json();if(o.alreadyConnected&&o.server){t(e=>pb(e,o.server)),c({tone:"success",message:"'".concat(e.key,"' is already connected.")});return}if(!1===o.supportsOAuth){var r;y(e,null!=(r=o.reason)?r:e.lastDetail);return}if(!o.authorizationUrl)return void y(e,"OAuth start did not return an authorization URL.");let l=window.open(o.authorizationUrl,"mcp-connect-".concat(e.key),"popup=yes,width=520,height=720,noopener=no");if(!l)return void y(e,"The browser blocked the OAuth popup. Allow popups and try again, or paste a token instead.");await pj(e.key,l),await b(e.key)}catch(t){y(e,t instanceof Error?t.message:"Connect failed.")}finally{x(null)}},[y,b]),k=(0,o.useCallback)(async e=>{c(null);try{let r=await fetch("/api/settings/mcp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!r.ok)return{ok:!1,error:await pg(r,"Failed to add MCP server.")};let n=(await r.json()).server;if(!n)return{ok:!1,error:"Server was added but the response was malformed."};return f.current.delete(n.key),t(e=>pb(e,n)),j(n),{ok:!0}}catch(e){return{ok:!1,error:e instanceof Error?e.message:"Failed to add MCP server."}}},[j]),w=(0,o.useCallback)(async e=>{if(!d)return"No server selected.";try{var r,n,o;let l=await fetch("/api/settings/mcp/connect/token",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:d.serverKey,authToken:e.authToken})});if(!l.ok)return await pg(l,"Failed to connect.");let a=await l.json();a.server&&t(e=>pb(e,a.server));let s=null==(r=a.probe)?void 0:r.status;if("connected"===s)return c({tone:"success",message:"Connected to '".concat(d.serverKey,"'.")}),null;return null!=(o=null==(n=a.probe)?void 0:n.detail)?o:"The token was saved but the server still rejected the connection."}catch(e){return e instanceof Error?e.message:"Failed to connect."}},[d]),N=(0,o.useCallback)(async e=>{if(window.confirm("Remove MCP server '".concat(e.key,"'?"))){h(e.key),c(null);try{let r=await fetch("/api/settings/mcp",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:e.key})});if(!r.ok)throw Error(await pg(r,"Failed to remove MCP server."));t(t=>t.filter(t=>t.key!==e.key)),c({tone:"success",message:"Removed MCP server '".concat(e.key,"'.")})}catch(e){c({tone:"error",message:e instanceof Error?e.message:"Failed to remove MCP server."})}finally{h(null)}}},[]);return(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsx)("div",{className:"flex items-center justify-between gap-3",children:(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:"MCP Servers"}),(0,n.jsx)("p",{className:"mt-1 text-xs leading-5",style:{color:"var(--color-text-muted)"},children:"Connect remote MCP servers to expose additional tools in DenchClaw."})]})}),i?(0,n.jsx)(pv,{notice:i}):null,r?(0,n.jsx)("div",{className:"flex items-center justify-center py-10",children:(0,n.jsx)("div",{className:"h-6 w-6 animate-spin rounded-full border-2",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}})}):a?(0,n.jsxs)("div",{className:"rounded-xl border px-4 py-6 text-center",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("p",{className:"mb-3 text-sm",style:{color:"var(--color-text-muted)"},children:a}),(0,n.jsx)(sS.$,{type:"button",variant:"outline",onClick:()=>void v(),children:"Retry"})]}):(0,n.jsxs)("div",{className:"space-y-3",children:[e.map(e=>(0,n.jsx)(pw,{server:e,busy:m===e.key,deleting:p===e.key,onConnect:()=>j(e),onRetry:()=>void g(e),onDelete:()=>void N(e)},e.key)),(0,n.jsx)(px,{onAddAndConnect:k})]}),d?(0,n.jsx)(pf,{open:!!d,onOpenChange:e=>{e||u(null)},serverKey:d.serverKey,serverUrl:d.serverUrl,hint:d.hint,onSubmit:w}):null]})}function pw(e){let{server:t,busy:r,deleting:o,onConnect:l,onRetry:a,onDelete:s}=e;return(0,n.jsx)("div",{className:"rounded-xl border px-4 py-4",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:(0,n.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,n.jsxs)("div",{className:"flex min-w-0 gap-3",children:[(0,n.jsx)("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-lg",style:{background:"var(--color-surface-hover)",color:"var(--color-text)"},children:(0,n.jsx)(ps.default,{className:"h-5 w-5","aria-hidden":!0})}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,n.jsx)("div",{className:"truncate text-sm font-medium",style:{color:"var(--color-text)"},children:t.key}),(0,n.jsx)(pN,{server:t}),(0,n.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium",style:{background:"var(--color-surface-hover)",color:"var(--color-text)"},children:[t.hasAuth?(0,n.jsx)(pi.default,{className:"h-3 w-3","aria-hidden":!0}):(0,n.jsx)(pc.default,{className:"h-3 w-3","aria-hidden":!0}),(0,n.jsx)("span",{children:t.hasAuth?"Authenticated":"No auth"})]})]}),(0,n.jsx)("p",{className:"mt-2 text-[11px] uppercase tracking-wide",style:{color:"var(--color-text-muted)"},children:"Remote endpoint"}),(0,n.jsx)("div",{className:"mt-1 truncate text-xs leading-5",style:{color:"var(--color-text-muted)"},title:t.url,children:t.url}),t.lastDetail&&"connected"!==t.state?(0,n.jsx)("div",{className:"mt-2 text-xs leading-5",style:{color:"var(--color-text-muted)"},title:t.lastDetail,children:t.lastDetail}):null]})]}),(0,n.jsxs)("div",{className:"flex shrink-0 items-center gap-2",children:[(0,n.jsx)(pC,{server:t,busy:r,onConnect:l,onRetry:a}),(0,n.jsx)(sS.$,{type:"button",variant:"ghost",size:"icon",className:"rounded-lg",onClick:s,disabled:o,"aria-label":"Remove ".concat(t.key),style:{color:"var(--color-text-muted)"},children:o?(0,n.jsx)(u3.default,{className:"h-4 w-4 animate-spin","aria-hidden":!0}):(0,n.jsx)(pd.default,{className:"h-4 w-4","aria-hidden":!0})})]})]})})}function pN(e){let{server:t}=e,r="inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium";if("connected"===t.state){var o;let e=null!=(o=t.toolCount)?o:0;return(0,n.jsxs)("span",{className:r,style:{background:"rgba(16, 185, 129, 0.12)",color:"rgb(110, 231, 183)"},children:[(0,n.jsx)(pu.default,{className:"h-3 w-3","aria-hidden":!0}),(0,n.jsxs)("span",{children:[e," tool",1===e?"":"s"," enabled"]})]})}return"needs_auth"===t.state?(0,n.jsxs)("span",{className:r,style:{background:"rgba(234, 179, 8, 0.12)",color:"rgb(252, 211, 77)"},children:[(0,n.jsx)(pc.default,{className:"h-3 w-3","aria-hidden":!0}),(0,n.jsx)("span",{children:"Needs authentication"})]}):"error"===t.state?(0,n.jsxs)("span",{className:r,style:{background:"rgba(239, 68, 68, 0.12)",color:"rgb(252, 165, 165)"},children:[(0,n.jsx)(pp.default,{className:"h-3 w-3","aria-hidden":!0}),(0,n.jsx)("span",{children:"Error"})]}):(0,n.jsx)("span",{className:r,style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:t.transport})}function pC(e){let{server:t,busy:r,onConnect:o,onRetry:l}=e;return"connected"===t.state?(0,n.jsx)(sS.$,{type:"button",variant:"ghost",size:"sm",className:"rounded-lg",onClick:l,disabled:r,"aria-label":"Re-check ".concat(t.key),style:{color:"var(--color-text-muted)"},children:r?(0,n.jsx)(u3.default,{className:"h-4 w-4 animate-spin","aria-hidden":!0}):(0,n.jsx)(ph.default,{className:"h-4 w-4","aria-hidden":!0})}):"error"===t.state?(0,n.jsxs)(sS.$,{type:"button",variant:"outline",size:"sm",className:"rounded-lg",onClick:l,disabled:r,children:[r?(0,n.jsx)(u3.default,{className:"mr-1 h-4 w-4 animate-spin","aria-hidden":!0}):null,"Retry"]}):(0,n.jsxs)(sS.$,{type:"button",variant:"outline",size:"sm",className:"rounded-lg",onClick:o,disabled:r,children:[r?(0,n.jsx)(u3.default,{className:"mr-1 h-4 w-4 animate-spin","aria-hidden":!0}):null,"Connect"]})}let pS=[{id:"dench",name:"Dench",src:"/dench-workspace-icon.png",rounded:!0},{id:"aviato",name:"Aviato",src:"/integrations/aviato.ico",rounded:!0},{id:"apollo",name:"Apollo",src:"/integrations/apollo.ico",rounded:!0},{id:"pdl",name:"People Data Labs",src:"/integrations/people-data-labs.ico",rounded:!0},{id:"datagma",name:"Datagma",src:"/integrations/datagma.png",rounded:!0},{id:"rocketreach",name:"RocketReach",src:"/integrations/rocketreach.ico",rounded:!0},{id:"hunter",name:"Hunter",src:"/integrations/hunter.png",rounded:!0},{id:"bettercontacts",name:"Better Contacts",src:"/integrations/bettercontacts.png",rounded:!0},{id:"dropcontacts",name:"Dropcontact",src:"/integrations/dropcontacts.ico",rounded:!0},{id:"explorium",name:"Explorium",src:"/integrations/explorium.png",rounded:!0}],pM="__dench_default_voice__",pT="w-full max-w-full rounded-xl border border-[color-mix(in_srgb,var(--color-border)_78%,transparent)] bg-[var(--color-surface)] px-3 py-2.5 hover:opacity-100";function pL(e){var t,r,n,o;let l=new Map;for(let r of null!=(t=null==e?void 0:e.integrations)?t:[])l.set(r.id,r.enabled);return{exa:null!=(r=l.get("exa"))&&r,apollo:null!=(n=l.get("apollo"))&&n,elevenlabs:null!=(o=l.get("elevenlabs"))&&o}}function pI(e){let{notice:t}=e,r="success"===t.tone?"border-emerald-500/30 bg-emerald-500/10 text-emerald-300":"warning"===t.tone?"border-amber-500/30 bg-amber-500/10 text-amber-300":"border-red-500/30 bg-red-500/10 text-red-300";return(0,n.jsx)("div",{className:"rounded-xl border px-4 py-3 text-sm ".concat(r),children:t.message})}function p_(){return(0,n.jsxs)("div",{className:"rounded-xl border px-4 py-4",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsxs)("div",{className:"space-y-1",children:[(0,n.jsx)("div",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:"Dench Enrichment"}),(0,n.jsx)("div",{className:"max-w-[42rem] text-xs leading-5",style:{color:"var(--color-text-muted)"},children:"Waterfall providers"})]}),(0,n.jsx)("div",{className:"mt-4 flex flex-wrap items-center gap-3",children:pS.map(e=>(0,n.jsx)("div",{className:"flex h-8 w-8 items-center justify-center",title:e.name,"aria-label":e.name,children:(0,n.jsx)("img",{src:e.src,alt:"",width:24,height:24,className:e.rounded?"h-6 w-6 rounded-[6px] object-contain":"h-6 w-6 object-contain",draggable:!1})},e.id))})]})}function pR(){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:"M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z"})})}function pE(){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:"m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4"}),(0,n.jsx)("path",{d:"m21 2-9.6 9.6"}),(0,n.jsx)("circle",{cx:"7.5",cy:"15.5",r:"5.5"})]})}function pD(){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:"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 pA(e){let{onSave:t,saving:r,notice:l,validationError:a}=e,[s,i]=(0,o.useState)("");return(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 rounded-xl border px-4 py-3",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg shrink-0",style:{background:"var(--color-surface-hover)",color:"var(--color-text)"},children:(0,n.jsx)(pR,{})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:"Dench Cloud"}),(0,n.jsx)("div",{className:"text-[11px] mt-0.5",style:{color:"var(--color-text-muted)"},children:a?"Your API key is invalid. Enter a new one below.":"Connect to Dench Cloud for AI model access."})]}),(0,n.jsxs)("a",{href:"https://dench.com/api",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded-lg transition-colors hover:bg-stone-200 dark:hover:bg-stone-700",style:{color:"var(--color-accent)"},children:["Get API Key ",(0,n.jsx)(pD,{})]})]}),a&&(0,n.jsx)("div",{className:"rounded-xl border border-red-500/30 bg-red-500/10 px-4 py-3 text-sm text-red-300",children:a}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("div",{className:"relative flex-1",children:[(0,n.jsx)("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none",style:{color:"var(--color-text-muted)"},children:(0,n.jsx)(pE,{})}),(0,n.jsx)("input",{type:"password",value:s,onChange:e=>i(e.target.value),onKeyDown:e=>{"Enter"===e.key&&s.trim()&&!r&&t(s.trim())},placeholder:"Paste your Dench API key...",className:"w-full pl-9 pr-3 py-2.5 rounded-xl text-sm outline-none transition-colors",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)",color:"var(--color-text)"},disabled:r})]}),(0,n.jsx)(sS.$,{type:"button",onClick:()=>{s.trim()&&t(s.trim())},disabled:!s.trim()||r,children:r?"Validating...":"Save"})]}),l&&(0,n.jsx)(pI,{notice:l})]})}function pF(e){var t,r;let{models:o,selectedModel:l,selectedVoiceId:a,elevenLabsEnabled:s,isDenchPrimary:i,recommendedModelId:c,onSelect:d,onSelectVoice:u,selecting:p,savingVoice:h,voiceLoading:m,voices:x}=e,f=o.map(e=>({stableId:e.stableId,...e.id.trim()&&e.id!==e.stableId?{catalogId:e.id}:{},displayName:e.displayName,provider:e.provider,reasoning:e.reasoning,isRecommended:e.id===c})),v=null!=(t=x.find(e=>e.voiceId===a))?t:null;return(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 rounded-xl border px-4 py-3",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)("img",{src:"/dench-workspace-icon.png",alt:"",width:36,height:36,className:"h-9 w-9 shrink-0 rounded-lg object-contain",draggable:!1}),(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)("span",{className:"text-sm font-medium",style:{color:"var(--color-text)"},children:"Dench Cloud"}),(0,n.jsx)("span",{className:"inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium",style:{background:i?"rgba(16,185,129,0.15)":"var(--color-surface-hover)",color:i?"rgb(16,185,129)":"var(--color-text-muted)"},children:i?"Active":"Available"})]}),(0,n.jsx)("div",{className:"text-[11px] mt-0.5",style:{color:"var(--color-text-muted)"},children:i?"Connected and active as your primary provider.":"Connected. Select a model to use Dench Cloud as your primary provider."})]}),(0,n.jsxs)("a",{href:"https://dench.com/usage",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-xs font-medium shrink-0 transition-opacity hover:opacity-80",style:{color:"var(--color-accent)"},children:["Usage ",(0,n.jsx)(pD,{})]})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-xs font-medium mb-2",style:{color:"var(--color-text-muted)"},children:"Primary Model"}),(0,n.jsx)("div",{className:"max-w-[420px]",children:(0,n.jsx)(u9,{models:f,selectedModel:i?l:null,onSelect:d,disabled:p,loading:p,fallbackToFirst:i,placeholder:"Choose a model...",ariaLabel:"Select primary model",triggerClassName:pT})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-xs font-medium mb-2",style:{color:"var(--color-text-muted)"},children:"ElevenLabs Voice"}),(0,n.jsx)("div",{className:"max-w-[420px]",children:(0,n.jsxs)(tG.rI,{children:[(0,n.jsxs)(tG.ty,{className:"inline-flex items-center gap-1.5 text-sm font-medium transition-opacity disabled:cursor-default disabled:opacity-60 cursor-pointer outline-none ring-0 ".concat(pT),style:{color:"var(--color-text-secondary)",opacity:.9},"aria-label":"Select ElevenLabs voice",title:null!=(r=null==v?void 0:v.name)?r:void 0,disabled:m||h||0===x.length,children:[(0,n.jsx)("span",{className:"max-w-[240px] truncate",style:m||!v&&0===x.length?{color:"var(--color-text-muted)"}:void 0,children:m?"Loading voices...":0===x.length?"No voices available":v?"".concat(v.name).concat(v.category?" \xb7 ".concat(v.category):""):"Default voice (first available)"}),m||h?(0,n.jsx)(u3.default,{className:"h-3.5 w-3.5 shrink-0 animate-spin","aria-hidden":!0}):(0,n.jsx)(u6.default,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0})]}),(0,n.jsx)(tG.SQ,{align:"start",side:"bottom",sideOffset:8,className:"min-w-[15rem] max-w-[20rem] p-1.5",children:(0,n.jsxs)(tG.Hr,{value:null!=a?a:pM,onValueChange:e=>{u(e===pM?null:e)},children:[(0,n.jsx)(tG.Ht,{value:pM,children:"Default voice (first available)"}),x.map(e=>(0,n.jsx)(tG.Ht,{value:e.voiceId,children:(0,n.jsxs)("span",{className:"truncate",children:[e.name,e.category?" \xb7 ".concat(e.category):""]})},e.voiceId))]})})]})}),(0,n.jsxs)("div",{className:"mt-2 space-y-1",children:[(0,n.jsx)("p",{className:"text-[11px]",style:{color:"var(--color-text-muted)"},children:s?"Used for message playback and server-side voice input.":"Choose a voice now. Playback and server-side voice input stay off until ElevenLabs is enabled in Integrations."}),(null==v?void 0:v.description)&&(0,n.jsx)("p",{className:"text-[11px]",style:{color:"var(--color-text-muted)"},children:v.description})]})]})]})}function pP(){let[e,t]=(0,o.useState)(null),[r,l]=(0,o.useState)(null),[a,s]=(0,o.useState)([]),[i,c]=(0,o.useState)(!0),[d,u]=(0,o.useState)(!1),[p,h]=(0,o.useState)(!1),[m,x]=(0,o.useState)(null),[f,v]=(0,o.useState)(null),[g,y]=(0,o.useState)(!1),[b,j]=(0,o.useState)(!1),[k,w]=(0,o.useState)(!1),[N,C]=(0,o.useState)(null),[S,M]=(0,o.useState)(null),[T,L]=(0,o.useState)(null),[I,_]=(0,o.useState)({exa:!1,apollo:!1,elevenlabs:!1}),[R,E]=(0,o.useState)(0),D=(0,o.useCallback)(async()=>{c(!0),x(null);try{let e=await fetch("/api/settings/cloud");if(!e.ok)throw Error("Failed to load cloud settings (".concat(e.status,")"));let r=await e.json();t(r)}catch(e){x(e instanceof Error?e.message:"Failed to load cloud settings.")}finally{c(!1)}},[]);(0,o.useEffect)(()=>{D()},[D]);let A=(0,o.useCallback)(async()=>{u(!0),v(null);try{let e=await fetch("/api/integrations");if(!e.ok)throw Error("Failed to load integrations (".concat(e.status,")"));let t=await e.json();l(t)}catch(e){v(e instanceof Error?e.message:"Failed to load integrations.")}finally{u(!1)}},[]);(0,o.useEffect)(()=>{if((null==e?void 0:e.status)!=="valid"){l(null),v(null),u(!1);return}(async()=>{await A(),E(e=>e+1)})()},[null==e?void 0:e.status,A]),(0,o.useEffect)(()=>{if((null==e?void 0:e.status)!=="valid")return void s([]);let t=!1;return h(!0),(async()=>{try{let e=await fetch("/api/voice/voices");if(!e.ok){t||s([]);return}let r=await e.json();t||s(Array.isArray(r.voices)?r.voices:[])}catch(e){t||s([])}finally{t||h(!1)}})(),()=>{t=!0}},[null==e?void 0:e.status,null==e?void 0:e.gatewayUrl]);let F=(0,o.useRef)(r);F.current=r,(0,o.useEffect)(()=>{(null==e?void 0:e.status)==="valid"&&F.current&&(M(e.isDenchPrimary?e.selectedDenchModel:null),L(e.selectedVoiceId),_(pL(F.current)))},[null==e?void 0:e.status,null==e?void 0:e.isDenchPrimary,null==e?void 0:e.selectedDenchModel,null==e?void 0:e.selectedVoiceId,R]);let P=(0,o.useCallback)(async e=>{y(!0),C(null);try{var r,n;let o=await fetch("/api/settings/cloud",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"save_key",apiKey:e})}),l=await o.json();if(!o.ok)return void C({tone:"error",message:null!=(r=l.error)?r:"Failed to save API key."});t(l.state);let a=l.refresh;a.restarted?C({tone:"success",message:"API key saved and the ".concat(a.profile," gateway restarted successfully.")}):a.attempted?C({tone:"warning",message:"API key saved, but the gateway restart did not complete: ".concat(null!=(n=a.error)?n:"unknown error",".")}):C({tone:"success",message:"API key saved successfully."})}catch(e){C({tone:"error",message:e instanceof Error?e.message:"Failed to save API key."})}finally{y(!1)}},[]),B=(0,o.useCallback)(e=>{C(null),M(e)},[]),W=(0,o.useCallback)(e=>{C(null),L(e)},[]),O=(0,o.useCallback)((e,t)=>{C(null),_(r=>({...r,[e.id]:t}))},[]),z=(0,o.useCallback)(()=>{(null==e?void 0:e.status)==="valid"&&r&&(C(null),M(e.isDenchPrimary?e.selectedDenchModel:null),L(e.selectedVoiceId),_(pL(r)))},[e,r]),U=(null==e?void 0:e.status)==="valid"&&e.isDenchPrimary?e.selectedDenchModel:null,H=(null==e?void 0:e.status)==="valid"?e.selectedVoiceId:null,V=(0,o.useMemo)(()=>pL(r),[r]),K=(null==e?void 0:e.status)==="valid"&&(S!==U||T!==H||I.exa!==V.exa||I.apollo!==V.apollo||I.elevenlabs!==V.elevenlabs),J=!!S,q=(0,o.useMemo)(()=>r?{...r,denchCloud:{...r.denchCloud,isPrimaryProvider:J,primaryModel:r.denchCloud.primaryModel},integrations:r.integrations.map(e=>"dench_not_primary"!==e.lockReason?{...e,enabled:I[e.id]}:J?{...e,enabled:I[e.id],locked:!1,lockReason:null,lockBadge:null,available:e.auth.configured&&!!e.gatewayBaseUrl}:{...e,enabled:I[e.id],locked:!0,lockReason:"dench_not_primary",lockBadge:"Use Dench Cloud",available:!1})}:null,[I,J,r]),G=(0,o.useCallback)(async()=>{j(!0),C(null);try{var e,r;let n=await fetch("/api/settings/cloud",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"save_active_settings",stableId:S,voiceId:T,integrations:I})}),o=await n.json();if(!n.ok)return void C({tone:"error",message:null!=(e=o.error)?e:"Failed to save cloud settings."});t(o.state),o.integrationsState?(l(o.integrationsState),E(e=>e+1)):(async()=>{await A(),E(e=>e+1)})();let a=o.refresh;o.changed?a.restarted?C({tone:"success",message:"Cloud settings saved and the ".concat(a.profile," gateway restarted successfully.")}):a.attempted?C({tone:"warning",message:"Cloud settings saved, but the gateway restart did not complete: ".concat(null!=(r=a.error)?r:"unknown error",".")}):C({tone:"success",message:"Cloud settings saved successfully."}):C({tone:"success",message:"No changes to save."})}catch(e){C({tone:"error",message:e instanceof Error?e.message:"Failed to save cloud settings."})}finally{j(!1)}},[I,S,T,A]),$=(0,o.useCallback)(async()=>{w(!0),C(null);try{var e,t;let r=await fetch("/api/integrations/repair",{method:"POST"}),n=await r.json();if(!r.ok)throw Error(null!=(e=n.error)?e:"Failed to repair integrations.");if(l(n),E(e=>e+1),n.changed&&n.refresh.restarted){let e=n.repairedIds.length>0?n.repairedIds.join(", "):"profiles";C({tone:"success",message:"Repair completed for ".concat(e," and the ").concat(n.refresh.profile," gateway restarted successfully.")})}else n.changed?C({tone:"warning",message:"Repair updated the profile, but the gateway restart did not complete: ".concat(null!=(t=n.refresh.error)?t:"unknown error",".")}):C({tone:"success",message:"No repair changes were needed for this profile."})}catch(e){C({tone:"error",message:e instanceof Error?e.message:"Failed to repair integrations."})}finally{w(!1)}},[]);return i?(0,n.jsx)("div",{className:"flex items-center justify-center py-16",children:(0,n.jsx)("div",{className:"h-6 w-6 animate-spin rounded-full border-2",style:{borderColor:"var(--color-border)",borderTopColor:"var(--color-accent)"}})}):m?(0,n.jsxs)("div",{className:"rounded-xl border px-4 py-6 text-center",style:{borderColor:"var(--color-border)"},children:[(0,n.jsx)("p",{className:"text-sm mb-3",style:{color:"var(--color-text-muted)"},children:m}),(0,n.jsx)(sS.$,{type:"button",variant:"outline",onClick:()=>void D(),children:"Retry"})]}):e?"no_key"===e.status||"invalid_key"===e.status?(0,n.jsxs)("div",{className:"space-y-8",children:[(0,n.jsx)(pA,{onSave:P,saving:g,notice:N,validationError:"invalid_key"===e.status?e.validationError:void 0}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium mb-3",style:{color:"var(--color-text)"},children:"Integrations"}),(0,n.jsx)(pa,{})]})]}):(0,n.jsxs)("div",{className:"space-y-8",children:[(0,n.jsx)(pF,{models:e.models,selectedModel:S,selectedVoiceId:T,elevenLabsEnabled:I.elevenlabs,isDenchPrimary:J,recommendedModelId:e.recommendedModelId,onSelect:B,onSelectVoice:W,selecting:b,savingVoice:b,voiceLoading:p,voices:a}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium mb-3",style:{color:"var(--color-text)"},children:"Integrations"}),(0,n.jsx)(pa,{data:q,loading:d,error:f,savingId:null,repairing:k,onToggle:O,onRetry:()=>void A(),onRepair:()=>void $()})]}),(0,n.jsx)(p_,{}),(0,n.jsx)(pk,{}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 pt-2",children:[(0,n.jsx)(sS.$,{type:"button",variant:"ghost",className:"shrink-0 rounded-lg px-4 text-sm font-medium",style:{color:"var(--color-text-muted)",background:"transparent"},onClick:z,disabled:!K||b,children:"Reset"}),(0,n.jsx)(sS.$,{type:"button",className:"min-w-28 shrink-0 rounded-lg px-5 text-sm font-semibold",style:{background:"var(--color-accent)",color:"var(--color-bg)"},onClick:()=>void G(),disabled:!K||b||d||!!f,children:(0,n.jsxs)("span",{className:"inline-flex items-center justify-center gap-2 leading-none",children:[b?(0,n.jsx)(u3.default,{className:"h-4 w-4 animate-spin","aria-hidden":!0}):null,(0,n.jsx)("span",{children:b?"Saving...":"Save"})]})})]})]}):null}function pB(e){var t;return{id:e.id,role:e.role,parts:null!=(t=e.parts)?t:[{type:"text",text:e.content}]}}function pW(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)(cZ,{message:pB(e)},e.id))]})}function pO(e){let{jobId:t,runAtMs:r,summary:l,fallback:a}=e,[s,i]=(0,o.useState)([]),[c,d]=(0,o.useState)(!0),[u,p]=(0,o.useState)(!1),h=(0,o.useCallback)(async()=>{if(!r||!l){d(!1),p(!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 p(!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 p(!0)}catch(e){p(!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)(cZ,{message:pB(e)},e.id))]})}function pz(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 pU(e){var t,r;let{job:l,onBack:a,onSendCommand:s,runFilter:i="all",onRunFilterChange:c,expandedRunTs:d,onExpandedRunChange:u}=e,[p,h]=(0,o.useState)([]),[m,x]=(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{x(!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)(pG,{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)(pJ,{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)(pH,{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)(p$,{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)(p$,{label:"Target",value:l.sessionTarget}),(0,n.jsx)(p$,{label:"Wake mode",value:l.wakeMode}),(0,n.jsx)(p$,{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)(p$,{label:"Agent",value:l.agentId}),l.delivery&&(0,n.jsx)(p$,{label:"Delivery",value:l.delivery.mode}),(0,n.jsx)(p$,{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))})]}),m?(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===p.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:p.toReversed().filter(e=>"all"===i||e.status===i).map(e=>(0,n.jsx)(pV,{run:e,isExpanded:f===e.ts,onToggle:()=>v(f===e.ts?null:e.ts)},"".concat(e.ts,"-").concat(e.jobId)))})]})]})}function pH(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 pV(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:pz(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: ",pz(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)(pW,{sessionId:r.sessionId}):(0,n.jsx)(pK,{run:r})]})]})}function pK(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)(iO.oz,{remarkPlugins:[iz.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)(pO,{jobId:t.jobId,runAtMs:t.runAtMs,summary:t.summary,fallback:r})}function pJ(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)(pq,{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)(pq,{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)(pq,{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)(pq,{onClick:()=>null==r?void 0:r('Delete cron job "'.concat(t.name,'" (').concat(t.id,")")),danger:!0,children:"Delete"})]})}function pq(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 pG(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 p$(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 pY(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)(dN,{initialSessionId:a,sessionTitle:"".concat(o.name," - Run ").concat(new Date(l.ts).toLocaleString())})})]})}function pZ(){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 pQ(){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 pX(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 p0(){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 p1(){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 p2(){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 p4={text:"Aa",number:"#",date:"\uD83D\uDCC5",boolean:"☑",enum:"\uD83C\uDFF7",relation:"\uD83D\uDD17",user:"\uD83D\uDC64",richtext:"\xb6",email:"@"};function p5(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-[160px] sm:min-w-[200px] max-w-[calc(100vw-2rem)] max-h-[320px] overflow-y-auto",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",["right"===s?"right":"left"]:0},children:a})]})}function p3(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 p6(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-[80px] sm:min-w-[120px]",style:{background:"var(--color-bg)",border:"1px solid var(--color-border)",color:"var(--color-text)"}})}function p8(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 p7(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 p9(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 he(){return null}function ht(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)(p6,{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((0,M.PV)(r),"..."):"ID..."})}function hr(e){var t,r,o,l,a,s,i;let{rule:c,field:d,fields:u,members:p,onUpdate:h,onRemove:m}=e,x=null!=(t=null==d?void 0:d.type)?t:"text",f=function(e){switch(e){case"text":case"richtext":case"email":default:return oW;case"number":return oO;case"date":return oz;case"enum":return oU;case"boolean":return oH;case"relation":case"user":return oV;case"tags":return oK}}(x),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:oJ(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=p4[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"===x||"richtext"===x||"email"===x||"tags"===x)&&(0,n.jsx)(p6,{value:String(null!=(r=c.value)?r:""),onChange:e=>h({value:e})}),"number"===x&&(0,n.jsx)(p8,{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"===x&&(0,n.jsx)(p7,{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"===x&&(0,n.jsx)(p9,{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"===x&&(0,n.jsx)(he,{}),("relation"===x||"user"===x)&&(0,n.jsx)(ht,{value:null!=(i=c.value)?i:"",relatedObjectName:null==d?void 0:d.related_object_name,members:"user"===x?p:void 0,multiple:y,onChange:e=>h({value:e})})]}),(0,n.jsx)("button",{type:"button",onClick:m,className:"p-1 rounded transition-colors cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Remove filter",children:(0,n.jsx)(pX,{size:14})})]})}function hn(e){let{fields:t,filters:r,onFiltersChange:l,savedViews:a,activeViewName:s,onSaveView:i,onLoadView:c,onDeleteView:d,onSetActiveView:u,members:p}=e,[h,m]=(0,o.useState)(!1),[x,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:oJ(a)};l({...r,rules:[...r.rules,s]}),m(!1)},[t,r,l]),N=(0,o.useCallback)((e,t)=>{let n=r.rules.map(r=>oq(r)||r.id!==e?r:{...r,...t});l({...r,rules:n})},[r,l]),C=(0,o.useCallback)(e=>{let t=r.rules.filter(t=>!!oq(t)||t.id!==e);l({...r,rules:t})},[r,l]),S=(0,o.useCallback)(()=>{l(o$()),u(void 0)},[l,u]),M=(0,o.useCallback)(()=>{l({...r,conjunction:"and"===r.conjunction?"or":"and"})},[r,l]),T=(0,o.useCallback)(()=>{y.trim()&&(i(y.trim()),b(""),g(!1))},[y,i]),L=(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]),I=r.rules.filter(e=>!oq(e)).length;return(0,n.jsxs)("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[(0,n.jsx)(ho,{ruleCount:I,hasFilters:k,filters:r,fields:t,groupedFields:L,members:p,addRule:w,updateRule:N,removeRule:C,clearAll:S,toggleConjunction:M,fieldPickerOpen:h,setFieldPickerOpen:m}),(0,n.jsxs)(p5,{trigger:(0,n.jsxs)("button",{type:"button",className:"flex items-center gap-1 h-7 px-2 rounded-md text-xs transition-colors cursor-pointer flex-shrink-0",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"},title:s?"Active view: ".concat(s):"Saved views",children:[(0,n.jsx)(p1,{}),(0,n.jsx)("span",{className:"hidden md:inline",children:null!=s?s:"Views"}),(0,n.jsx)(p0,{})]}),open:x,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)(p3,{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 md:opacity-0 md:group-hover:opacity-100 transition-opacity cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Delete view",children:(0,n.jsx)(p2,{})})]},e.name)),(0,n.jsx)("div",{className:"border-t my-1",style:{borderColor:"var(--color-border)"}}),k&&!v&&(0,n.jsxs)(p3,{onClick:()=>g(!0),children:[(0,n.jsx)(p1,{}),"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&&T(),"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:T,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)(p3,{onClick:()=>{S(),f(!1)},children:[(0,n.jsx)(pX,{size:12}),"Clear active view"]})]})]})]})}function ho(e){let{ruleCount:t,hasFilters:r,filters:l,fields:a,groupedFields:s,members:i,addRule:c,updateRule:d,removeRule:u,clearAll:p,toggleConjunction:h,fieldPickerOpen:m,setFieldPickerOpen:x}=e,[f,v]=(0,o.useState)(!1),g=(0,o.useRef)(null);return(0,o.useEffect)(()=>{if(!f)return;let e=e=>{let t=e.target;g.current&&!g.current.contains(t)&&v(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[f]),(0,n.jsxs)("div",{className:"relative",ref:g,children:[(0,n.jsxs)("button",{type:"button",onClick:()=>v(e=>!e),className:"flex items-center gap-1 h-7 px-2 rounded-md text-xs transition-colors cursor-pointer flex-shrink-0",style:{color:r?"var(--color-accent)":"var(--color-text-muted)",border:"1px solid ".concat(r?"var(--color-accent)":"var(--color-border)"),background:r?"var(--color-accent-light, rgba(99,102,241,0.1))":"transparent"},title:r?"".concat(t," active filter").concat(1!==t?"s":""):"Add a filter",children:[(0,n.jsx)(pZ,{}),(0,n.jsx)("span",{className:"hidden md:inline",children:r?"Filter \xb7 ".concat(t):"Filter"})]}),f&&(0,n.jsxs)("div",{className:"absolute right-0 top-full mt-1 z-50 rounded-lg border shadow-lg p-3 min-w-[300px] sm:min-w-[420px] max-w-[calc(100vw-2rem)] flex flex-col gap-2",style:{borderColor:"var(--color-border)",background:"var(--color-surface)",boxShadow:"0 8px 24px rgba(0,0,0,0.12)"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsx)("div",{className:"text-[10px] font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:"Filters"}),l.rules.length>=2&&(0,n.jsxs)("button",{type:"button",onClick:h,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"===l.conjunction?"ALL":"ANY"," rules. Click to toggle."),children:["Match ","and"===l.conjunction?"ALL":"ANY"]})]}),r?(0,n.jsx)("div",{className:"flex flex-col gap-1.5",children:l.rules.map((e,t)=>{if(oq(e))return null;let r=a.find(t=>t.name===e.field);return(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"text-[10px] font-semibold uppercase w-10 text-center flex-shrink-0",style:{color:"var(--color-text-muted)"},children:0===t?"Where":l.conjunction}),(0,n.jsx)(hr,{rule:e,field:r,fields:a,members:i,onUpdate:t=>d(e.id,t),onRemove:()=>u(e.id)})]},e.id)})}):(0,n.jsx)("div",{className:"text-[11px] py-1",style:{color:"var(--color-text-muted)"},children:"No filters applied. Add one below."}),(0,n.jsxs)("div",{className:"flex items-center gap-2 pt-1",children:[(0,n.jsx)(p5,{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)(pQ,{})," Add filter"]}),open:m,onOpenChange:x,children:Object.entries(s).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=p4[r])?t:"?"," ",r]}),o.map(e=>(0,n.jsx)(p3,{onClick:()=>c(e.name),children:e.name},e.name))]},r)})}),r&&(0,n.jsxs)("button",{type:"button",onClick:p,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)(pX,{size:10}),"Clear all"]})]})]})]})}let hl="denchclaw:sync-banner-dismissed";function ha(e){try{window.sessionStorage.setItem(hl,JSON.stringify(Array.from(e)))}catch(e){}}function hs(e,t){let r="gmail"===e?"Gmail":"Calendar";if(t.needsReconnect&&t.lastError)return{source:e,errorKey:"".concat(e,":reconnect"),title:"".concat(r," sync paused"),description:"Reconnect from the Integrations panel — your OAuth connection was revoked or expired upstream.",needsReconnect:!0};if(t.lastError){let n=t.lastError.length>220?"".concat(t.lastError.slice(0,217),"…"):t.lastError;return{source:e,errorKey:"".concat(e,":error:").concat(t.lastError.slice(0,60)),title:"".concat(r," sync failing"),description:n,needsReconnect:!1}}if(t.stale){var n;return{source:e,errorKey:"".concat(e,":stale:").concat(null!=(n=t.lastPolledAt)?n:"never"),title:"".concat(r," sync hasn't run recently"),description:"The gateway daemon may be down. Try `denchclaw start` to relaunch the cron.",needsReconnect:!1}}return null}function hi(){let{pollIntervalMs:e=6e4}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},[t,r]=(0,o.useState)(null),[l,a]=(0,o.useState)(()=>(function(){try{let e=window.sessionStorage.getItem(hl);if(!e)return new Set;let t=JSON.parse(e);if(!Array.isArray(t))return new Set;return new Set(t.filter(e=>"string"==typeof e))}catch(e){return new Set}})()),[s,i]=(0,o.useState)({phase:"idle"}),c=(0,o.useRef)(0),d=(0,o.useRef)(null),u=(0,o.useRef)(null),p=(0,o.useCallback)(async()=>{var e;null==(e=d.current)||e.abort();let t=new AbortController;d.current=t;try{let e=await fetch("/api/sync/status",{signal:t.signal,cache:"no-store"});if(!e.ok)throw Error("HTTP ".concat(e.status));let n=await e.json();r(n),c.current=0}catch(e){if("AbortError"===e.name)return;c.current+=1}},[]);(0,o.useEffect)(()=>{p();let t=null;return!function r(){t=setTimeout(async()=>{await p(),r()},Math.min(e*Math.max(1,c.current||1),6e5))}(),()=>{var e;t&&clearTimeout(t),null==(e=d.current)||e.abort()}},[p,e]);let h=(0,o.useMemo)(()=>{if(!t)return[];let e=[],r=hs("gmail",t.gmail);r&&!l.has(r.errorKey)&&e.push(r);let n=hs("calendar",t.calendar);return n&&!l.has(n.errorKey)&&e.push(n),e},[t,l]);(0,o.useEffect)(()=>{if(!t)return;let e=new Set,r=hs("gmail",t.gmail);r&&e.add(r.errorKey);let n=hs("calendar",t.calendar);n&&e.add(n.errorKey),a(t=>{let r=new Set;for(let n of t)e.has(n)&&r.add(n);return r.size===t.size?t:(ha(r),r)})},[t]);let m=(0,o.useCallback)(e=>{a(t=>{let r=new Set(t);return r.add(e),ha(r),r})},[]),x=(0,o.useCallback)(()=>{window.open("/?path=~integrations","_blank","noopener,noreferrer")},[]),f=(0,o.useCallback)(async e=>{var t,r;null==(t=u.current)||t.abort();let n=new AbortController;u.current=n,i({phase:"in-flight",source:e});try{let e=await fetch("/api/sync/refresh",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({mode:"incremental"}),signal:n.signal});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(null!=(r=t.error)?r:"HTTP ".concat(e.status))}await p(),i({phase:"idle"})}catch(t){if("AbortError"===t.name)return;i({phase:"error",source:e,message:t instanceof Error?t.message:"Refresh failed."})}},[p]);return((0,o.useEffect)(()=>()=>{var e;null==(e=u.current)||e.abort()},[]),0===h.length)?null:(0,n.jsx)("div",{role:"status","aria-live":"polite",className:"pointer-events-none fixed top-3 right-3 z-[9999] flex w-full max-w-sm flex-col gap-2",children:h.map(e=>(0,n.jsx)("div",{className:"pointer-events-auto rounded-lg border px-3.5 py-3 shadow-lg",style:{background:"var(--color-surface)",borderColor:"rgba(220, 38, 38, 0.35)",backdropFilter:"blur(12px)"},"data-testid":"sync-health-banner-".concat(e.source),children:(0,n.jsxs)("div",{className:"flex items-start gap-2.5",children:[(0,n.jsx)("span",{"aria-hidden":!0,className:"mt-0.5 flex-shrink-0",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#dc2626",strokeWidth:"2.5",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)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("p",{className:"text-[12.5px] font-semibold leading-tight",style:{color:"var(--color-text)"},children:e.title}),(0,n.jsx)("p",{className:"mt-1 text-[11.5px] leading-snug break-words",style:{color:"var(--color-text-muted)"},children:e.description}),(0,n.jsxs)("div",{className:"mt-2 flex items-center gap-2",children:[e.needsReconnect?(0,n.jsx)("button",{type:"button",onClick:x,className:"rounded-md px-2 py-1 text-[11px] font-medium transition-opacity hover:opacity-90",style:{background:"var(--color-accent)",color:"#fff"},children:"Reconnect"}):null,(0,n.jsx)("button",{type:"button",onClick:()=>void f(e.source),disabled:"in-flight"===s.phase,className:"rounded-md border px-2 py-1 text-[11px] font-medium transition-opacity hover:opacity-80 disabled:cursor-not-allowed disabled:opacity-50",style:{borderColor:"var(--color-border)",color:"var(--color-text)",background:"transparent"},"data-testid":"sync-health-refresh-".concat(e.source),children:"in-flight"===s.phase&&s.source===e.source?"Refreshing…":"Refresh now"}),(0,n.jsx)("button",{type:"button",onClick:()=>m(e.errorKey),className:"rounded-md px-2 py-1 text-[11px] font-medium transition-opacity hover:opacity-70",style:{color:"var(--color-text-muted)"},children:"Dismiss"})]}),"error"===s.phase&&s.source===e.source?(0,n.jsxs)("p",{className:"mt-1.5 text-[11px] leading-snug break-words",style:{color:"#dc2626"},"data-testid":"sync-health-refresh-error-".concat(e.source),children:["Refresh failed: ",s.message]}):null]}),(0,n.jsx)("button",{type:"button","aria-label":"Close",onClick:()=>m(e.errorKey),className:"ml-1 flex-shrink-0 rounded p-0.5 transition-opacity hover:opacity-60",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.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})},e.errorKey))})}function hc(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")}function hd(){return(0,n.jsxs)("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:"M5 12h14"}),(0,n.jsx)("path",{d:"M12 5v14"})]})}function hu(){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 hp(){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 hh(){return(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:(0,n.jsx)("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})})}let hm={telegram:{label:"Telegram",icon:function(){return(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm4.64 6.8c-.15 1.58-.8 5.42-1.13 7.19-.14.75-.42 1-.68 1.03-.58.05-1.02-.38-1.58-.75-.88-.58-1.38-.94-2.23-1.5-.99-.65-.35-1.01.22-1.59.15-.15 2.71-2.48 2.76-2.69a.2.2 0 00-.05-.18c-.06-.05-.14-.03-.21-.02-.09.02-1.49.95-4.22 2.79-.4.27-.76.41-1.08.4-.36-.01-1.04-.2-1.55-.37-.63-.2-1.12-.31-1.08-.66.02-.18.27-.36.74-.55 2.92-1.27 4.86-2.11 5.83-2.51 2.78-1.16 3.35-1.36 3.73-1.36.08 0 .27.02.39.12.1.08.13.19.14.27-.01.06.01.24 0 .38z"})})},color:"#2AABEE"},whatsapp:{label:"WhatsApp",icon:function(){return(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"})})},color:"#25D366"},discord:{label:"Discord",icon:function(){return(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M20.317 4.37a19.791 19.791 0 00-4.885-1.515.074.074 0 00-.079.037c-.21.375-.444.864-.608 1.25a18.27 18.27 0 00-5.487 0 12.64 12.64 0 00-.617-1.25.077.077 0 00-.079-.037A19.736 19.736 0 003.677 4.37a.07.07 0 00-.032.027C.533 9.046-.32 13.58.099 18.057a.082.082 0 00.031.057 19.9 19.9 0 005.993 3.03.078.078 0 00.084-.028c.462-.63.874-1.295 1.226-1.994a.076.076 0 00-.041-.106 13.107 13.107 0 01-1.872-.892.077.077 0 01-.008-.128 10.2 10.2 0 00.372-.292.074.074 0 01.077-.01c3.928 1.793 8.18 1.793 12.062 0a.074.074 0 01.078.01c.12.098.246.198.373.292a.077.077 0 01-.006.127 12.299 12.299 0 01-1.873.892.077.077 0 00-.041.107c.36.698.772 1.362 1.225 1.993a.076.076 0 00.084.028 19.839 19.839 0 006.002-3.03.077.077 0 00.032-.054c.5-5.177-.838-9.674-3.549-13.66a.061.061 0 00-.031-.03zM8.02 15.33c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.956-2.419 2.157-2.419 1.21 0 2.176 1.096 2.157 2.42 0 1.333-.956 2.418-2.157 2.418zm7.975 0c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.955-2.419 2.157-2.419 1.21 0 2.176 1.096 2.157 2.42 0 1.333-.946 2.418-2.157 2.418z"})})},color:"#5865F2"},slack:{label:"Slack",icon:function(){return(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M5.042 15.165a2.528 2.528 0 01-2.52 2.523A2.528 2.528 0 010 15.165a2.527 2.527 0 012.522-2.52h2.52v2.52zm1.271 0a2.527 2.527 0 012.521-2.52 2.527 2.527 0 012.521 2.52v6.313A2.528 2.528 0 018.834 24a2.528 2.528 0 01-2.521-2.522v-6.313zM8.834 5.042a2.528 2.528 0 01-2.521-2.52A2.528 2.528 0 018.834 0a2.528 2.528 0 012.521 2.522v2.52H8.834zm0 1.271a2.528 2.528 0 012.521 2.521 2.528 2.528 0 01-2.521 2.521H2.522A2.528 2.528 0 010 8.834a2.528 2.528 0 012.522-2.521h6.312zM18.956 8.834a2.528 2.528 0 012.522-2.521A2.528 2.528 0 0124 8.834a2.528 2.528 0 01-2.522 2.521h-2.522V8.834zm-1.27 0a2.528 2.528 0 01-2.523 2.521 2.527 2.527 0 01-2.52-2.521V2.522A2.527 2.527 0 0115.163 0a2.528 2.528 0 012.523 2.522v6.312zM15.163 18.956a2.528 2.528 0 012.523 2.522A2.528 2.528 0 0115.163 24a2.527 2.527 0 01-2.52-2.522v-2.522h2.52zm0-1.27a2.527 2.527 0 01-2.52-2.523 2.527 2.527 0 012.52-2.52h6.315A2.528 2.528 0 0124 15.163a2.528 2.528 0 01-2.522 2.523h-6.315z"})})},color:"#4A154B"},signal:{label:"Signal",icon:function(){return(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 15h-2v-6h2v6zm4 0h-2v-6h2v6zm-2-8a1.5 1.5 0 110-3 1.5 1.5 0 010 3zm-4 0a1.5 1.5 0 110-3 1.5 1.5 0 010 3z"})})},color:"#3A76F0"},imessage:{label:"iMessage",icon:function(){return(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M12 2C6.477 2 2 5.813 2 10.5c0 2.684 1.464 5.084 3.768 6.635L4.5 21l4.17-2.083A11.51 11.51 0 0012 19.5c5.523 0 10-3.813 10-8.5S17.523 2 12 2z"})})},color:"#34C759"},googlechat:{label:"Google Chat",icon:function(){return(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10h5v-2h-5a8 8 0 110-16 8 8 0 018 8v1.43c0 .79-.71 1.57-1.5 1.57s-1.5-.78-1.5-1.57V12a5 5 0 10-1.47 3.53 3.5 3.5 0 002.97 1.47c1.93 0 3.5-1.57 3.5-3.57V12c0-5.52-4.48-10-10-10zm0 13a3 3 0 110-6 3 3 0 010 6z"})})},color:"#00AC47"},nostr:{label:"Nostr",icon:function(){return(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"})})},color:"#8B5CF6"}};function hx(e){let{channel:t}=e,r=hm[t];if(!r)return null;let o=r.icon;return(0,n.jsx)("span",{className:"inline-flex shrink-0 items-center justify-center",style:{color:r.color,width:12,height:12},title:r.label,"aria-label":r.label,children:(0,n.jsx)(o,{})})}function hf(e){let{session:t,isActive:r,isHovered:l,isStreaming:a,sessionSubagents:s,activeSubagentKey:i,renamingId:c,renameValue:d,onHover:u,onLeave:p,onSelect:h,onStartRename:m,onCommitRename:x,onCancelRename:f,onRenameChange:v,onDelete:g,onStop:y,onSelectSubagent:b,onStopSubagent:j}=e,[k,w]=(0,o.useState)(!1),N=l||a||k,C=!!(m||g),S=(0,n.jsxs)("div",{className:"group relative",onMouseEnter:()=>u(t.id),onMouseLeave:()=>{k||p()},children:[(0,n.jsxs)("div",{className:"flex items-stretch w-full rounded-lg",style:{background:r?"var(--color-chat-sidebar-active-bg)":l||k?"var(--color-surface-hover)":"transparent"},children:[c===t.id?(0,n.jsx)("form",{className:"flex-1 min-w-0 px-2 py-1.5",onSubmit:e=>{e.preventDefault(),null==x||x()},children:(0,n.jsx)("input",{type:"text",value:d,onChange:e=>null==v?void 0:v(e.target.value),onBlur:x,onKeyDown:e=>{"Escape"===e.key&&(null==f||f())},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:()=>h(t.id),className:"flex-1 min-w-0 text-left px-2 py-1.5 rounded-l-lg cursor-pointer",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[a&&(0,n.jsx)(da.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:r?"var(--color-chat-sidebar-active-text)":"var(--color-text)"},children:t.title||"Untitled chat"})]}),(0,n.jsx)("div",{className:"mt-0.5 text-[10px]",style:{color:"var(--color-text-muted)",paddingLeft:a?"calc(0.375rem + 6px)":void 0},children:hc(t.updatedAt)})]}),(0,n.jsxs)("div",{className:"shrink-0 flex items-center pr-1 gap-0.5 transition-opacity ".concat(N?"opacity-100":"opacity-0"),children:[a&&y&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),y(t.id)},className:"flex items-center justify-center w-6 h-6 rounded-md transition-colors hover:bg-black/5",style:{color:"var(--color-text-muted)"},title:"Stop chat","aria-label":"Stop chat",children:(0,n.jsx)(hh,{})}),g&&(0,n.jsxs)(tG.rI,{children:[(0,n.jsx)(tG.ty,{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)(hp,{})}),(0,n.jsxs)(tG.SQ,{align:"end",side:"bottom",children:[m&&(0,n.jsxs)(tG._2,{onSelect:()=>m(t.id,t.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)(tG._2,{variant:"destructive",onSelect:()=>g(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",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&&s.length>0&&(0,n.jsx)("div",{className:"ml-4 border-l",style:{borderColor:"var(--color-border)"},children:s.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.jsxs)("div",{className:"flex items-center",children:[(0,n.jsx)("button",{type:"button",onClick:()=>null==b?void 0:b(e.childSessionKey),className:"flex-1 text-left pl-3 pr-2 py-1.5 rounded-r-lg 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)(da.V,{name:"braille",className:"text-[9px] flex-shrink-0",style:{color:"var(--color-chat-sidebar-muted)"}}),(0,n.jsx)(hu,{}),(0,n.jsx)("span",{className:"text-[11px] truncate",style:{color:t?"var(--color-chat-sidebar-active-text)":"var(--color-text-muted)"},children:l})]})}),r&&j&&(0,n.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),j(e.childSessionKey)},className:"shrink-0 flex items-center justify-center w-6 h-6 rounded-md mr-1 transition-colors hover:bg-black/5",style:{color:"var(--color-text-muted)"},title:"Stop subagent","aria-label":"Stop subagent",children:(0,n.jsx)(hh,{})})]},e.childSessionKey)})})]});return C?(0,n.jsxs)(B,{onOpenChange:e=>{w(e),e||p()},children:[(0,n.jsx)(W,{asChild:!0,children:S}),(0,n.jsxs)(O,{className:"min-w-[160px]",children:[m&&(0,n.jsxs)(z,{onSelect:()=>m(t.id,t.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"]}),g&&(0,n.jsxs)(z,{variant:"destructive",onSelect:()=>g(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",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}function hv(e){let{gs:t,isActive:r,isHovered:o,onHover:l,onLeave:a,onSelect:s}=e;return(0,n.jsx)("div",{onMouseEnter:()=>l(t.sessionKey),onMouseLeave:a,children:(0,n.jsxs)("button",{type:"button",onClick:()=>s(t.sessionKey,t.sessionId),className:"w-full text-left px-2 py-1.5 rounded-lg cursor-pointer",style:{background:r?"var(--color-chat-sidebar-active-bg)":o?"var(--color-surface-hover)":"transparent"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)(hx,{channel:t.channel}),(0,n.jsx)("div",{className:"text-xs font-medium truncate",style:{color:r?"var(--color-chat-sidebar-active-text)":"var(--color-text)"},children:t.title})]}),(0,n.jsx)("div",{className:"mt-0.5 text-[10px]",style:{color:"var(--color-text-muted)",paddingLeft:"calc(12px + 0.375rem)"},children:hc(t.updatedAt)})]})})}function hg(e){let{sessions:t,activeSessionId:r,activeSessionTitle:l,streamingSessionIds:a,subagents:s,activeSubagentKey:i,onSelectSession:c,onNewSession:d,onSelectSubagent:u,onDeleteSession:p,onRenameSession:h,onStopSession:m,onStopSubagent:x,onCollapse:f,mobile:v,onClose:g,width:y,loading:b=!1,embedded:j=!1,gatewaySessions:k,activeGatewaySessionKey:w,onSelectGatewaySession:N}=e,[C,S]=(0,o.useState)(null),[M,T]=(0,o.useState)(null),[L,I]=(0,o.useState)(""),_=(0,o.useCallback)(e=>{c(e),null==g||g()},[c,g]),R=(0,o.useCallback)(e=>{null==u||u(e),null==g||g()},[u,g]),E=(0,o.useCallback)(e=>{null==p||p(e)},[p]),D=(0,o.useCallback)((e,t)=>{T(e),I(t||"")},[]),A=(0,o.useCallback)(()=>{M&&L.trim()&&(null==h||h(M,L.trim())),T(null),I("")},[M,L,h]),F=(0,o.useCallback)(()=>{T(null),I("")},[]),P=(0,o.useCallback)((e,t)=>{null==N||N(e,t),null==g||g()},[N,g]),B=(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]),W=(0,o.useMemo)(()=>{let e=[];for(let r of t)r.id.includes(":subagent:")||r.filePath||e.push({kind:"native",ts:r.updatedAt,session:r});if(k)for(let t of k)"cron"!==t.channel&&"unknown"!==t.channel&&e.push({kind:"gateway",ts:t.updatedAt,gs:t});return e.sort((e,t)=>t.ts-e.ts),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.ts;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",rows:a}),s.length>0&&u.push({label:"yesterday",rows:s}),i.length>0&&u.push({label:"this week",rows:i}),c.length>0&&u.push({label:"this month",rows:c}),d.length>0&&u.push({label:"older",rows:d}),u}(e)},[t,k]),O=W.reduce((e,t)=>e+t.rows.length,0),z=j?36:40,U=(0,n.jsxs)("div",{className:"flex-1 min-h-0 relative",children:[(0,n.jsx)("div",{className:"absolute inset-0 overflow-y-auto",style:j?void 0:{paddingTop:z},children:b&&0===O?(0,n.jsxs)("div",{className:"px-4 py-8 flex flex-col items-center justify-center min-h-[120px]",children:[(0,n.jsx)(da.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===O?(0,n.jsx)("div",{className:"px-4 py-8 text-center",children:(0,n.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"No conversations yet."})}):(0,n.jsx)("div",{className:"px-2 py-1",children:W.map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-2 pt-4 pb-1 text-[9px] lowercase",style:{color:"var(--color-text-muted)",letterSpacing:"0.05em"},children:e.label}),e.rows.map(e=>{if("native"===e.kind){var t;let o=e.session;return(0,n.jsx)(hf,{session:o,isActive:o.id===r&&!i&&!w,isHovered:o.id===C,isStreaming:null!=(t=null==a?void 0:a.has(o.id))&&t,sessionSubagents:B.get(o.id),activeSubagentKey:i,renamingId:M,renameValue:L,onHover:S,onLeave:()=>S(null),onSelect:_,onStartRename:h?D:void 0,onCommitRename:A,onCancelRename:F,onRenameChange:I,onDelete:p?E:void 0,onStop:m,onSelectSubagent:R,onStopSubagent:x},"n-".concat(o.id))}let o=e.gs;return(0,n.jsx)(hv,{gs:o,isActive:w===o.sessionKey,isHovered:C===o.sessionKey,onHover:S,onLeave:()=>S(null),onSelect:P},"g-".concat(o.sessionKey))})]},e.label))})}),!j&&(0,n.jsx)("div",{className:"absolute top-0 left-0 right-0 z-10 backdrop-blur-md border-b",style:{borderColor:"var(--color-border)",background:"color-mix(in srgb, var(--color-bg) 80%, transparent)"},children:(0,n.jsxs)("div",{className:"flex items-center justify-between px-3",style:{height:z},children:[f?(0,n.jsx)("button",{type:"button",onClick:f,className:"p-1 rounded-md transition-colors hover:bg-black/5",style:{color:"var(--color-text-muted)"},title:"Hide chat sidebar",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",{}),(0,n.jsxs)("button",{type:"button",onClick:d,className:"flex items-center gap-1 px-2 py-1 rounded-lg text-[11px] font-medium transition-colors cursor-pointer",style:{color:"var(--color-text-muted)"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-surface-hover)",e.currentTarget.style.color="var(--color-text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--color-text-muted)"},title:"New chat",children:[(0,n.jsx)(hd,{}),"New"]})]})})]});if(j)return U;let H=v?"280px":null!=y?y:260,V=(0,n.jsx)("aside",{className:"flex flex-col h-full shrink-0 ".concat(v?"drawer-right":"border-l"),style:{width:"number"==typeof H?"".concat(H,"px"):H,minWidth:"number"==typeof H?"".concat(H,"px"):H,borderColor:"var(--color-border)",background:"var(--color-sidebar-bg)"},children:U});return v?(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 right-0 z-50",children:V})}):V}function hy(e){let{children:t}=e;return(0,n.jsx)("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:t})}function hb(e,t){if(!(t in e))return e;let r={...e};return delete r[t],r}function hj(e){return{parentStatuses:new Map(e.parentRuns.map(e=>[e.sessionId,e.status])),subagentStatuses:new Map(e.subagents.map(e=>[e.childSessionKey,e.status]))}}let hk=(0,li.default)(()=>Promise.all([r.e(32078),r.e(4560),r.e(77858)]).then(r.bind(r,77858)),{loadableGenerated:{webpack:()=>[77858]},ssr:!1}),hw="dench-workspace-left-sidebar-width",hN="dench-workspace-right-panel-width",hC="dench-workspace-right-panel-collapsed",hS="dench-workspace-file-tree-collapsed";function hM(e,t,r){return Math.min(r,Math.max(t,e))}function hT(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(hM("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:40}})}function hL(e,t){for(let r of e){if(r.path===t)return r;if(r.children){let e=hL(r.children,t);if(e)return e}}return null}function hI(e){let t=e.split("/");return t[t.length-1]}let h_=new Set(["people","company","companies"]),hR=new Set(["email_thread","email_message","calendar_event","interaction"]),hE=new Set(["people","company","companies"]);function hD(e,t){if("~cron"===t)return"cron-dashboard";if(t.startsWith("~cron/"))return"cron-job";if("~skills"===t)return"skills";if("~integrations"===t)return"integrations";if("~cloud"===t)return"cloud";if("~crm/inbox"===t)return"crm-inbox";if("~crm/calendar"===t)return"crm-calendar";switch(e){case"object":return"object";case"document":return"document";case"database":return"database";case"report":return"report";case"app":return"app";case"folder":return"directory";default:return"file"}}function hA(e,t){let r=hL(e,t);if(r||!t.startsWith("knowledge/")&&(r=hL(e,"knowledge/".concat(t)))||t.startsWith("knowledge/")&&(r=hL(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&&hI(r.path)===n)return r;if(r.children){let t=e(r.children);if(t)return t}}return null}(e))?r:null}function hF(){return(0,n.jsxs)(r8,{children:[(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)(da.V,{name:"braille",className:"text-2xl",style:{color:"var(--color-text-muted)"}})}),children:(0,n.jsx)(hP,{})}),(0,n.jsx)(hi,{})]})}function hP(){var e,t,r;let a=(0,l.useSearchParams)(),s=(0,l.useRouter)(),i=(0,o.useRef)("init"),c=(0,o.useRef)(!1),d=(0,o.useRef)(null),u=(0,o.useRef)({}),p=(0,o.useRef)(null),[h,m]=(0,o.useState)(0),{tree:x,loading:f,exists:v,refresh:g,reconnect:y,browseDir:b,setBrowseDir:j,parentDir:k,workspaceRoot:w,openclawDir:N,activeWorkspace:C,showHidden:S,setShowHidden:T}=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,p]=(0,o.useState)(null),[h,m]=(0,o.useState)(null),[x,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.useRef)(new Map),C=(0,o.useCallback)(e=>{let t=N.current,r=new Map,n=e=>e.map(e=>{let o=t.get(e.path),l=e;return"object"===e.type&&!e.defaultView&&(null==o?void 0:o.defaultView)&&(l={...e,defaultView:o.defaultView}),"object"===l.type&&r.set(l.path,{type:l.type,defaultView:l.defaultView}),l.children&&l.children.length>0&&(l={...l,children:n(l.children)}),l}),o=n(e);return N.current=r,o},[]),S=(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(C(null!=(r=h.tree)?r:[])),a(null!=(o=h.exists)&&o),p(null!=(l=h.workspaceRoot)?l:null),m(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]),M=(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]),T=(0,o.useRef)(null),L=(0,o.useCallback)(e=>{let t=e;null!=e&&u&&e===u&&(t=null),null!=t&&t!==T.current&&n(!0),T.current=t,i(t)},[u]),I=(0,o.useCallback)(async()=>{s?await M(s):await S()},[s,M,S]),_=(0,o.useCallback)(()=>{I()},[I]),R=(0,o.useCallback)(()=>{w(e=>e+1),I()},[I]);return(0,o.useEffect)(()=>(y.current=!0,I(),()=>{y.current=!1}),[I]),(0,o.useEffect)(()=>{if(s)return;let e=null,t=null,r=null,n=!0,o=null;function l(){!t&&n&&(t=setInterval(()=>{n&&S()},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&&S()},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,S,k]),{tree:e,loading:r,exists:l,refresh:_,reconnect:R,browseDir:s,setBrowseDir:L,parentDir:c,workspaceRoot:u,openclawDir:h,activeWorkspace:x,showHidden:v,setShowHidden:g}}(),L=(0,o.useRef)(0),[I,_]=(0,o.useState)(0);(0,o.useEffect)(()=>{x.length>0&&(L.current+=1,_(L.current))},[x]);let{search:R}=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 dU.A(e,dH)},[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),[])}}(I),[E,D]=(0,o.useState)(null),[A,P]=(0,o.useState)(null),[B,W]=(0,o.useState)([]),[O,z]=(0,o.useState)(!0),[U,H]=(0,o.useState)(0),[V,K]=(0,o.useState)(new Set),[J,q]=(0,o.useState)({}),[G,$]=(0,o.useState)(()=>hj({parentRuns:[],subagents:[]})),[Y,Q]=(0,o.useState)([]),[X,ee]=(0,o.useState)(null),[et,er]=(0,o.useState)([]),[en,eo]=(0,o.useState)(null),[el,ea]=(0,o.useState)([]),[es,ei]=(0,o.useState)("overview"),[ec,ed]=(0,o.useState)("month"),[eu,ep]=(0,o.useState)(null),[eh,em]=(0,o.useState)("all"),[ex,ef]=(0,o.useState)(null),[ev,eg]=(0,o.useState)(null),ey=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}(),[eb,ej]=(0,o.useState)(!1),[ek,ew]=(0,o.useState)(!1),[eN,eC]=(0,o.useState)(!0),[eS,eM]=(0,o.useState)(!1),[eT,eL]=(0,o.useState)(!1),[eI,e_]=(0,o.useState)(!1),[eR,eE]=(0,o.useState)(null),[eD,eA]=(0,o.useState)(null);(0,o.useEffect)(()=>{let e=()=>{var e,t;m(null!=(t=null==(e=p.current)?void 0:e.clientWidth)?t:window.innerWidth)};e();let t="undefined"!=typeof ResizeObserver&&p.current?new ResizeObserver(e):null;return p.current&&(null==t||t.observe(p.current)),window.addEventListener("resize",e),()=>{null==t||t.disconnect(),window.removeEventListener("resize",e)}},[]);let[eF,eP]=(0,o.useReducer)(d8,dV),eB=(0,o.useRef)(dV);(0,o.useEffect)(()=>{eB.current=eF},[eF]);let eW=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e=C||null;eW.current!==e&&(eW.current=e,eP({type:"replace",state:d1(function(e){try{var t,r,n,o;let l=window.localStorage.getItem(d2(e));if(!l)return dV;let a=JSON.parse(l),s=Array.isArray(a.contentTabs)?a.contentTabs.filter(d4):[],i=Array.isArray(a.chatTabs)?a.chatTabs.filter(d5):[],c=null!=(t=a.activeContentId)?t:null;c&&!s.some(e=>e.id===c)&&(c=null);let d=null!=(r=a.activeChatId)?r:null;return d&&!i.some(e=>e.id===d)&&(d=null!=(o=null==(n=i[0])?void 0:n.id)?o:null),{contentTabs:s,chatTabs:i,activeContentId:c,activeChatId:d}}catch(e){return dV}}(e))}),q({}))},[C]),(0,o.useEffect)(()=>{if("hydrated"===i.current){var e=C||null;try{let t={contentTabs:eF.contentTabs.map(d3),chatTabs:eF.chatTabs.filter(e=>"draft"!==e.variant||e.pinned).map(d6),activeContentId:eF.activeContentId,activeChatId:eF.activeChatId};window.localStorage.setItem(d2(e),JSON.stringify(t))}catch(e){}}},[eF,C]),(0,o.useEffect)(()=>{let e=new Set([...eF.contentTabs.map(e=>e.id),...eF.chatTabs.map(e=>e.id)]);for(let t of(q(t=>{let r=t;for(let n of Object.keys(t))e.has(n)||(r=hb(r,n));return r}),Object.keys(u.current)))e.has(t)||delete u.current[t]},[eF.contentTabs,eF.chatTabs]);let eO=(0,o.useMemo)(()=>dQ(eF),[eF]),ez=null!=(r=null==eO?void 0:eO.path)?r:null;eF.activeContentId;let eU=eF.activeChatId;eF.contentTabs;let eH=eF.chatTabs,eV=(0,o.useRef)(null),eK=(0,o.useCallback)(()=>{let e=dY();return P(null),ee(null),eP({type:"openChat",tab:{...e,preview:!0}}),e},[]),eJ=(0,o.useCallback)(()=>{let e=dY();return P(null),ee(null),eP({type:"openChat",tab:{...e,preview:!1}}),e},[]),eq=(0,o.useCallback)((e,t)=>{var r;P(e),ee(null),eP({type:"openChat",tab:{...d$({id:(r={sessionId:e,title:t}).sessionId,variant:"session",title:r.title||"New Chat",sessionId:r.sessionId}),preview:!0}})},[]),eG=(0,o.useCallback)(e=>{P(e.parentSessionId),ee(e.sessionKey),eP({type:"openChat",tab:{...d$({id:e.sessionKey,variant:"subagent",title:e.title||"Subagent",sessionKey:e.sessionKey,parentSessionId:e.parentSessionId}),preview:!0}})},[]),e$=(0,o.useCallback)((e,t,r,n)=>{var o;P(null),ee(null),eo(e),eP({type:"openChat",tab:{...d$({id:(o={sessionKey:e,sessionId:t,channel:null!=r?r:"unknown",title:null!=n?n:"Channel Chat"}).sessionKey,variant:"gateway",title:o.title||"Channel Chat",sessionId:o.sessionId,sessionKey:o.sessionKey,channel:o.channel}),preview:!0}})},[]),eY=(0,o.useCallback)(e=>{e&&(eB.current.contentTabs.some(t=>t.id===e)?eP({type:"promoteContent",id:e}):eP({type:"promoteChat",id:e}))},[]),eZ=(0,o.useCallback)(e=>{e&&eP({type:"promoteContentByPath",path:e})},[]),eQ=(0,o.useMemo)(()=>{var e,t;if(eU&&eH.some(e=>e.id===eU))return eU;if(en){let e=eH.find(e=>"gateway"===e.variant&&e.sessionKey===en);if(e)return e.id}if(X){let e=eH.find(e=>e.sessionKey===X);if(e)return e.id}if(A){let e=eH.find(e=>e.sessionId===A);if(e)return e.id}return null!=(t=null==(e=eH[0])?void 0:e.id)?t:null},[eU,A,X,en,eH]);(0,o.useEffect)(()=>{if(!eU)return;let e=eH.find(e=>e.id===eU);e&&(P(t=>{var r,n;return t===(null!=(r=e.sessionId)?r:null)?t:null!=(n=e.sessionId)?n:null}),"subagent"===e.variant?ee(t=>{var r,n;return t===(null!=(r=e.sessionKey)?r:null)?t:null!=(n=e.sessionKey)?n:null}):ee(e=>null===e?e:null),"gateway"===e.variant?eo(t=>{var r,n;return t===(null!=(r=e.sessionKey)?r:null)?t:null!=(n=e.sessionKey)?n:null}):eo(e=>null===e?e:null))},[eU,eH]);let eX=(0,o.useCallback)((e,t)=>{u.current[e]=t},[]);(0,o.useEffect)(()=>{var e;d.current=eQ&&null!=(e=u.current[eQ])?e:null},[eQ]);let e0=(0,o.useCallback)((e,t)=>{q(r=>(function(e,t){let r=e[t.tabId];return r&&r.sessionId===t.sessionId&&r.sessionKey===t.sessionKey&&r.isStreaming===t.isStreaming&&r.status===t.status&&r.isReconnecting===t.isReconnecting&&r.loadingSession===t.loadingSession?e:{...e,[t.tabId]:t}})(r,{tabId:e,...t}))},[]),e1=(0,o.useCallback)((e,t)=>{eP({type:"bindChatSession",tabId:e,sessionId:t}),(eQ===e||eU===e)&&(P(t),ee(null))},[eQ,eU]),e2=(0,o.useCallback)((e,t)=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{var r;null==(r=u.current[e])||r.sendNewMessage(t)})})},[]),e4=(0,o.useCallback)(e=>{let t=Y.find(t=>t.childSessionKey===e);if(t)return void eG({sessionKey:t.childSessionKey,parentSessionId:t.parentSessionId,title:t.label||t.task});let r=Y.find(t=>t.task===e);r&&eG({sessionKey:r.childSessionKey,parentSessionId:r.parentSessionId,title:r.label||r.task})},[eG,Y]),e5=(0,o.useCallback)(e=>{let t=Y.find(t=>t.childSessionKey===e);t&&eG({sessionKey:e,parentSessionId:t.parentSessionId,title:t.label||t.task})},[eG,Y]),e3=(0,o.useCallback)(()=>{if(!X)return;let e=Y.find(e=>e.childSessionKey===X);if(e)return void eq(e.parentSessionId);ee(null)},[X,eq,Y]),e6=(0,o.useCallback)((e,t)=>{var r;let n=hD(e.type,e.path),o="object"===n?(0,M.PV)(e.name):dZ(e.path,e.name);eP({type:"openContent",tab:{id:dK(n,e.path),kind:n,path:e.path,title:o,preview:null==(r=null==t?void 0:t.preview)||r}})},[]),[e8,e7]=(0,o.useState)(56),[e9,te]=(0,o.useState)(520);(0,o.useEffect)(()=>{let e=window.localStorage.getItem(hw),t=e?parseInt(e,10):NaN;Number.isFinite(t)&&e7(t<140?56:hM(t,200,480));let r=window.localStorage.getItem(hN),n=r?parseInt(r,10):NaN;Number.isFinite(n)&&te(hM(n,360,2e3)),"0"===window.localStorage.getItem(hC)&&eC(!1),"1"===window.localStorage.getItem(hS)&&eL(!0)},[]);let tt=e8<200,tr=ey||ek?0:e8,tn=(0,o.useMemo)(()=>{let e=h||window.innerWidth;return e?hM(e-tr-300,360,2e3):e9},[h,tr,e9]),to=Math.min(e9,tn),tl=eN?0:to,ta=(0,o.useCallback)(e=>{e<140?e7(56):e<200?e7(200):e7(hM(e,200,480))},[]),ts=(0,o.useCallback)(()=>{e7(e=>e<200?260:56)},[]);(0,o.useEffect)(()=>{window.localStorage.setItem(hw,String(e8))},[e8]),(0,o.useEffect)(()=>{window.localStorage.setItem(hN,String(e9))},[e9]),(0,o.useEffect)(()=>{window.localStorage.setItem(hC,eN?"1":"0")},[eN]),(0,o.useEffect)(()=>{window.localStorage.setItem(hS,eT?"1":"0")},[eT]),(0,o.useEffect)(()=>{let e=e=>{let t=e.metaKey||e.ctrlKey,r=e.key.toLowerCase();if(t&&"b"===r){e.preventDefault(),e.shiftKey?eC(e=>!e):ew(e=>!e);return}if(t&&"e"===r&&!e.shiftKey&&!e.altKey){e.preventDefault(),eL(e=>!e);return}if(t&&"j"===r&&!e.shiftKey&&!e.altKey){e.preventDefault(),e_(e=>!e);return}if(t&&"w"===r&&!e.shiftKey&&!e.altKey){var n;e.preventDefault(),null==(n=eV.current)||n.call(eV);return}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let ti=(0,o.useMemo)(()=>{if(!ez)return;let e=(()=>{if(ez.startsWith("~crm/")){let e=ez.slice(5);return"CRM ".concat(e.charAt(0).toUpperCase()).concat(e.slice(1))}return"~cloud"===ez?"Cloud settings":"~integrations"===ez?"Integrations panel":"~skills"===ez?"Skills store":"~cron"===ez?"Cron dashboard":ez.startsWith("~cron/")?"Cron job ".concat(ez.slice(6)):ez.split("/").pop()||ez})(),t=(null==eO?void 0:eO.kind)==="directory"||(null==eO?void 0:eO.kind)==="browse"||(0,Z.L6)(ez)||(null==eO?void 0:eO.kind)==="crm-inbox"||(null==eO?void 0:eO.kind)==="crm-calendar";return{path:ez,filename:e,isDirectory:t,tableSelection:null!=eD?eD:void 0}},[ez,null==eO?void 0:eO.kind,eD]),tc=(0,o.useCallback)(e=>{},[]),td=(0,o.useCallback)(async()=>{try{let e=await fetch("/api/workspace/context"),t=await e.json();D(t)}catch(e){}},[]);(0,o.useEffect)(()=>{td()},[td]);let tu=(0,o.useCallback)(async()=>{z(!0);try{var e;let t=await fetch("/api/web-sessions?includeAll=true"),r=null!=(e=(await t.json()).sessions)?e:[];W(r)}catch(e){}finally{z(!1)}},[]);(0,o.useEffect)(()=>{tu()},[tu,U]);let tp=(0,o.useCallback)(()=>{H(e=>e+1)},[]),th=(0,o.useCallback)(async()=>{try{var e;let t=await fetch("/api/gateway/sessions"),r=(null!=(e=(await t.json()).sessions)?e:[]).map(e=>{var t;return{sessionKey:e.sessionKey,sessionId:e.sessionId,channel:e.channel,title:(null==(t=e.origin)?void 0:t.label)||"".concat(e.channel.charAt(0).toUpperCase()+e.channel.slice(1)," Session"),updatedAt:e.updatedAt,origin:e.origin}});er(r)}catch(e){}},[]);(0,o.useEffect)(()=>{th();let e=setInterval(th,1e4);return()=>{clearInterval(e)}},[th]);let tm=(0,o.useCallback)(()=>{(async()=>{var e;try{let e=await fetch("/api/onboarding/state",{cache:"no-store"});if(e.ok){let t=await e.json();if(t.currentStep&&"complete"!==t.currentStep)return void window.location.assign("/onboarding")}}catch(e){}(e={setBrowseDir:j,clearActiveContent:()=>eP({type:"activateContent",id:null}),setActiveSessionId:P,setActiveSubagentKey:ee,resetMainChat:()=>{u.current={},q({}),$(hj({parentRuns:[],subagents:[]})),K(new Set),Q([]),eP({type:"replace",state:d1(dV)})},replaceUrlToRoot:()=>{},reconnectWorkspaceWatcher:y,refreshSessions:tp,refreshContext:()=>{td()}}).setBrowseDir(null),e.clearActiveContent(),e.setActiveSessionId(null),e.setActiveSubagentKey(null),e.resetMainChat(),e.replaceUrlToRoot(),e.reconnectWorkspaceWatcher(),e.refreshSessions(),e.refreshContext()})()},[y,td,tp,s,j]),tx=(0,o.useCallback)(async e=>{if(!(await fetch("/api/web-sessions/".concat(e),{method:"DELETE"})).ok)return;let t=new Set(eB.current.chatTabs.filter(t=>t.sessionId===e||t.parentSessionId===e).map(e=>e.id));if(eP({type:"closeChatsForSession",sessionId:e}),q(e=>{let r=e;for(let e of t)r=hb(r,e);return r}),A===e){let t=B.filter(t=>t.id!==e);t.length>0?eq(t[0].id,t[0].title):eK()}tu()},[A,B,tu,eK,eq]),tf=(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})}),tu()},[tu]);(0,o.useEffect)(()=>{let e=!1,t=async()=>{try{var t,r;let n=await fetch("/api/chat/runs");if(e)return;let o=await n.json(),l=null!=(t=o.parentRuns)?t:[],a=null!=(r=o.subagents)?r:[],s=l.filter(e=>"running"===e.status||"waiting-for-subagents"===e.status).map(e=>e.sessionId);$(hj({parentRuns:l,subagents:a.map(e=>{var t;return{childSessionKey:e.childSessionKey,status:null!=(t=e.status)?t:"completed"}})})),Q(a),K(e=>e.size===s.length&&s.every(t=>e.has(t))?e:new Set(s))}catch(e){}};t();let r=setInterval(t,3e3);return()=>{e=!0,clearInterval(r)}},[]);let tv=(0,o.useCallback)(async()=>{try{var e;let t=await fetch("/api/cron/jobs"),r=await t.json();ea(null!=(e=r.jobs)?e:[])}catch(e){}},[]);(0,o.useEffect)(()=>{tv();let e=setInterval(tv,3e4);return()=>clearInterval(e)},[tv]);let tg=(0,o.useCallback)(()=>{eg(e=>e?null:e)},[]),ty=(0,o.useCallback)(()=>{},[]),tb=(0,o.useCallback)(()=>{var e,t;let r=hM((null!=(t=null==(e=p.current)?void 0:e.clientWidth)?t:window.innerWidth)-tr-300,360,2e3);eC(!1),te(e=>Math.max(e,r))},[tr]),tj=(0,o.useCallback)(e=>{if(tb(),"crm-people"===e||"crm-companies"===e){var t,r;e6(null!=(r=function e(t,r){for(let n of t){if("object"===n.type&&hI(n.path)===r)return n;if(n.children){let t=e(n.children,r);if(t)return t}}return null}(x,t="crm-people"===e?"people":"company"))?r:{name:t,path:t,type:"object"},{preview:!1}),tg();return}let n={cloud:{path:"~cloud",name:"Cloud"},integrations:{path:"~integrations",name:"Integrations"},skills:{path:"~skills",name:"Skills"},cron:{path:"~cron",name:"Cron"},"crm-inbox":{path:"~crm/inbox",name:"Inbox"},"crm-calendar":{path:"~crm/calendar",name:"Calendar"}}[e];e6({path:n.path,name:n.name,type:"folder"},{preview:!1}),tg()},[e6,x,tb,tg]),tk=(0,o.useCallback)(e=>{var t,r;eE({action:e.action,toolkitSlug:null!=(t=e.toolkitSlug)?t:null,toolkitName:null!=(r=e.toolkitName)?r:null})},[]),tw=(0,o.useCallback)(()=>{eE(null)},[]),tN=(0,o.useCallback)(()=>{tj("integrations")},[tj]),tC=(0,o.useCallback)(e=>{if(b&&(0,Z.Z1)(e.path)){if(w&&e.path===w)return void j(null);if(N&&N&&e.path.startsWith(N+"/web-chat")){j(null),eP({type:"activateContent",id:null}),eK();return}if("folder"===e.type){j(e.path),eP({type:"openContent",tab:{id:dK("browse",e.path,{browsePath:e.path}),kind:"browse",path:e.path,title:e.name,meta:{browsePath:e.path},preview:!0}}),tg();return}}if(e.path.startsWith("~chats/"))return void eq(e.path.slice(7));if("~chats"===e.path)return void eK();if("~skills"===e.path)return void tj("skills");if("~integrations"===e.path)return void tj("integrations");if("~cloud"===e.path)return void tj("cloud");if("~cron"===e.path||e.path.startsWith("~cron/")){e6(e),tg();return}"folder"!==e.type&&(e6(e),tg())},[eK,eq,e6,b,w,N,j,tj,tg]);(0,o.useCallback)(e=>{eB.current.contentTabs.some(t=>t.id===e)?(tg(),eP({type:"activateContent",id:e})):eP({type:"activateChat",id:e})},[tg]);let tS=(0,o.useCallback)(e=>{eB.current.contentTabs.some(t=>t.id===e)?eP({type:"closeContent",id:e}):eP({type:"closeChat",id:e})},[]);(0,o.useEffect)(()=>{eV.current=()=>{eF.activeContentId?tS(eF.activeContentId):eF.activeChatId&&tS(eF.activeChatId)}},[eF.activeContentId,eF.activeChatId,tS]);let tM=(0,o.useCallback)(e=>{eB.current.contentTabs.some(t=>t.id===e)&&eP({type:"closeOtherContent",id:e})},[]),tT=(0,o.useCallback)(e=>{eB.current.contentTabs.some(t=>t.id===e)&&eP({type:"closeContentToRight",id:e})},[]),tL=(0,o.useCallback)(()=>{eP({type:"closeAllContent"}),P(null),ee(null),eg(null)},[]);(0,o.useCallback)((e,t,r)=>{eB.current.contentTabs.some(t=>t.id===e)&&(eP({type:"promoteContent",id:e}),eP({type:"reorderContent",id:e,toIndex:r}))},[]),(0,o.useCallback)(e=>{eB.current.contentTabs.some(t=>t.id===e)?eP({type:"togglePinContent",id:e}):eP({type:"togglePinChat",id:e})},[]);let tI=(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=e=>(tC(e),!0);if(!(0,Z.Z1)(t)&&!(0,Z.Pv)(t)&&!t.startsWith("./")&&!t.startsWith("../")){let e=hA(x,t);if(e)return r(e)}try{let e=await fetch("/api/workspace/path-info?path=".concat(encodeURIComponent(t)));if(!e.ok)return!1;let n=await e.json();if(!n.path||!n.name||!n.type)return!1;if(w&&(n.path===w||n.path.startsWith("".concat(w,"/")))){let e=n.path===w?"":n.path.slice(w.length+1);if(e){let t=hA(x,e);if(t)return r(t)}}if("directory"===n.type){let e={name:n.name,path:n.path,type:"folder"};return r(e)}if("file"===n.type){let e={name:n.name,path:n.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"}(n.name)};return r(e)}}catch(e){}return!1},[x,tC,w]),t_=(0,o.useMemo)(()=>new Set(["people","company","companies","email_thread","email_message","calendar_event","interaction"]),[]),tR=(0,o.useMemo)(()=>x.filter(e=>!t_.has(e.path)),[x,t_]),tE=(0,o.useMemo)(()=>b?k:w?"/"===w?null:w.split("/").slice(0,-1).join("/")||"/":null,[b,k,w]),tD=(0,o.useCallback)(()=>{null!=tE&&j(tE)},[tE,j]),tA=(0,o.useCallback)(()=>{j(null)},[j]),tF=(0,o.useCallback)(()=>{P(null),ee(null),eo(null);let e=eB.current.chatTabs.filter(e=>"draft"===e.variant);0===e.length?eP({type:"openChat",tab:{...dY(),preview:!0}}):eP({type:"activateChat",id:e[0].id})},[]),tP=(0,o.useCallback)(e=>{var t,r;null==(r=d.current)||null==(t=r.insertFileMention)||t.call(r,e.name,e.path)},[]),tB=(0,o.useCallback)(e=>{let t=null==b&&w&&e.path.startsWith(w+"/")?e.path.slice(w.length+1):e.path,r={name:e.name,path:t,type:e.type};"folder"===e.type&&null!=b?j(e.path):"folder"!==e.type&&null!=b&&j(e.path.split("/").slice(0,-1).join("/")||"/"),e6(r),tg()},[b,w,j,e6,tg]);(0,o.useEffect)(()=>{let e=new URLSearchParams(window.location.search);if("1"===e.get("terminal")===eI)return;eI?e.set("terminal","1"):e.delete("terminal");let t=e.toString();window.history.replaceState(window.history.state,"",t?"/?".concat(t):"/")},[eI]);let tW=(0,o.useCallback)((e,t,r)=>{let n=r?!!r&&r===d7.people:"people"===e,o=r?!!r&&r===d7.company:"company"===e||"companies"===e;n?(eP({type:"openContent",tab:{id:dK("crm-person","people",{entryId:t}),kind:"crm-person",path:"people",title:"Person",meta:{entryId:t},preview:!0}}),eg(null)):o?(eP({type:"openContent",tab:{id:dK("crm-company","company",{entryId:t}),kind:"crm-company",path:"company",title:"Company",meta:{entryId:t},preview:!0}}),eg(null)):eg({objectName:e,entryId:t})},[]),tz=(0,o.useCallback)(()=>{eg(null)},[]),tU=(0,o.useCallback)(e=>{let t=eB.current.activeContentId;t&&eP({type:"updateContentMeta",id:t,meta:{profileTab:e}})},[]),tH=(0,o.useCallback)(()=>({resolveKind:e=>{let t=hA(x,e);if(t)return hD(t.type,t.path);if(e.startsWith("~crm/")){let t=e.slice(5).split("/")[0];if("people"===t||"companies"===t)return"object"}return null}}),[x]);(0,o.useEffect)(()=>{if("hydrated"!==i.current)return;if(c.current){c.current=!1;return}let e=function(e,t){let r=dQ(e),n={};if(r){var o,l;if("crm-person"===r.kind&&(null==(o=r.meta)?void 0:o.entryId)?(n.entry={objectName:"people",entryId:r.meta.entryId},r.meta.profileTab&&"overview"!==r.meta.profileTab&&(n.profileTab=r.meta.profileTab)):"crm-company"===r.kind&&(null==(l=r.meta)?void 0:l.entryId)?(n.entry={objectName:"company",entryId:r.meta.entryId},r.meta.profileTab&&"overview"!==r.meta.profileTab&&(n.profileTab=r.meta.profileTab)):n.path=r.path,t.entryModal&&(n.entry=t.entryModal),"cron-dashboard"===r.kind?("overview"!==t.cron.view&&(n.cronView=t.cron.view),"calendar"===t.cron.view&&"month"!==t.cron.calMode&&(n.cronCalMode=t.cron.calMode),("calendar"===t.cron.view||"timeline"===t.cron.view)&&t.cron.date&&(n.cronDate=t.cron.date)):"cron-job"===r.kind&&("all"!==t.cron.runFilter&&(n.cronRunFilter=t.cron.runFilter),null!=t.cron.run&&(n.cronRun=t.cron.run)),t.objectViewParams){let e=t.objectViewParams;e.viewType&&(n.viewType=e.viewType),e.view&&(n.view=e.view),e.filters&&(n.filters=e.filters),e.search&&(n.search=e.search),e.sort&&(n.sort=e.sort),null!=e.page&&(n.page=e.page),null!=e.pageSize&&(n.pageSize=e.pageSize),e.cols&&(n.cols=e.cols)}}else t.chatSessionId&&(n.chat=t.chatSessionId,t.chatSubagentKey&&(n.subagent=t.chatSubagentKey));return t.browseDir&&(n.browse=t.browseDir),t.showHidden&&(n.hidden=!0),t.terminalOpen&&(n.terminal=!0),n}(eF,{chatSessionId:A,chatSubagentKey:X,entryModal:ev,browseDir:b,showHidden:S,terminalOpen:eI,cron:{view:es,calMode:ec,date:eu,runFilter:eh,run:ex}}),t=new URLSearchParams(window.location.search),r=(0,rt.M4)(e,t),n=(0,rt.bg)(r);n!==t.toString()&&s.push(n?"/?".concat(n):"/",{scroll:!1})},[eF,A,X,ev,b,S,eI,es,ec,eu,eh,ex,s]),(0,o.useEffect)(()=>{if("init"!==i.current||f||0===x.length||eW.current!==(C||null))return;let e=(0,rt.yh)(a);eP({type:"applyUrl",url:e,shell:tH()}),e.path||e.crm||e.entry||!e.chat||(e.subagent?eG({sessionKey:e.subagent,parentSessionId:e.chat,title:"Subagent"}):eq(e.chat)),e.entry&&"people"!==e.entry.objectName&&"company"!==e.entry.objectName&&"companies"!==e.entry.objectName&&eg(e.entry),e.browse&&j(e.browse),e.hidden&&T(!0),e.terminal&&e_(!0),e.cronView&&ei(e.cronView),e.cronCalMode&&ed(e.cronCalMode),e.cronDate&&ep(e.cronDate),e.cronRunFilter&&em(e.cronRunFilter),null!=e.cronRun&&ef(e.cronRun),c.current=!0,i.current="hydrated"},[x,f,a,C]),(0,o.useEffect)(()=>{let e=()=>{let e=(0,rt.yh)(window.location.search);eP({type:"applyUrl",url:e,shell:tH()}),e.path||e.crm||e.entry||!e.chat||(e.subagent?eG({sessionKey:e.subagent,parentSessionId:e.chat,title:"Subagent"}):eq(e.chat)),e.entry&&"people"!==e.entry.objectName&&"company"!==e.entry.objectName&&"companies"!==e.entry.objectName?eg(e.entry):eg(null),e.browse?j(e.browse):e.path&&(0,Z.Z1)(e.path)||j(null),T(!!e.hidden),e_(!!e.terminal),e.cronView&&ei(e.cronView),e.cronCalMode&&ed(e.cronCalMode),e.cronDate&&ep(e.cronDate),e.cronRunFilter&&em(e.cronRunFilter),null!=e.cronRun&&ef(e.cronRun)};return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[tH,eq,eG,j,T]),(0,o.useEffect)(()=>{let e=a.get("send");if(!e)return;let t=new URLSearchParams(window.location.search);t.delete("send");let r=t.toString();s.replace(r?"/?".concat(r):"/",{scroll:!1}),e2(eK().id,e)},[eK,a,s,e2]),(0,o.useCallback)((e,t)=>{if((0,Z.Z1)(t))return e;let r=hA(x,t);return(null==r?void 0:r.type)==="object"?(0,M.PV)(e):e},[x]),(0,o.useCallback)(e=>{if(!e)return void eP({type:"activateContent",id:null});if((0,Z.Z1)(e)){let t=e.split("/").pop()||e;j(e),eP({type:"openContent",tab:{id:dK("browse",e,{browsePath:e}),kind:"browse",path:e,title:t,meta:{browsePath:e},preview:!0}});return}let t=hA(x,e);t&&tC(t)},[x,tC,j]);let tV=(0,o.useCallback)(e=>{let t=function t(r){for(let n of r){if("object"===n.type&&hI(n.path)===e)return n;if(n.children){let e=t(n.children);if(e)return e}}return null}(x);t&&(tb(),tC(t))},[x,tC,tb]),tK=(0,o.useCallback)(e=>{let t=(0,rt.lc)(e);if(t){if("entry"===t.kind)return void tW(t.objectName,t.entryId);let e=hA(x,t.path);if(e)return void tC(e)}let r=hA(x,e);r&&tC(r)},[x,tC,tW]),tJ=(0,o.useRef)(()=>{}),tq=(0,o.useCallback)(async()=>{tJ.current()},[]),tG=(0,o.useCallback)(e=>{tJ.current=e},[]),t$=(0,o.useRef)(x);(0,o.useEffect)(()=>{t$.current!==x&&(t$.current=x,(null==eO?void 0:eO.kind)==="object"&&tJ.current())},[x,null==eO?void 0:eO.kind]);let tY=(0,o.useCallback)(e=>{let t=e.target.closest("a");if(!t)return;let r=t.getAttribute("href");r&&(0,rt.m9)(r)&&(e.preventDefault(),e.stopPropagation(),tK(r))},[tK]),tZ=(0,o.useCallback)(e=>{let t="~cron/".concat(e);eP({type:"openContent",tab:{id:dK("cron-job",t,{cronJobId:e}),kind:"cron-job",path:t,title:e,meta:{cronJobId:e},preview:!0}})},[]),tQ=(0,o.useCallback)(()=>{eP({type:"openContent",tab:{id:"~cron",kind:"cron-dashboard",path:"~cron",title:"Cron",preview:!0}}),em("all"),ef(null)},[]),tX=(0,o.useCallback)(e=>{e2(eK().id,e)},[eK,e2]),t0=(0,o.useMemo)(()=>{if(!A)return;let e=B.find(e=>e.id===A);return(null==e?void 0:e.title)||void 0},[A,B]);(0,o.useEffect)(()=>{eP({type:"syncChatTitles",sessions:B,subagents:Y})},[B,Y]),(0,o.useEffect)(()=>{if(!t0||!eU)return;let e=eB.current.chatTabs.find(e=>e.id===eU);e&&"subagent"!==e.variant&&e.title!==t0&&eP({type:"renameChat",id:e.id,title:t0})},[t0,eU]);let t1=(0,o.useMemo)(()=>new Set(Y.filter(e=>"running"===e.status).map(e=>e.childSessionKey)),[Y]);(0,o.useMemo)(()=>{let e=new Set;for(let t of eH){let r=J[t.id];if((null==r?void 0:r.isStreaming)||t.sessionKey&&(t1.has(t.sessionKey)||"running"===G.subagentStatuses.get(t.sessionKey))){e.add(t.id);continue}t.sessionId&&V.has(t.sessionId)&&e.add(t.id)}return e},[G.subagentStatuses,J,eH,t1,V]);let t2=(0,o.useCallback)(e=>{K(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),r}),Q(t=>t.map(t=>t.parentSessionId===e&&"running"===t.status?{...t,status:"completed"}:t)),q(t=>{let r={};for(let[n,o]of Object.entries(t))r[n]=o.sessionId===e?{...o,isStreaming:!1,isReconnecting:!1,status:"ready"}:o;return r})},[]),t4=(0,o.useCallback)(e=>{Q(t=>t.map(t=>t.childSessionKey===e&&"running"===t.status?{...t,status:"completed"}:t)),q(t=>{let r={};for(let[n,o]of Object.entries(t))r[n]=o.sessionKey===e?{...o,isStreaming:!1,isReconnecting:!1,status:"ready"}:o;return r})},[]),t5=(0,o.useCallback)(async e=>{t2(e);try{await fetch("/api/chat/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:e,cascadeChildren:!0})})}catch(e){}},[t2]),t3=(0,o.useCallback)(async e=>{t4(e);try{await fetch("/api/chat/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionKey:e})})}catch(e){}},[t4]);(0,o.useCallback)(e=>{let t=eB.current.chatTabs.find(t=>t.id===e);if(t){if(t.sessionKey)return void t3(t.sessionKey);t.sessionId&&t5(t.sessionId)}},[t5,t3]);let t6=(0,o.useCallback)(e=>{tg(),eP({type:"activateContent",id:e})},[tg]),t8=(0,o.useCallback)(e=>{eP({type:"closeContent",id:e})},[]),t7=(0,o.useMemo)(()=>(function(e){let t=new Map;return!function e(r){for(let n of r){if("object"===n.type){let e=hI(n.path);h_.has(e)||t.has(e)||t.set(e,{name:e,icon:n.icon,defaultView:n.defaultView})}n.children&&e(n.children)}}(e),[...t.values()].toSorted((e,t)=>e.name.localeCompare(t.name))})(tR),[tR]),t9={activePath:null,orgName:null==E||null==(e=E.organization)?void 0:e.name,browseDir:b,onFileSearchSelect:tB,searchFn:R,workspaceRoot:w,onGoToChat:tF,activeWorkspace:C,onWorkspaceChanged:tm,activeCrmTarget:(null==eO?void 0:eO.kind)==="crm-person"||(null==eO?void 0:eO.kind)==="object"&&"people"===eO.path?"people":(null==eO?void 0:eO.kind)==="crm-company"||(null==eO?void 0:eO.kind)==="object"&&("company"===eO.path||"companies"===eO.path)?"companies":(null==eO?void 0:eO.kind)==="crm-inbox"?"inbox":(null==eO?void 0:eO.kind)==="crm-calendar"?"calendar":null,customCrmObjects:t7,activeCrmObjectName:(null==eO?void 0:eO.kind)==="object"?eO.path:null,onNavigateToCrmObject:tV,onNewChatSession:()=>eJ(),chatsPanel:(0,n.jsx)(hg,{embedded:!0,sessions:B,activeSessionId:A,streamingSessionIds:V,subagents:Y,activeSubagentKey:X,loading:O,gatewaySessions:et,activeGatewaySessionKey:en,onSelectSession:e=>{let t=B.find(t=>t.id===e);eq(e,null==t?void 0:t.title)},onNewSession:()=>eJ(),onSelectSubagent:e5,onSelectGatewaySession:(e,t)=>{let r=et.find(t=>t.sessionKey===e);e$(e,t,null==r?void 0:r.channel,null==r?void 0:r.title)},onRenameSession:tf,onDeleteSession:tx})},re={historySessions:B,historyStreamingSessionIds:V,historySubagents:Y,historyActiveSubagentKey:X,historyLoading:O,historyGatewaySessions:et,historyActiveGatewaySessionKey:en,onSelectHistorySession:e=>{let t=B.find(t=>t.id===e);eq(e,null==t?void 0:t.title)},onNewChatSession:()=>{eJ()},onSelectHistorySubagent:e5,onSelectHistoryGatewaySession:(e,t)=>{let r=et.find(t=>t.sessionKey===e);e$(e,t,null==r?void 0:r.channel,null==r?void 0:r.title)},onRenameHistorySession:tf,onDeleteHistorySession:tx},rr=(0,o.useCallback)(e=>(0,n.jsx)(dz,{objectName:e.objectName,entryId:e.entryId,members:null==E?void 0:E.members,tree:x,searchFn:R,onClose:tz,onNavigateEntry:(e,t,r)=>tW(e,t,r),onNavigateObject:e=>{tz(),tV(e)},onRefresh:tq,onNavigate:tK}),[null==E?void 0:E.members,x,R,tz,tW,tV,tq,tK]),rn=(0,o.useCallback)((e,t)=>(0,n.jsx)(hB,{content:e,workspaceExists:v,expectedPath:w,tree:x,activePath:ez,browseDir:b,treeLoading:f,members:null==E?void 0:E.members,onNodeSelect:tC,onNavigateToObject:tV,onRefreshObject:tq,onRefreshTree:g,onNavigate:tK,onOpenEntry:tW,activeEntryId:void 0,searchFn:R,onSelectCronJob:tZ,onBackToCronDashboard:tQ,cronView:es,onCronViewChange:ei,cronCalMode:ec,onCronCalModeChange:ed,cronDate:eu,onCronDateChange:ep,cronRunFilter:eh,onCronRunFilterChange:em,cronRun:ex,onCronRunChange:ef,onSendCommand:tX,onMakeTabPermanent:eZ,onTableSelectionContextChange:eA,onProfileTabChange:tU}),[v,w,x,ez,b,f,null==E?void 0:E.members,tC,tV,tq,g,tK,tW,R,tZ,tQ,es,ec,eu,eh,ex,tX,eZ,eA,tU]),ro=(0,o.useCallback)(()=>(0,n.jsx)("p",{className:"text-sm text-center px-6 max-w-xs",style:{color:"var(--color-text-muted)"},children:"Select a file or open a page from the sidebar"}),[]);return(0,n.jsxs)("div",{ref:p,className:"flex h-screen",style:{background:"var(--color-main-bg)"},onClick:tY,children:[ey?eb&&(0,n.jsx)(F,{...t9,tree:x,onSelect:e=>{tC(e),ej(!1)},onRefresh:g,loading:f,parentDir:tE,onNavigateUp:tD,onGoHome:tA,onExternalDrop:tP,showHidden:S,onToggleHidden:()=>T(e=>!e),onNavigate:e=>{tj(e),ej(!1)},mobile:!0,onClose:()=>ej(!1)}):(0,n.jsx)("div",{className:"sidebar-animate flex shrink-0 flex-col relative z-10 overflow-hidden",style:{width:ek?0:e8,minWidth:ek?0:e8,transition:"width 200ms ease, min-width 200ms ease"},children:(0,n.jsxs)("div",{className:"flex flex-col h-full relative",style:{width:e8,minWidth:e8},children:[(0,n.jsx)(hT,{mode:"left",containerRef:p,min:56,max:480,onResize:ta}),(0,n.jsx)(F,{...t9,tree:x,onSelect:tC,onRefresh:g,loading:f,parentDir:tE,onNavigateUp:tD,onGoHome:tA,onExternalDrop:tP,showHidden:S,onToggleHidden:()=>T(e=>!e),width:e8,compact:tt,onToggleCompact:ts,onCollapse:()=>ew(!0),onNavigate:tj})]})}),(0,n.jsxs)("main",{className:"flex-1 flex flex-col min-w-[300px] overflow-hidden relative",style:{background:"var(--color-main-bg)"},children:[ey&&(0,n.jsxs)("div",{className:"px-2 py-1.5 border-b flex-shrink-0 flex items-center gap-1.5",style:{borderColor:"var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>ej(!0),className:"p-1.5 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:t0||(null==E||null==(t=E.organization)?void 0:t.name)||"Chat"}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{type:"button",onClick:()=>eM(!0),className:"p-1.5 rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)"},title:"Open files & content",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:"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)("button",{type:"button",onClick:()=>e_(e=>!e),className:"p-1.5 rounded-lg flex-shrink-0",style:{color:eI?"var(--color-text)":"var(--color-text-muted)",background:eI?"var(--color-surface-hover)":"transparent"},title:"Terminal",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)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",x2:"20",y1:"19",y2:"19"})]})}),(0,n.jsx)("button",{type:"button",onClick:()=>eJ(),className:"p-1.5 rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)"},title:"New 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 5v14"}),(0,n.jsx)("path",{d:"M5 12h14"})]})})]})]}),(0,n.jsx)("div",{className:"flex-1 flex min-h-0 min-w-0 flex-col overflow-hidden",style:{background:"var(--color-main-bg)"},children:eH.map(e=>{var t,r;let o="gateway"===e.variant,l=!o&&e.sessionKey?Y.find(t=>t.childSessionKey===e.sessionKey):null,a=e.id===eQ,s=!ey&&ek,i=!ey&&eN,c=s?(0,n.jsx)("button",{type:"button",onClick:()=>ew(!1),className:"p-1.5 rounded-md transition-colors cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Show sidebar (⌘B)",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)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M9 3v18"})]})}):void 0,d=i?(0,n.jsx)("button",{type:"button",onClick:()=>eC(!1),className:"p-1.5 rounded-md transition-colors cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Show right panel (⌘⇧B)",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)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,n.jsx)("path",{d:"M15 3v18"})]})}):void 0;return(0,n.jsx)("div",{className:a?"flex-1 flex min-h-0 min-w-0 flex-col overflow-hidden":"hidden",children:(0,n.jsx)(dN,{ref:t=>eX(e.id,t),sessionTitle:e.title,initialSessionId:o||e.sessionKey?void 0:null!=(t=e.sessionId)?t:void 0,onActiveSessionChange:o||e.sessionKey?void 0:t=>e1(e.id,t),onSessionsChange:o?void 0:tp,onConversationActivity:()=>eY(e.id),onSubagentClick:e4,onFilePathClick:tI,onComposioAction:tk,onDeleteSession:o||e.sessionKey?void 0:tx,onRenameSession:o||e.sessionKey?void 0:tf,compact:ey,sessionKey:o?void 0:null!=(r=e.sessionKey)?r:void 0,subagentTask:null==l?void 0:l.task,subagentLabel:null==l?void 0:l.label,onBack:e.sessionKey&&!o?e3:void 0,hideHeaderActions:!1,headerLeftSlot:c,headerRightSlot:d,onRuntimeStateChange:t=>e0(e.id,t),onOpenCloudSettings:()=>tj("cloud"),gatewaySessionKey:o?e.sessionKey:void 0,gatewaySessionId:o?e.sessionId:void 0,gatewayChannel:o?e.channel:void 0,visible:a,searchFn:R,fileContext:a?ti:void 0,onFileChanged:tc,...re})},e.id)})}),(0,n.jsx)(u5,{request:eR,onRequestHandled:tw,onFallbackToIntegrations:tN}),eI&&(0,n.jsx)(hk,{onClose:()=>e_(!1),cwd:null!=w?w:void 0})]}),!ey&&(0,n.jsx)("aside",{className:"sidebar-animate flex-shrink-0 min-h-0 flex flex-col relative ".concat(eN?"overflow-hidden":"border-l overflow-hidden"),style:{width:tl,minWidth:tl,borderColor:"var(--color-border)",background:"var(--color-bg)",transition:"width 200ms ease, min-width 200ms ease"},children:(0,n.jsxs)("div",{className:"flex h-full min-h-0 flex-col relative overflow-hidden",style:{width:to,minWidth:to},children:[(0,n.jsx)(hT,{mode:"right",containerRef:p,min:360,max:tn,onResize:te}),(0,n.jsx)(hy,{children:(0,n.jsx)(tO,{tabsState:eF,activeContentTab:eO,fileTreeCollapsed:eT,enhancedTree:x,effectiveParentDir:tE,browseDir:b,workspaceRoot:w,fileSearchFn:R,entryModal:ev,tree:x,cronJobs:el,onTreeNodeSelect:tC,onTreeRefresh:g,onTreeNavigateUp:tD,onTreeExternalDrop:tP,onTreeFileSearchSelect:tB,onTreeGoHome:tA,onSetFileTreeCollapsed:eL,onSetRightPanelCollapsed:eC,onActivateContent:t6,onCloseContent:t8,onCloseOtherContent:tM,onCloseContentToRight:tT,onCloseAllContent:tL,onDuckDBMissing:ty,onRefreshActiveChange:tG,renderContent:rn,renderEntryDetail:rr,renderPlaceholder:ro})})]})}),ey&&eS&&(0,n.jsx)("div",{className:"drawer-backdrop",onClick:()=>eM(!1),children:(0,n.jsx)("div",{onClick:e=>e.stopPropagation(),className:"fixed inset-y-0 right-0 z-50 drawer-right",style:{width:"min(90vw, 400px)",background:"var(--color-bg)"},children:(0,n.jsx)("div",{className:"flex flex-col h-full",children:(0,n.jsx)(hy,{children:(0,n.jsx)(tO,{tabsState:eF,activeContentTab:eO,fileTreeCollapsed:eT,enhancedTree:x,effectiveParentDir:tE,browseDir:b,workspaceRoot:w,fileSearchFn:R,entryModal:ev,tree:x,cronJobs:el,onTreeNodeSelect:tC,onTreeRefresh:g,onTreeNavigateUp:tD,onTreeFileSearchSelect:tB,onTreeGoHome:tA,onSetFileTreeCollapsed:eL,onSetRightPanelCollapsed:()=>eM(!1),onActivateContent:t6,onCloseContent:t8,onCloseOtherContent:tM,onCloseContentToRight:tT,onCloseAllContent:tL,onDuckDBMissing:ty,onRefreshActiveChange:tG,renderContent:rn,renderEntryDetail:rr,renderPlaceholder:ro})})})})})]})}function hB(e){let{content:t,workspaceExists:r,expectedPath:o,tree:l,activePath:a,browseDir:s,treeLoading:i,members:c,onNodeSelect:d,onNavigateToObject:u,onRefreshObject:p,onRefreshTree:h,onNavigate:m,onOpenEntry:x,activeEntryId:f,searchFn:v,onSelectCronJob:g,onBackToCronDashboard:y,cronView:b,onCronViewChange:j,cronCalMode:k,onCronCalModeChange:w,cronDate:N,onCronDateChange:C,cronRunFilter:S,onCronRunFilterChange:M,cronRun:T,onCronRunChange:L,onSendCommand:I,onMakeTabPermanent:_,onTableSelectionContextChange:R,onProfileTabChange:E}=e;switch(t.kind){case"loading":return(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)(da.V,{name:"braille",className:"text-2xl",style:{color:"var(--color-text-muted)"}})});case"object":return(0,n.jsx)(hW,{data:t.data,members:c,onNavigateToObject:u,onRefreshObject:p,onRefreshTree:h,onOpenEntry:x,activeEntryId:f,onSelectionContextChange:R},t.data.object.name);case"document":return(0,n.jsx)(lb,{content:t.data.content,title:t.title,filePath:null!=a?a:void 0,tree:l,onSave:h,onNavigate:m,searchFn:v,onDirty:a?()=>_(a):void 0});case"file":return(0,n.jsx)(tu,{content:t.data.content,filename:t.filename,type:"yaml"===t.data.type?"yaml":"text"});case"code":return(0,n.jsx)(l0,{content:t.data.content,filename:t.filename,filePath:t.filePath,onDirty:t.filePath?()=>_(t.filePath):void 0});case"media":return(0,n.jsx)(tN,{url:t.url,filename:t.filename,mediaType:t.mediaType,filePath:t.filePath});case"spreadsheet":return(0,n.jsx)(l_,{url:t.url,filename:t.filename,filePath:t.filePath,onDirty:()=>_(t.filePath)});case"html":return(0,n.jsx)(lA,{rawUrl:t.rawUrl,contentUrl:t.contentUrl,filename:t.filename});case"app":return(0,n.jsx)(lJ,{appPath:t.appPath,manifest:t.manifest});case"database":return(0,n.jsx)(ar,{dbPath:t.dbPath,filename:t.filename});case"report":return(0,n.jsx)(ag,{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)(da.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)(hO,{node:r,onNodeSelect:d})}case"cron-dashboard":return(0,n.jsx)(uo,{onSelectJob:g,onSendCommand:I,activeView:b,onViewChange:j,calendarMode:k,onCalendarModeChange:w,calendarDate:N,onCalendarDateChange:C});case"skill-store":return(0,n.jsx)("div",{className:"h-full overflow-y-auto",children:(0,n.jsx)("div",{className:"mx-auto max-w-5xl p-6",children:(0,n.jsx)(uW,{})})});case"integrations":return(0,n.jsx)("div",{className:"h-full overflow-y-auto",children:(0,n.jsx)("div",{className:"mx-auto max-w-5xl p-6",children:(0,n.jsx)(u2,{})})});case"cloud":return(0,n.jsx)("div",{className:"h-full overflow-y-auto",children:(0,n.jsxs)("div",{className:"mx-auto max-w-5xl p-6",children:[(0,n.jsxs)("div",{className:"mb-6",children:[(0,n.jsx)("h1",{className:"font-instrument text-3xl tracking-tight",style:{color:"var(--color-text)"},children:"Cloud"}),(0,n.jsx)("p",{className:"mt-1 text-sm",style:{color:"var(--color-text-muted)"},children:"Manage your Dench Cloud connection and model settings."})]}),(0,n.jsx)(pP,{})]})});case"cron-job":return(0,n.jsx)(pU,{job:t.job,onBack:y,onSendCommand:I,runFilter:S,onRunFilterChange:M,expandedRunTs:T,onExpandedRunChange:L});case"cron-session":return(0,n.jsx)(pY,{job:t.job,run:t.run,sessionId:t.sessionId,onBack:()=>y(),onBackToJob:()=>g(t.jobId)});case"duckdb-missing":return(0,n.jsx)(at,{});case"richDocument":return(0,n.jsx)(e$,{mode:t.mode,initialHtml:t.html,filePath:t.filePath,onSave:h,onDirty:()=>_(t.filePath)});case"crm-inbox":return(0,n.jsx)(so,{onOpenPerson:e=>x("people",e)});case"crm-calendar":return(0,n.jsx)(sC,{onOpenPerson:e=>x("people",e),onOpenCompany:e=>x("company",e)});case"crm-person":return(0,n.jsx)(sH,{personId:t.entryId,activeTab:t.profileTab,onOpenPerson:e=>x("people",e),onOpenCompany:e=>x("company",e),onBackToList:()=>u("people"),onTabChange:E});case"crm-company":return(0,n.jsx)(sX,{companyId:t.entryId,activeTab:t.profileTab,onOpenPerson:e=>x("people",e),onOpenCompany:e=>x("company",e),onBackToList:()=>u("company"),onTabChange:E});default:if(0===l.length)return(0,n.jsx)(as,{workspaceExists:r,expectedPath:o});return(0,n.jsx)(hz,{tree:l,onNodeSelect:d})}}function hW(e){var t,r,a,s,i,c,d,u,p,h,m,x,f,v,g,y,b;let{data:j,members:k,onNavigateToObject:w,onRefreshObject:N,onRefreshTree:C,onOpenEntry:S,activeEntryId:T,onSelectionContextChange:L}=e,I=(0,l.useSearchParams)(),_=(0,l.useRouter)(),R=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):""},[E,D]=(0,o.useState)(!1),A=(0,o.useMemo)(()=>{var e,t,r,n,o,l,a,s;let i=(0,rt.yh)(I);return{view:null!=(e=i.view)?e:void 0,viewType:null!=(t=i.viewType)?t:void 0,filters:null!=(r=i.filters)?r:void 0,search:null!=(n=i.search)?n:void 0,sort:null!=(o=i.sort)?o:void 0,page:null!=(l=i.page)?l:void 0,pageSize:null!=(a=i.pageSize)?a:void 0,cols:null!=(s=i.cols)?s:void 0}},[j.object.name]),[F,P]=(0,o.useState)(()=>{var e;return null!=(e=A.viewType)?e:oF(void 0,void 0,j.object.default_view)}),[B,W]=(0,o.useState)(()=>{var e;return null!=(e=j.viewSettings)?e:{}}),[O,z]=(0,o.useState)(()=>{var e;return null!=(e=A.filters)?e:o$()}),[U,H]=(0,o.useState)(null!=(t=j.savedViews)?t:[]),[V,K]=(0,o.useState)(null!=(r=A.view)?r:j.activeView),[J,q]=(0,o.useState)(null!=(s=null!=(a=A.page)?a:j.page)?s:1),[G,$]=(0,o.useState)(null!=(c=null!=(i=A.pageSize)?i:j.pageSize)?c:100),[Y,Z]=(0,o.useState)(null!=(d=j.totalCount)?d:j.entries.length),[Q,X]=(0,o.useState)(j.entries),[ee,et]=(0,o.useState)(null!=(u=A.search)?u:""),[er,en]=(0,o.useState)(null!=(p=A.sort)?p:void 0),eo=(0,o.useRef)(null),el=O.rules.length>0||(null!=(h=null==er?void 0:er.length)?h:0)>0||ee.trim().length>0,[ea,es]=(0,o.useState)(null!=(m=A.cols)?m:void 0),ei=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e=function(e,t,r){if(null===t){let t=new Set;for(let e of r)t.add(e.id);return{nextViewColumns:e,nextSeen:t}}let n=new Set(t),o=[];for(let e of r)n.has(e.id)||(n.add(e.id),o.push(e.name));if(0===o.length||!e||0===e.length)return{nextViewColumns:e,nextSeen:n};let l=new Set(e),a=[];for(let e of o)l.has(e)||(l.add(e),a.push(e));return 0===a.length?{nextViewColumns:e,nextSeen:n}:{nextViewColumns:[...e,...a],nextSeen:n}}(ea,ei.current,j.fields);ei.current=e.nextSeen,e.nextViewColumns!==ea&&es(e.nextViewColumns)},[j.fields,ea]);let[ec,ed]=(0,o.useState)(()=>{var e;return null==(e=j.viewSettings)?void 0:e.column_widths}),[eu,ep]=(0,o.useState)(null!=(x=A.search)?x:""),[eh,em]=(0,o.useState)(!0),[ex,ef]=(0,o.useState)(!1),ev=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(!ev.current){ev.current=!0;return}let e=oF(void 0,void 0,j.object.default_view),t=new URLSearchParams(window.location.search),r=(e,r)=>{null==r||""===r?t.delete(e):t.set(e,r)};r("viewType",F!==e?F:null),r("view",V&&V!==j.activeView?V:null),r("filters",O.rules.length>0?btoa(JSON.stringify(O)):null),r("search",ee||null),r("sort",er&&er.length>0?btoa(JSON.stringify(er)):null),r("page",J>1?String(J):null),r("pageSize",100!==G?String(G):null),r("cols",ea&&ea.length>0?ea.join(","):null);let n=t.toString();n!==window.location.search.replace(/^\?/,"")&&_.replace(n?"/?".concat(n):"/",{scroll:!1})},[F,V,O,ee,er,J,G,ea]);let eg=(0,o.useMemo)(()=>{let e={};if(ea&&ea.length>0){for(let t of j.fields)e[t.id]=ea.includes(t.name);e.created_at=ea.includes("created_at"),e.updated_at=ea.includes("updated_at")}if(hE.has(j.object.name)&&j.reverseRelations)for(let t of j.reverseRelations)hR.has(t.sourceObjectName)&&(e["rev_".concat(t.sourceObjectName,"_").concat(t.fieldName)]=!1);return 0===Object.keys(e).length?void 0:e},[ea,j.fields,j.reverseRelations,j.object.name]),ey=(0,o.useCallback)(e=>{let t=[];for(let r of j.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"),es(t.length>0?t:void 0)},[j.fields]),eb=(0,o.useMemo)(()=>{if(!ec)return;let e={};for(let t of j.fields)null!=ec[t.name]&&(e[t.id]=ec[t.name]);return null!=ec.created_at&&(e.created_at=ec.created_at),null!=ec.updated_at&&(e.updated_at=ec.updated_at),Object.keys(e).length>0?e:void 0},[ec,j.fields]),ej=(0,o.useCallback)(e=>{let t={};for(let r of j.fields)null!=e[r.id]&&(t[r.name]=Math.round(e[r.id]));null!=e.created_at&&(t.created_at=Math.round(e.created_at)),null!=e.updated_at&&(t.updated_at=Math.round(e.updated_at));let r=Object.keys(t).length>0?t:void 0;ed(r);let n={...B,column_widths:r};fetch("/api/workspace/objects/".concat(encodeURIComponent(j.object.name),"/views"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({views:U,activeView:V,viewSettings:n})}).catch(()=>{})},[j.fields,j.object.name,B,U,V]),ek=(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:J,d=null!=(r=null==e?void 0:e.pageSize)?r:G,u=null!=(n=null==e?void 0:e.filters)?n:O,p=null!=(o=null==e?void 0:e.sort)?o:er,h=null!=(l=null==e?void 0:e.search)?l:ee,m=new URLSearchParams;m.set("page",String(c)),m.set("pageSize",String(d)),u&&u.rules.length>0&&m.set("filters",oG(u)),p&&p.length>0&&m.set("sort",JSON.stringify(p)),h&&m.set("search",h);try{let e=await fetch("/api/workspace/objects/".concat(encodeURIComponent(j.object.name),"?").concat(m.toString()));if(!e.ok)return;let t=await e.json();X(t.entries),Z(null!=(a=t.totalCount)?a:t.entries.length),q(null!=(s=t.page)?s:c),$(null!=(i=t.pageSize)?i:d)}catch(e){}},[J,G,O,er,ee,j.object.name]);(0,o.useEffect)(()=>{var e;if(el)return void ek();X(j.entries),Z(null!=(e=j.totalCount)?e:j.entries.length)},[j.entries,j.totalCount]),(0,o.useEffect)(()=>{var e;H(null!=(e=j.savedViews)?e:[]),j.viewSettings&&W(j.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:o$(),i=a.columns,c=a.column_widths,d=a.name,u=a.view_type,p=a.settings,h=e.currentActiveViewName!==d,m=(n=e.currentFilters,oG(n)!==oG(s)),x=!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),f=e.currentViewType!==u,v=(o=e.currentSettings,(!!o||!!p)&&(!o||!p||JSON.stringify(o)!==JSON.stringify(p)));return{shouldApply:h||m||x||f||v,nextFilters:s,nextColumns:i,nextColumnWidths:c,nextActiveViewName:d,nextViewType:u,nextSettings:p}}({savedViews:j.savedViews,activeView:j.activeView,currentActiveViewName:V,currentFilters:O,currentViewColumns:ea,currentColumnWidths:ec,currentViewType:F,currentSettings:B});(null==t?void 0:t.shouldApply)&&(z(t.nextFilters),es(t.nextColumns),void 0!==t.nextColumnWidths&&ed(t.nextColumnWidths),K(t.nextActiveViewName),t.nextViewType&&P(t.nextViewType),t.nextSettings&&W(e=>({...e,...t.nextSettings})),ek({page:1,filters:t.nextFilters}))},[j.savedViews,j.activeView]);let ew=(0,o.useCallback)(e=>{z(e),q(1),ek({page:1,filters:e})},[ek]),eN=(0,o.useCallback)(e=>{et(e),eo.current&&clearTimeout(eo.current),eo.current=setTimeout(()=>{q(1),ek({page:1,search:e})},300)},[ek]),eC=(0,o.useCallback)(e=>{en(e.length>0?e:void 0),q(1),ek({page:1,sort:e})},[ek]),eS=(0,o.useCallback)(e=>{q(e),ek({page:e})},[ek]),eM=(0,o.useCallback)(e=>{$(e),q(1),ek({page:1,pageSize:e})},[ek]),eT=(0,o.useCallback)(()=>{ek(),N()},[ek,N]),eL=(0,o.useCallback)(e=>{null==S||S(j.object.name,e)},[S,j.object.name]),eI=S?eL:void 0,e_=(0,o.useCallback)(()=>{ef(!0)},[]),eR=(0,o.useMemo)(()=>({totalCount:Y,page:J,pageSize:G,onPageChange:eS,onPageSizeChange:eM}),[Y,J,G,eS,eM]),eE=(0,o.useCallback)(async e=>{let t=[...U.filter(t=>t.name!==e),{name:e,view_type:F,filters:O,columns:ea,column_widths:ec,settings:B}];H(t),K(e);try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(j.object.name),"/views"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({views:t,activeView:e,viewSettings:B})})}catch(e){}},[O,U,j.object.name,F,ea,ec,B]),eD=(0,o.useCallback)(e=>{var t;let r=null!=(t=e.filters)?t:o$();z(r),es(e.columns),ed(e.column_widths),K(e.name),e.view_type&&P(e.view_type),e.settings&&W(t=>({...t,...e.settings})),q(1),ek({page:1,filters:r})},[ek]),eA=(0,o.useCallback)(async e=>{let t=U.filter(t=>t.name!==e);H(t),V===e&&(K(void 0),z(o$()),es(void 0));try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(j.object.name),"/views"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({views:t,activeView:V===e?void 0:V})})}catch(e){}},[U,V,j.object.name]),eF=(0,o.useCallback)(async e=>{K(e),e||es(void 0);try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(j.object.name),"/views"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({views:U,activeView:e})})}catch(e){}},[U,j.object.name]),eP=(0,o.useCallback)(e=>{P(e)},[]),eB=(0,o.useCallback)(async e=>{W(e);try{await fetch("/api/workspace/objects/".concat(encodeURIComponent(j.object.name),"/views"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({views:U,activeView:V,viewSettings:e})})}catch(e){}},[U,V,j.object.name]),eW=(0,o.useMemo)(()=>{let e=U.find(e=>e.name===V),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,B),r=[...j.fields.map(e=>({name:e.name,type:e.type})),{name:"created_at",type:"date"},{name:"updated_at",type:"date"}];return"kanban"!==F||t.kanbanField||(t.kanbanField=oP("kanban","kanbanField",r)),"calendar"!==F||t.calendarDateField||(t.calendarDateField=oP("calendar","calendarDateField",r)),"timeline"!==F||t.timelineStartField||(t.timelineStartField=oP("timeline","timelineStartField",r)),"gallery"!==F||t.galleryTitleField||(t.galleryTitleField=oP("gallery","galleryTitleField",r)),"list"!==F||t.listTitleField||(t.listTitleField=oP("list","listTitleField",r)),t},[F,B,U,V,j.fields]),eO=async e=>{D(!0);try{(await fetch("/api/workspace/objects/".concat(encodeURIComponent(j.object.name),"/display-field"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({displayField:e})})).ok&&N()}catch(e){}finally{D(!1)}},ez=(0,o.useCallback)(async e=>{let t=eW.calendarDateField,r=eW.calendarEndDateField;if(!t)return;let n={[t]:e.newDate};r&&e.newEndDate&&(n[r]=e.newEndDate),X(n=>n.map(n=>{if(R(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(j.object.name),"/entries/").concat(encodeURIComponent(e.entryId)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:n})})}catch(e){}},[eW,j.object.name]),eU=(0,o.useCallback)(async e=>{let t=eW.timelineStartField,r=eW.timelineEndField;if(!t)return;let n={[t]:e.newStartDate};r&&(n[r]=e.newEndDate),X(n=>n.map(n=>{if(R(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(j.object.name),"/entries/").concat(encodeURIComponent(e.entryId)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:n})})}catch(e){}},[eW,j.object.name]),eH=j.fields.filter(e=>!["relation","boolean","richtext"].includes(e.type));j.fields.some(e=>"relation"===e.type),j.reverseRelations&&j.reverseRelations.some(e=>Object.keys(e.entries).length>0);let eV=(0,o.useMemo)(()=>null==k?void 0:k.map(e=>({id:e.id,name:e.name})),[k]),eK=(0,o.useMemo)(()=>[...j.fields,{id:"created_at",name:"created_at",type:"date"},{id:"updated_at",name:"updated_at",type:"date"}],[j.fields]);(0,o.useEffect)(()=>{ep(ee)},[ee]);let eJ=(0,o.useCallback)(e=>{ep(e),eN(e)},[eN]);return(0,n.jsxs)("div",{className:"flex flex-col h-full min-w-0 overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-4 py-1.5 flex flex-wrap items-center gap-x-3 gap-y-1.5 flex-shrink-0 min-w-0",style:{borderBottom:"1px solid var(--color-border)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 min-w-0 flex-shrink",children:[(0,n.jsx)(ll,{value:null!=(f=j.object.icon)?f:null,onChange:async e=>{try{if(!(await fetch("/api/workspace/objects/".concat(encodeURIComponent(j.object.name),"/icon"),{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({icon:e})})).ok)return}catch(e){return}N(),null==C||C()},title:"Change icon for ".concat((0,M.PV)(j.object.name))}),(0,n.jsx)("h1",{className:"text-sm font-semibold truncate",style:{color:"var(--color-text)"},title:j.object.description||(0,M.PV)(j.object.name),children:(0,M.PV)(j.object.name)}),(0,n.jsx)("span",{className:"text-[11px] tabular-nums px-1.5 py-0.5 rounded-full flex-shrink-0",style:{color:"var(--color-text-muted)",background:"var(--color-surface)",border:"1px solid var(--color-border)"},title:"".concat(Y.toLocaleString()," ").concat(1===Y?"entry":"entries"," \xb7 ").concat(j.fields.length," fields"),children:Y.toLocaleString()})]}),(0,n.jsx)(oQ,{value:F,onChange:eP}),(0,n.jsxs)("div",{className:"ml-auto flex min-w-0 max-w-full flex-[1_1_280px] flex-wrap items-center justify-end gap-1.5",children:[(0,n.jsxs)("div",{className:"flex min-w-[128px] max-w-[180px] flex-[1_1_150px] items-center gap-1.5 h-7 px-2 rounded-md focus-within:ring-2 focus-within:ring-(--color-accent)/30 transition-shadow",style:{border:"1px solid var(--color-border)",background:"var(--color-surface)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",style:{color:"var(--color-text-muted)",opacity:.6},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:eu,onChange:e=>eJ(e.target.value),placeholder:"Search ".concat((0,M.PV)(j.object.name),"..."),className:"w-full h-full text-[12px] bg-transparent outline-none border-0 p-0",style:{color:"var(--color-text)"}}),eu&&(0,n.jsx)("button",{type:"button",onClick:()=>eJ(""),className:"shrink-0 h-4 w-4 rounded-full flex items-center justify-center cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Clear search",children:(0,n.jsxs)("svg",{width:"10",height:"10",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"})]})})]}),(0,n.jsx)(hn,{fields:j.fields,filters:O,onFiltersChange:ew,savedViews:U,activeViewName:V,onSaveView:eE,onLoadView:eD,onDeleteView:eA,onSetActiveView:eF,members:eV}),(0,n.jsx)(lt,{viewType:F,settings:eW,fields:eK,onSettingsChange:eB,description:j.object.description,displayField:j.effectiveDisplayField,displayFieldCandidates:eH,onDisplayFieldChange:eO,updatingDisplayField:E,columnVisibility:eg,onColumnVisibilityChange:ey,stickyFirstColumn:eh,onStickyFirstColumnChange:em}),(0,n.jsx)("button",{type:"button",onClick:eT,className:"flex items-center justify-center w-7 h-7 rounded-md hover:bg-[var(--color-surface-hover)] transition-colors cursor-pointer",style:{color:"var(--color-text-muted)"},title:"Refresh","aria-label":"Refresh",children:(0,n.jsxs)("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:"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 21h5v-5"})]})}),(0,n.jsxs)("button",{type:"button",onClick:()=>ef(!0),className:"flex items-center gap-1 h-7 px-2.5 rounded-md text-[12px] font-medium cursor-pointer transition-colors",style:{background:"var(--color-accent)",color:"#fff"},title:"Add ".concat((0,M.A3)(j.object.name)),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:"M12 5v14"}),(0,n.jsx)("path",{d:"M5 12h14"})]}),(0,n.jsx)("span",{className:"hidden md:inline",children:"Add"})]})]})]}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-hidden",children:["kanban"===F&&(0,n.jsx)("div",{className:"h-full overflow-auto px-6 py-4",children:(0,n.jsx)(nO,{objectName:j.object.name,fields:j.fields,entries:Q,statuses:j.statuses,members:k,relationLabels:j.relationLabels,onEntryClick:eI,onRefresh:eT})}),"table"===F&&(0,n.jsx)(nR,{objectName:j.object.name,fields:j.fields,entries:Q,members:k,relationLabels:j.relationLabels,relationFaviconUrls:j.relationFaviconUrls,reverseRelations:j.reverseRelations,onNavigateToObject:w,onNavigateToEntry:S,onEntryClick:eI,onRefresh:eT,activeEntryId:T,columnVisibility:eg,onColumnVisibilityChanged:ey,columnSizing:eb,onColumnSizingChanged:ej,serverPagination:eR,onServerSearch:eN,onServerSort:eC,hideInternalToolbar:!0,globalFilter:eu,onGlobalFilterChange:eJ,stickyFirstColumnValue:eh,onStickyFirstColumnChange:em,onAddRequest:e_,onSelectionContextChange:L}),"calendar"===F&&(0,n.jsx)("div",{className:"h-full overflow-auto px-6 py-4",children:(0,n.jsx)(om,{objectName:j.object.name,fields:j.fields,entries:Q,dateField:null!=(v=eW.calendarDateField)?v:"",endDateField:eW.calendarEndDateField,mode:null!=(g=eW.calendarMode)?g:"month",onModeChange:e=>eB({...eW,calendarMode:e}),members:k,onEntryClick:eI,onEntryDateChange:ez})}),"timeline"===F&&(0,n.jsx)("div",{className:"h-full overflow-auto px-6 py-4",children:(0,n.jsx)(oC,{objectName:j.object.name,fields:j.fields,entries:Q,startDateField:null!=(y=eW.timelineStartField)?y:"",endDateField:eW.timelineEndField,groupField:eW.timelineGroupField,zoom:null!=(b=eW.timelineZoom)?b:"week",onZoomChange:e=>eB({...eW,timelineZoom:e}),members:k,onEntryClick:eI,onEntryDateChange:eU})}),"gallery"===F&&(0,n.jsx)("div",{className:"h-full overflow-auto px-6 py-4",children:(0,n.jsx)(oL,{objectName:j.object.name,fields:j.fields,entries:Q,titleField:eW.galleryTitleField,coverField:eW.galleryCoverField,members:k,relationLabels:j.relationLabels,onEntryClick:eI})}),"list"===F&&(0,n.jsx)("div",{className:"h-full overflow-auto px-6 py-4",children:(0,n.jsx)(oE,{objectName:j.object.name,fields:j.fields,entries:Q,titleField:eW.listTitleField,subtitleField:eW.listSubtitleField,members:k,onEntryClick:eI})})]}),ex&&(0,n.jsx)(nE,{objectName:j.object.name,fields:j.fields.filter(e=>"action"!==e.type),members:k,onClose:()=>ef(!1),onSaved:eT})]})}function hO(e){var t;let{node:r,onNodeSelect:o}=e,l=null!=(t=r.children)?t:[],a="object"===r.type?(0,M.PV)(r.name):r.name;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".concat("object"===r.type?"":" capitalize"),style:{color:"var(--color-text)"},children:a}),(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)(hU,{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:"object"===e.type?(0,M.PV)(e.name):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 hz(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)(hU,{type:"object"})}),(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:(0,M.PV)(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)(hU,{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 hU(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"})]})}}},68840:(e,t,r)=>{"use strict";r.d(t,{M4:()=>d,VE:()=>u,bJ:()=>p,bg:()=>c,lc:()=>h,m9:()=>m,yh:()=>i});let n=["table","kanban","calendar","timeline","gallery","list"],o=["overview","calendar","timeline","insights"],l=["day","week","month","year"],a=["all","ok","error","running"],s=["people","companies","inbox","calendar"];function i(e){let t="string"==typeof e?new URLSearchParams(e):e,r=null,i=t.get("entry");if(i&&i.includes(":")){let e=i.indexOf(":");r={objectName:i.slice(0,e),entryId:i.slice(e+1)}}let c=null,d=t.get("filters");if(d)try{c=JSON.parse(atob(d))}catch(e){}let u=null,p=t.get("sort");if(p)try{u=JSON.parse(atob(p))}catch(e){}let h=t.get("page"),m=t.get("pageSize"),x=t.get("cols"),f=t.get("viewType"),v=t.get("cronView"),g=t.get("cronCalMode"),y=t.get("cronRunFilter"),b=t.get("cronRun"),j=t.get("crm");return{path:t.get("path"),chat:t.get("chat"),subagent:t.get("subagent"),fileChat:t.get("fileChat"),entry:r,profileTab:t.get("profileTab"),send:t.get("send"),browse:t.get("browse"),hidden:"1"===t.get("hidden"),preview:t.get("preview"),view:t.get("view"),viewType:f&&n.includes(f)?f:null,filters:c,search:t.get("search"),sort:u,page:h&&parseInt(h,10)||null,pageSize:m&&parseInt(m,10)||null,cols:x?x.split(",").filter(Boolean):null,cronView:v&&o.includes(v)?v:null,cronCalMode:g&&l.includes(g)?g:null,cronDate:t.get("cronDate"),cronRunFilter:y&&a.includes(y)?y:null,cronRun:b&&parseInt(b,10)||null,terminal:"1"===t.get("terminal"),crm:j&&s.includes(j)?j:null,thread:t.get("thread")}}function c(e){let t=new URLSearchParams;return e.path&&t.set("path",e.path),e.chat&&t.set("chat",e.chat),e.subagent&&t.set("subagent",e.subagent),e.fileChat&&t.set("fileChat",e.fileChat),e.entry&&t.set("entry","".concat(e.entry.objectName,":").concat(e.entry.entryId)),e.profileTab&&t.set("profileTab",e.profileTab),e.send&&t.set("send",e.send),e.browse&&t.set("browse",e.browse),e.hidden&&t.set("hidden","1"),e.preview&&t.set("preview",e.preview),e.view&&t.set("view",e.view),e.viewType&&t.set("viewType",e.viewType),e.filters&&e.filters.rules.length>0&&t.set("filters",btoa(JSON.stringify(e.filters))),e.search&&t.set("search",e.search),e.sort&&e.sort.length>0&&t.set("sort",btoa(JSON.stringify(e.sort))),null!=e.page&&e.page>1&&t.set("page",String(e.page)),null!=e.pageSize&&t.set("pageSize",String(e.pageSize)),e.cols&&e.cols.length>0&&t.set("cols",e.cols.join(",")),e.cronView&&"overview"!==e.cronView&&t.set("cronView",e.cronView),e.cronCalMode&&t.set("cronCalMode",e.cronCalMode),e.cronDate&&t.set("cronDate",e.cronDate),e.cronRunFilter&&"all"!==e.cronRunFilter&&t.set("cronRunFilter",e.cronRunFilter),null!=e.cronRun&&t.set("cronRun",String(e.cronRun)),e.terminal&&t.set("terminal","1"),e.crm&&t.set("crm",e.crm),e.thread&&t.set("thread",e.thread),t.toString()}function d(e,t){let r="string"==typeof t?new URLSearchParams(t):t,n={...e};if(!e.path||e.path!==r.get("path"))return n;let o=i(r);return o.viewType&&(n.viewType=o.viewType),o.view&&(n.view=o.view),o.filters&&(n.filters=o.filters),o.search&&(n.search=o.search),o.sort&&(n.sort=o.sort),null!=o.page&&(n.page=o.page),null!=o.pageSize&&(n.pageSize=o.pageSize),o.cols&&(n.cols=o.cols),n}function u(e,t){return"/?entry=".concat(encodeURIComponent(e),":").concat(encodeURIComponent(t))}function p(e){return"/?path=".concat(encodeURIComponent(e))}function h(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 m(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})}},90425:(e,t,r)=>{"use strict";function n(e){return e.startsWith("~/")}function o(e){return e.startsWith("~")&&!n(e)}function l(e){return e.startsWith("/")}function a(e){return o(e)?"virtual":n(e)?"homeRelative":l(e)?"absolute":"workspaceRelative"}function s(e,t){return t?"/"===e?"/".concat(t):"".concat(e,"/").concat(t):e}function i(e,t){let r=a(e);return"absolute"===r||"homeRelative"===r?e:"workspaceRelative"===r?t?s(t,e):e:t?"~skills"===e?s(t,"skills"):e.startsWith("~skills/")?s(t,"skills/".concat(e.slice(8))):"~workspace"===e?t:e.startsWith("~workspace/")?s(t,e.slice(11)):e:e}function c(e){let t=a(e);return"virtual"===t?"/api/workspace/virtual-file?path=".concat(encodeURIComponent(e)):"absolute"===t||"homeRelative"===t?"/api/workspace/browse-file?path=".concat(encodeURIComponent(e)):"/api/workspace/file?path=".concat(encodeURIComponent(e))}function d(e){return!function(e){let t=a(e);return"absolute"===t||"homeRelative"===t}(e)?"/api/workspace/raw-file?path=".concat(encodeURIComponent(e)):"/api/workspace/browse-file?path=".concat(encodeURIComponent(e),"&raw=true")}function u(e){return"virtual"===a(e)?"/api/workspace/virtual-file":"/api/workspace/file"}r.d(t,{Bv:()=>a,L6:()=>o,Pv:()=>n,WW:()=>i,Z1:()=>l,kb:()=>c,nC:()=>u,oj:()=>d})}},e=>{e.O(0,[55700,6237,32830,35261,98438,62763,7073,81377,63040,42368,41791,21705,98522,77358],()=>e(e.s=10610)),_N_E=e.O()}]);