okengine 0.18.4 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (512) hide show
  1. package/AGENTS.md +18 -10
  2. package/README.md +2 -2
  3. package/package.json +51 -50
  4. package/site/content/docs/ai/index.mdx +25 -6
  5. package/site/content/docs/ai/llms-txt.mdx +1 -1
  6. package/site/content/docs/ai/meta.json +1 -1
  7. package/site/content/docs/ai/skills.mdx +4 -1
  8. package/site/content/docs/ai/try-it.mdx +58 -0
  9. package/site/content/docs/client/auth.mdx +208 -0
  10. package/site/content/docs/client/calling.mdx +451 -0
  11. package/site/content/docs/client/index.mdx +209 -0
  12. package/site/content/docs/client/live.mdx +234 -0
  13. package/site/content/docs/client/meta.json +5 -0
  14. package/site/content/docs/client/react.mdx +249 -0
  15. package/site/content/docs/elements/ai/agents.mdx +232 -0
  16. package/site/content/docs/elements/ai/index.mdx +341 -0
  17. package/site/content/docs/elements/ai/mcp.mdx +275 -0
  18. package/site/content/docs/elements/ai/meta.json +5 -0
  19. package/site/content/docs/elements/ai/models.mdx +283 -0
  20. package/site/content/docs/elements/ai/prompts.mdx +256 -0
  21. package/site/content/docs/elements/channel/email.mdx +266 -0
  22. package/site/content/docs/elements/channel/index.mdx +344 -0
  23. package/site/content/docs/elements/channel/meta.json +5 -0
  24. package/site/content/docs/elements/channel/push.mdx +218 -0
  25. package/site/content/docs/elements/channel/receipts.mdx +206 -0
  26. package/site/content/docs/elements/channel/sms.mdx +264 -0
  27. package/site/content/docs/elements/channel/whatsapp.mdx +220 -0
  28. package/site/content/docs/elements/clock/index.mdx +300 -0
  29. package/site/content/docs/elements/clock/meta.json +5 -0
  30. package/site/content/docs/elements/clock/schedules.mdx +508 -0
  31. package/site/content/docs/elements/clock/sleep.mdx +445 -0
  32. package/site/content/docs/elements/flow/consumers.mdx +707 -0
  33. package/site/content/docs/elements/flow/http.mdx +1080 -0
  34. package/site/content/docs/elements/flow/index.mdx +618 -0
  35. package/site/content/docs/elements/flow/meta.json +5 -0
  36. package/site/content/docs/elements/flow/routing.mdx +559 -0
  37. package/site/content/docs/elements/flow/workflows.mdx +640 -0
  38. package/site/content/docs/elements/gate/auth.mdx +371 -0
  39. package/site/content/docs/elements/gate/authorization.mdx +298 -0
  40. package/site/content/docs/elements/gate/index.mdx +418 -0
  41. package/site/content/docs/elements/gate/meta.json +5 -0
  42. package/site/content/docs/elements/gate/rate-limits.mdx +365 -0
  43. package/site/content/docs/elements/gate/rls.mdx +303 -0
  44. package/site/content/docs/elements/gate/tenancy.mdx +372 -0
  45. package/site/content/docs/elements/index.mdx +52 -11
  46. package/site/content/docs/elements/signal/broadcast.mdx +517 -0
  47. package/site/content/docs/elements/signal/index.mdx +352 -0
  48. package/site/content/docs/elements/signal/live.mdx +590 -0
  49. package/site/content/docs/elements/signal/meta.json +5 -0
  50. package/site/content/docs/elements/signal/once.mdx +596 -0
  51. package/site/content/docs/elements/store/files.mdx +659 -0
  52. package/site/content/docs/elements/store/index.mdx +310 -0
  53. package/site/content/docs/elements/store/kv.mdx +629 -0
  54. package/site/content/docs/elements/store/meta.json +5 -0
  55. package/site/content/docs/elements/store/search.mdx +946 -0
  56. package/site/content/docs/elements/store/sql.mdx +937 -0
  57. package/site/content/docs/elements/vault/config.mdx +256 -0
  58. package/site/content/docs/elements/vault/index.mdx +356 -0
  59. package/site/content/docs/elements/vault/meta.json +5 -0
  60. package/site/content/docs/elements/vault/rotation.mdx +273 -0
  61. package/site/content/docs/elements/vault/secrets.mdx +285 -0
  62. package/site/content/docs/index.mdx +78 -30
  63. package/site/content/docs/meta.json +11 -8
  64. package/site/content/docs/plugins/cors.mdx +2 -1
  65. package/site/content/docs/plugins/csrf.mdx +4 -1
  66. package/site/content/docs/plugins/headers.mdx +2 -1
  67. package/site/content/docs/plugins/ip-allowlist.mdx +2 -1
  68. package/site/content/docs/plugins/magic-link.mdx +6 -0
  69. package/site/content/docs/plugins/maintenance-mode.mdx +2 -1
  70. package/site/content/docs/plugins/oauth.mdx +1 -1
  71. package/site/content/docs/plugins/otp.mdx +12 -1
  72. package/site/content/docs/plugins/passkey.mdx +39 -15
  73. package/site/content/docs/plugins/two-factor.mdx +91 -34
  74. package/site/content/docs/plugins/username.mdx +1 -1
  75. package/site/content/docs/recipes/caddy.mdx +3 -3
  76. package/site/content/docs/recipes/index.mdx +18 -28
  77. package/site/content/docs/recipes/mailpit.mdx +1 -1
  78. package/site/content/docs/recipes/meilisearch.mdx +3 -3
  79. package/site/content/docs/recipes/meta.json +1 -4
  80. package/site/content/docs/recipes/nginx.mdx +2 -2
  81. package/site/content/docs/recipes/openrouter.mdx +283 -0
  82. package/site/content/docs/recipes/pgdog.mdx +3 -3
  83. package/site/content/docs/recipes/postgres.mdx +1 -2
  84. package/site/content/docs/recipes/rustfs.mdx +2 -2
  85. package/site/content/docs/recipes/traefik.mdx +3 -3
  86. package/site/content/docs/reference/cli.mdx +231 -0
  87. package/site/content/docs/reference/configuration.mdx +30 -10
  88. package/site/content/docs/reference/environment-variables.mdx +93 -20
  89. package/site/content/docs/reference/errors.mdx +132 -29
  90. package/site/content/docs/reference/fx.mdx +137 -73
  91. package/site/content/docs/reference/index.mdx +13 -21
  92. package/site/content/docs/reference/meta.json +4 -5
  93. package/site/content/docs/reference/okid.mdx +42 -17
  94. package/site/content/docs/reference/plugins.mdx +4 -3
  95. package/site/content/docs/reference/security.mdx +197 -0
  96. package/site/content/docs/understand/meta.json +5 -0
  97. package/site/content/docs/understand/the-anatomy.mdx +132 -0
  98. package/site/content/docs/understand/the-model.mdx +32 -0
  99. package/site/content/docs/understand/the-problem.mdx +74 -0
  100. package/site/content/docs/understand/the-vocabulary.mdx +26 -0
  101. package/src/auth/api-keys.ts +2 -1
  102. package/src/auth/bindings.ts +64 -16
  103. package/src/auth/gate-auth.test.ts +6 -1
  104. package/src/auth/identity.ts +152 -5
  105. package/src/auth/index.ts +29 -0
  106. package/src/auth/invites.ts +2 -1
  107. package/src/auth/method-context.ts +41 -0
  108. package/src/auth/oauth-as/crypto.ts +2 -1
  109. package/src/auth/oauth-as/stores.ts +2 -1
  110. package/src/auth/operator.ts +2 -1
  111. package/src/auth/sessions-jwt.test.ts +77 -0
  112. package/src/auth/sessions.ts +20 -4
  113. package/src/auth/tenants.ts +3 -2
  114. package/src/auth/two-factor-challenge.test.ts +61 -0
  115. package/src/auth/two-factor-challenge.ts +284 -0
  116. package/src/auth/verification.ts +5 -0
  117. package/src/bench/REPORT.md +49 -0
  118. package/src/bench/g03-signal-once.bench.ts +1 -1
  119. package/src/bench/g10-observability-contention.bench.ts +1 -1
  120. package/src/bench/g17-hybrid-search.bench.ts +572 -0
  121. package/src/bench/load-app.ts +2 -10
  122. package/src/cli/ai-setup/ai-setup.test.ts +331 -42
  123. package/src/cli/ai-setup/apply.ts +294 -52
  124. package/src/cli/ai-setup/catalog.ts +238 -1342
  125. package/src/cli/ai-setup/index.ts +14 -99
  126. package/src/cli/ai-setup/prompts.ts +60 -443
  127. package/src/cli/ask-seed.test.ts +96 -0
  128. package/src/cli/ask-seed.ts +82 -0
  129. package/src/cli/ask-vault-gaps.test.ts +84 -0
  130. package/src/cli/ask-vault-gaps.ts +146 -0
  131. package/src/cli/build.ts +2 -2
  132. package/src/cli/client-add.test.ts +26 -1
  133. package/src/cli/client-add.ts +106 -27
  134. package/src/cli/competitor-mention-removal.test.ts +1 -1
  135. package/src/cli/db-seed.ts +2 -0
  136. package/src/cli/db.ts +150 -11
  137. package/src/cli/dev.ts +119 -211
  138. package/src/cli/docker-clean.ts +2 -2
  139. package/src/cli/docker-cli.test.ts +1 -1
  140. package/src/cli/doctor-diff.ts +4 -2
  141. package/src/cli/doctor-pii.test.ts +1 -1
  142. package/src/cli/doctor.ts +14 -1
  143. package/src/cli/hero-meta.test.ts +4 -2
  144. package/src/cli/load-config.images.test.ts +8 -10
  145. package/src/cli/load-config.ts +1 -1
  146. package/src/cli/registry.ts +22 -10
  147. package/src/cli/replay.ts +3 -1
  148. package/src/cli/start.ts +1 -1
  149. package/src/cli/tui/keys.ts +2 -3
  150. package/src/client/auth/cookies.ts +74 -0
  151. package/src/client/auth/create-auth-client.ts +636 -0
  152. package/src/client/auth/denials.ts +99 -0
  153. package/src/client/auth/session.ts +283 -0
  154. package/src/client/auth.test.ts +251 -0
  155. package/src/client/auth.ts +39 -114
  156. package/src/client/create-with-session.ts +245 -0
  157. package/src/client/create.ts +51 -5
  158. package/src/client/index.ts +11 -1
  159. package/src/client/live.ts +11 -79
  160. package/src/client/notes-contract.test.ts +5 -10
  161. package/src/client/sse.ts +137 -0
  162. package/src/client/stream.ts +147 -0
  163. package/src/client/transport.test.ts +32 -0
  164. package/src/client/transport.ts +123 -26
  165. package/src/client/types.ts +118 -14
  166. package/src/client-react/index.ts +185 -24
  167. package/src/client-react/use-live-query.ts +13 -3
  168. package/src/compiler/aot.test.ts +7 -4
  169. package/src/compiler/effects-embed.test.ts +56 -0
  170. package/src/compiler/effects-fetch.test.ts +43 -0
  171. package/src/compiler/effects-infer.ts +58 -2
  172. package/src/compiler/extract.test.ts +258 -44
  173. package/src/compiler/extract.ts +566 -48
  174. package/src/compiler/fixtures/skyport/src/flows/bookings/index.ts +7 -4
  175. package/src/compiler/fixtures/skyport/src/flows/bookings/signals.ts +2 -8
  176. package/src/compiler/fixtures/skyport.expected.json +4 -4
  177. package/src/compiler/fixtures/triggers/five-triggers.ts +14 -10
  178. package/src/compiler/response.ts +2 -2
  179. package/src/compiler/search-writer-isolation.test.ts +40 -0
  180. package/src/config/index.ts +11 -0
  181. package/src/console/server/app.ts +17 -23
  182. package/src/console/server/bind.ts +4 -0
  183. package/src/console/server/console.test.ts +2 -2
  184. package/src/console/server/flows-invoke.test.ts +50 -34
  185. package/src/console/server/flows.ts +436 -255
  186. package/src/console/server/runs-ingest.test.ts +6 -3
  187. package/src/console/server/serve.ts +1 -1
  188. package/src/console/server/signals.test.ts +1 -5
  189. package/src/console/server/signals.ts +8 -6
  190. package/src/console/server/state.ts +6 -1
  191. package/src/console/server/store.ts +1 -1
  192. package/src/console/ui-next/dist/assets/FileExportIcon-Ck-5od4R.js +1 -0
  193. package/src/console/ui-next/dist/assets/MoreHorizontalCircle01Icon-gMNGsE37.js +1 -0
  194. package/src/console/ui-next/dist/assets/PlusSignIcon-CwG3nxfu.js +1 -0
  195. package/src/console/ui-next/dist/assets/UnavailableIcon-D9cvHVPr.js +1 -0
  196. package/src/console/ui-next/dist/assets/UserIcon-DaE2PB5_.js +1 -0
  197. package/src/console/ui-next/dist/assets/access-page-DFeymU07.js +4 -0
  198. package/src/console/ui-next/dist/assets/agent-disclosure-U1rdfblp.js +1 -0
  199. package/src/console/ui-next/dist/assets/cache-glyph-BeFJeqBG.js +1 -0
  200. package/src/console/ui-next/dist/assets/call-pii-button-CVAONPii.js +1 -0
  201. package/src/console/ui-next/dist/assets/collapsible-D2A6NJ-3.js +1 -0
  202. package/src/console/ui-next/dist/assets/copy-inline-button-CAYD18cr.js +1 -0
  203. package/src/console/ui-next/dist/assets/dagre.esm-B1_XeuLP.js +1 -0
  204. package/src/console/ui-next/dist/assets/detail-header-DVWNjWjg.js +1 -0
  205. package/src/console/ui-next/dist/assets/dropdown-menu-4h2LOVXM.js +1 -0
  206. package/src/console/ui-next/dist/assets/duration-tone-Cgk_h5ja.js +9 -0
  207. package/src/console/ui-next/dist/assets/element-icons-BI8cJgdh.js +1 -0
  208. package/src/console/ui-next/dist/assets/explorer-empty-CJs5A-wm.js +1 -0
  209. package/src/console/ui-next/dist/assets/flows-page-Dss7941e.js +1 -0
  210. package/src/console/ui-next/dist/assets/highlighted-json-MYZQtRnw.js +154 -0
  211. package/src/console/ui-next/dist/assets/http-method-Jrh39p7A.js +1 -0
  212. package/src/console/ui-next/dist/assets/index-D0zS5rKO.css +2 -0
  213. package/src/console/ui-next/dist/assets/index-DXP2dBIF.js +63 -0
  214. package/src/console/ui-next/dist/assets/observability-page-HvolXxTI.js +4 -0
  215. package/src/console/ui-next/dist/assets/react-dom-Ddte4I-Q.js +9 -0
  216. package/src/console/ui-next/dist/assets/replica-lag-CSh2dzrb.js +18 -0
  217. package/src/console/ui-next/dist/assets/request-meta-BatF8KrK.js +1 -0
  218. package/src/console/ui-next/dist/assets/shortcut-keys-3ILd8oGn.js +1 -0
  219. package/src/console/ui-next/dist/assets/{sql-BskegiFM.js → sql-BsFa4tDR.js} +1 -1
  220. package/src/console/ui-next/dist/assets/store-page-eiKiHnNe.js +41 -0
  221. package/src/console/ui-next/dist/assets/trace-detail-sheet-CZkMeKS-.js +2 -0
  222. package/src/console/ui-next/dist/assets/tree-expand-toggle-CW8y5A2h.js +55 -0
  223. package/src/console/ui-next/dist/assets/units-page-B_RWJrEO.js +1 -0
  224. package/src/console/ui-next/dist/assets/{use-vault-list-uk4WVboC.js → use-vault-list-CT4-gajj.js} +1 -1
  225. package/src/console/ui-next/dist/assets/vault-page-CWrg-A68.js +2 -0
  226. package/src/console/ui-next/dist/assets/xyflow-CSyC6ryz.css +1 -0
  227. package/src/console/ui-next/dist/assets/xyflow-yApv7D4e.js +7 -0
  228. package/src/console/ui-next/dist/index.html +6 -13
  229. package/src/console/ui-next/seed-invoke-host.ts +21 -18
  230. package/src/console/ui-next/src/client.ts +7 -2
  231. package/src/console/ui-next/src/features/flows/graph/element-map.ts +2 -0
  232. package/src/console/ui-next/src/features/flows/traces/effect-kind.ts +12 -2
  233. package/src/console/ui-next/src/features/flows/traces/effect-summary.ts +4 -0
  234. package/src/console/ui-next/src/features/flows/traces/trace-detail-sheet.tsx +8 -0
  235. package/src/console/ui-next/src/features/flows/traces/waterfall-bars.ts +4 -0
  236. package/src/console/ui-next/src/features/flows/traces/waterfall-tooltip.ts +9 -3
  237. package/src/console/ui-next/src/features/store/detail/reveal-cell.tsx +7 -11
  238. package/src/console/ui-next/src/features/store/detail/store-row-detail-sheet.tsx +2 -2
  239. package/src/console/ui-next/src/features/store/lib/fields-from-table.ts +2 -0
  240. package/src/console/ui-next/src/features/store/lib/grid-model.test.ts +25 -1
  241. package/src/console/ui-next/src/features/store/lib/grid-model.ts +36 -1
  242. package/src/console/ui-next/src/features/store/query/query-results.tsx +3 -3
  243. package/src/console/ui-next/src/features/units/detail/effects-summary.tsx +2 -0
  244. package/src/console/ui-next/src/features/units/lib/call-read-safe.ts +3 -1
  245. package/src/console/ui-next/src/features/units/lib/fields-from-schema.ts +6 -0
  246. package/src/docker/ai-model-status.test.ts +1 -12
  247. package/src/docker/ai-model-status.ts +10 -38
  248. package/src/docker/compose-up.test.ts +100 -0
  249. package/src/docker/compose-up.ts +292 -0
  250. package/src/docker/compose.ts +4 -14
  251. package/src/docker/derive.ts +9 -34
  252. package/src/docker/docker.test.ts +16 -261
  253. package/src/docker/images-config.test.ts +13 -25
  254. package/src/docker/index.ts +1 -24
  255. package/src/docker/recipes/index.ts +0 -23
  256. package/src/docker/recipes/pgdog.ts +6 -4
  257. package/src/docker/stack-id.test.ts +2 -2
  258. package/src/docker/stack-id.ts +0 -1
  259. package/src/docker/types.ts +2 -2
  260. package/src/drivers/ai-anthropic.ts +10 -0
  261. package/src/drivers/ai-openai-compatible.ts +34 -7
  262. package/src/drivers/ai-providers.test.ts +0 -107
  263. package/src/drivers/ai-stream.test.ts +0 -34
  264. package/src/drivers/ai-types.ts +17 -8
  265. package/src/drivers/channel-fcm.ts +6 -1
  266. package/src/drivers/channel-msegat.ts +6 -1
  267. package/src/drivers/channel-resend.ts +5 -1
  268. package/src/drivers/channel-smtp.ts +5 -1
  269. package/src/drivers/channel-sndr.ts +10 -1
  270. package/src/drivers/channel-taqnyat-mail.ts +5 -1
  271. package/src/drivers/channel-taqnyat-whatsapp.ts +6 -1
  272. package/src/drivers/channel-taqnyat.ts +6 -1
  273. package/src/drivers/channel-types.ts +10 -0
  274. package/src/drivers/channel-unifonic.ts +6 -1
  275. package/src/drivers/channel-wa-cloud.ts +6 -1
  276. package/src/drivers/channel-webpush.ts +6 -1
  277. package/src/drivers/external.ts +33 -0
  278. package/src/drivers/index.ts +0 -10
  279. package/src/drivers/meilisearch.ts +6 -0
  280. package/src/drivers/oauth-types.ts +4 -0
  281. package/src/drivers/postgres.test.ts +74 -3
  282. package/src/drivers/postgres.ts +175 -6
  283. package/src/drivers/signal-types.ts +5 -5
  284. package/src/drivers/types.ts +7 -0
  285. package/src/drivers/vault-types.ts +5 -0
  286. package/src/elements/ai/declare.ts +17 -4
  287. package/src/elements/ai/eval.ts +1 -1
  288. package/src/elements/ai/mcp-http.ts +1 -1
  289. package/src/elements/ai/pii.ts +1 -1
  290. package/src/elements/ai/providers.test.ts +289 -0
  291. package/src/elements/ai/providers.ts +169 -0
  292. package/src/elements/ai/runtime.ts +68 -5
  293. package/src/elements/ai/schema.ts +2 -2
  294. package/src/elements/ai.test.ts +7 -7
  295. package/src/elements/ai.ts +17 -1
  296. package/src/elements/channel/runtime.ts +105 -12
  297. package/src/elements/clock/cron-fields.test.ts +144 -0
  298. package/src/elements/clock/cron-fields.ts +185 -0
  299. package/src/elements/clock/declare.ts +247 -3
  300. package/src/elements/clock.ts +21 -1
  301. package/src/elements/index.ts +15 -0
  302. package/src/elements/signal/chaos-child.ts +1 -2
  303. package/src/elements/signal/declare.ts +65 -37
  304. package/src/elements/signal/delivery-modes.test.ts +11 -31
  305. package/src/elements/signal/dry-run-replay.test.ts +1 -7
  306. package/src/elements/signal/dry-run-write-isolation.test.ts +1 -7
  307. package/src/elements/signal/key-ordering.test.ts +6 -26
  308. package/src/elements/signal/lease-reclaim.test.ts +2 -6
  309. package/src/elements/signal/optional-emit.test.ts +6 -9
  310. package/src/elements/signal/order-lifecycle.test.ts +4 -17
  311. package/src/elements/signal/orphan-messages.test.ts +4 -15
  312. package/src/elements/signal/reconcile.test.ts +2 -2
  313. package/src/elements/signal/runtime.ts +1 -1
  314. package/src/elements/signal/schema-emit.test.ts +4 -8
  315. package/src/elements/signal.test.ts +24 -49
  316. package/src/elements/signal.ts +9 -2
  317. package/src/elements/store/domain-ddl.test.ts +1 -1
  318. package/src/elements/store/live-http.test.ts +9 -4
  319. package/src/elements/store/prepare-row.test.ts +123 -0
  320. package/src/elements/store/resource.ts +43 -12
  321. package/src/elements/store/schema-decl.ts +117 -0
  322. package/src/elements/store/search-backfill.ts +205 -0
  323. package/src/elements/store/search-bind.ts +66 -0
  324. package/src/elements/store/search-bm25.ts +78 -0
  325. package/src/elements/store/search-ddl.ts +156 -0
  326. package/src/elements/store/search-embed-flow.ts +141 -0
  327. package/src/elements/store/search-errors.ts +34 -0
  328. package/src/elements/store/search-fusion.ts +112 -0
  329. package/src/elements/store/search-lsh.ts +179 -0
  330. package/src/elements/store/search-runtime.ts +300 -0
  331. package/src/elements/store/search.test.ts +144 -0
  332. package/src/elements/store/sql-session.test.ts +1 -0
  333. package/src/elements/store/sql-session.ts +83 -3
  334. package/src/elements/store/table.ts +23 -2
  335. package/src/elements/store/upsert-app.test.ts +1 -3
  336. package/src/elements/store.ts +50 -0
  337. package/src/full.ts +4 -2
  338. package/src/http.ts +4 -1
  339. package/src/i18n/catalogs/ar.ts +14 -6
  340. package/src/i18n/catalogs/en.ts +14 -6
  341. package/src/index.ts +6 -1
  342. package/src/kernel/adopt-barrel-fresh.test.ts +7 -7
  343. package/src/kernel/adopt-routes.ts +9 -1
  344. package/src/kernel/app-auth.ts +5 -0
  345. package/src/kernel/app.ts +102 -9
  346. package/src/kernel/auto-cache.test.ts +6 -12
  347. package/src/kernel/auto-registry.test.ts +3 -3
  348. package/src/kernel/boot-bind/ai.test.ts +22 -19
  349. package/src/kernel/boot-bind/ai.ts +5 -43
  350. package/src/kernel/boot-bind/clock.ts +23 -5
  351. package/src/kernel/boot-bind/honor-config.test.ts +4 -4
  352. package/src/kernel/boot.test.ts +11 -6
  353. package/src/kernel/boot.ts +66 -16
  354. package/src/kernel/boundary-contract.ts +93 -0
  355. package/src/kernel/budget.test.ts +1 -1
  356. package/src/kernel/call.ts +89 -0
  357. package/src/kernel/capability.ts +6 -0
  358. package/src/kernel/client-descriptor.ts +123 -0
  359. package/src/kernel/clock-timezone.test.ts +80 -0
  360. package/src/kernel/correlation.test.ts +1 -1
  361. package/src/kernel/dry-run.ts +11 -8
  362. package/src/kernel/effects-stamping.test.ts +42 -9
  363. package/src/kernel/effects.test.ts +4 -2
  364. package/src/kernel/effects.ts +51 -9
  365. package/src/kernel/errors-channel.ts +17 -0
  366. package/src/kernel/errors-live-resume.ts +3 -2
  367. package/src/kernel/errors-tenant.ts +7 -4
  368. package/src/kernel/errors.registry-helpers.ts +96 -0
  369. package/src/kernel/errors.registry.test.ts +139 -25
  370. package/src/kernel/errors.ts +102 -23
  371. package/src/kernel/external-effects.test.ts +196 -0
  372. package/src/kernel/flow.test.ts +13 -4
  373. package/src/kernel/flow.ts +69 -71
  374. package/src/kernel/fx-ask-telemetry.test.ts +2 -2
  375. package/src/kernel/fx-dead-letters.test.ts +3 -3
  376. package/src/kernel/fx-fetch.ts +55 -0
  377. package/src/kernel/fx-live-stream.ts +2 -2
  378. package/src/kernel/fx-live.test.ts +8 -8
  379. package/src/kernel/fx.test.ts +17 -11
  380. package/src/kernel/fx.ts +180 -57
  381. package/src/kernel/horizontal-child.ts +1 -1
  382. package/src/kernel/http-query.test.ts +3 -6
  383. package/src/kernel/index.ts +13 -3
  384. package/src/kernel/instance-id.ts +1 -1
  385. package/src/kernel/instances.test.ts +40 -0
  386. package/src/kernel/instances.ts +47 -9
  387. package/src/kernel/live-http.test.ts +6 -7
  388. package/src/kernel/live-http.ts +6 -2
  389. package/src/kernel/live-resume.test.ts +1 -1
  390. package/src/kernel/mcp-tool.test.ts +3 -3
  391. package/src/kernel/on.ts +98 -4
  392. package/src/kernel/pipeline.test.ts +12 -15
  393. package/src/kernel/plugin-elements.test.ts +1 -1
  394. package/src/kernel/stamp-http.test.ts +3 -3
  395. package/src/kernel/triggers.ts +210 -95
  396. package/src/kernel-entry.ts +0 -1
  397. package/src/manifest/diff.ts +11 -1
  398. package/src/manifest/fixtures/skyport.excerpt.json +1 -1
  399. package/src/manifest/types.ts +46 -2
  400. package/src/mcp/docs-index.ts +3 -3
  401. package/src/mcp/docs-mcp.test.ts +2 -2
  402. package/src/mcp/docs-tools.ts +1 -1
  403. package/src/okid.test.ts +56 -0
  404. package/src/okid.ts +55 -11
  405. package/src/plugins/anonymous.ts +8 -4
  406. package/src/plugins/auth/shared.ts +27 -3
  407. package/src/plugins/auth-delivery.mailpit.integration.test.ts +1 -1
  408. package/src/plugins/auth-methods.security.test.ts +561 -23
  409. package/src/plugins/config-source.ts +1 -1
  410. package/src/plugins/csrf.test.ts +65 -0
  411. package/src/plugins/index.ts +2 -0
  412. package/src/plugins/magic-link.ts +36 -16
  413. package/src/plugins/oauth/shared.ts +3 -1
  414. package/src/plugins/oauth.ts +22 -14
  415. package/src/plugins/otp.ts +37 -21
  416. package/src/plugins/passkey-webauthn.ts +9 -6
  417. package/src/plugins/passkey.ts +98 -26
  418. package/src/plugins/pre-account-hijack.test.ts +223 -0
  419. package/src/plugins/two-factor.ts +466 -37
  420. package/src/plugins/username.ts +19 -7
  421. package/src/release/build-lib.ts +1 -0
  422. package/src/release/limits.ts +2 -2
  423. package/src/release/measure.ts +1 -1
  424. package/src/runs/collect.test.ts +0 -2
  425. package/src/runtime/json-code-block.test.ts +250 -20
  426. package/src/runtime/json-code-block.ts +1261 -41
  427. package/src/term.test.ts +1 -1
  428. package/src/test/create-test-app.test.ts +12 -12
  429. package/src/test/live-signals.test.ts +6 -6
  430. package/src/test/provisions.integration.test.ts +10 -14
  431. package/src/test/reset-element-registries.ts +1 -1
  432. package/src/test/tenant-isolation.test.ts +12 -6
  433. package/site/content/docs/deployment/docker-swarm.mdx +0 -164
  434. package/site/content/docs/deployment/docker.mdx +0 -227
  435. package/site/content/docs/deployment/index.mdx +0 -83
  436. package/site/content/docs/deployment/kubernetes.mdx +0 -176
  437. package/site/content/docs/deployment/meta.json +0 -5
  438. package/site/content/docs/deployment/reverse-proxy.mdx +0 -234
  439. package/site/content/docs/elements/ai.mdx +0 -385
  440. package/site/content/docs/elements/channel.mdx +0 -346
  441. package/site/content/docs/elements/clock.mdx +0 -244
  442. package/site/content/docs/elements/flow.mdx +0 -420
  443. package/site/content/docs/elements/gate.mdx +0 -436
  444. package/site/content/docs/elements/signal.mdx +0 -380
  445. package/site/content/docs/elements/store.mdx +0 -1099
  446. package/site/content/docs/elements/vault.mdx +0 -405
  447. package/site/content/docs/get-started/basic-usage.mdx +0 -173
  448. package/site/content/docs/get-started/index.mdx +0 -43
  449. package/site/content/docs/get-started/installation.mdx +0 -220
  450. package/site/content/docs/get-started/introduction.mdx +0 -132
  451. package/site/content/docs/get-started/meta.json +0 -13
  452. package/site/content/docs/get-started/project-structure.mdx +0 -925
  453. package/site/content/docs/get-started/testing.mdx +0 -328
  454. package/site/content/docs/get-started/why.mdx +0 -162
  455. package/site/content/docs/recipes/llama-cpp.mdx +0 -151
  456. package/site/content/docs/recipes/ollama.mdx +0 -142
  457. package/site/content/docs/recipes/sglang.mdx +0 -105
  458. package/site/content/docs/recipes/vllm.mdx +0 -106
  459. package/site/content/docs/reference/cli.md +0 -232
  460. package/site/content/docs/reference/client.mdx +0 -469
  461. package/site/content/docs/reference/security.md +0 -74
  462. package/src/cli/ai-setup/detect-ollama.ts +0 -213
  463. package/src/cli/ai-setup/recommend.test.ts +0 -225
  464. package/src/cli/ai-setup/recommend.ts +0 -225
  465. package/src/cli/dev-controls.test.ts +0 -122
  466. package/src/cli/dev-controls.ts +0 -164
  467. package/src/cli/tui/DevLive.tsx +0 -126
  468. package/src/console/ui-next/dist/assets/access-page-De7Lc2JC.js +0 -4
  469. package/src/console/ui-next/dist/assets/agent-disclosure-BP0Y0Sux.js +0 -1
  470. package/src/console/ui-next/dist/assets/cache-glyph-B5X-NM0-.js +0 -1
  471. package/src/console/ui-next/dist/assets/call-pii-button-ChAUiLo9.js +0 -1
  472. package/src/console/ui-next/dist/assets/collapsible-DGnOM2ph.js +0 -1
  473. package/src/console/ui-next/dist/assets/copy-inline-button-DBHhgHKP.js +0 -1
  474. package/src/console/ui-next/dist/assets/dagre.esm-ZwcdTuZZ.js +0 -1
  475. package/src/console/ui-next/dist/assets/detail-header-DhHM1iaZ.js +0 -1
  476. package/src/console/ui-next/dist/assets/dropdown-menu-_NjTEo5_.js +0 -1
  477. package/src/console/ui-next/dist/assets/duration-tone-sC3lGABz.js +0 -9
  478. package/src/console/ui-next/dist/assets/element-icons-BVXtRyd3.js +0 -1
  479. package/src/console/ui-next/dist/assets/explorer-empty-2uIhBu0_.js +0 -1
  480. package/src/console/ui-next/dist/assets/flows-page-RGy7VEA_.js +0 -1
  481. package/src/console/ui-next/dist/assets/highlighted-json-Awq7gYdu.js +0 -154
  482. package/src/console/ui-next/dist/assets/http-method-_UHM2ODJ.js +0 -1
  483. package/src/console/ui-next/dist/assets/index-Ck88Jmv8.css +0 -2
  484. package/src/console/ui-next/dist/assets/index-_rgpdVzo.js +0 -66
  485. package/src/console/ui-next/dist/assets/link-BX6Vqztd.js +0 -1
  486. package/src/console/ui-next/dist/assets/observability-page-Ds6pcnh-.js +0 -4
  487. package/src/console/ui-next/dist/assets/preload-helper-oH4irX4C.js +0 -1
  488. package/src/console/ui-next/dist/assets/react-D8E3mtu1.js +0 -1
  489. package/src/console/ui-next/dist/assets/react-dom-Bph1y7z7.js +0 -9
  490. package/src/console/ui-next/dist/assets/replica-lag-DKRrbvdo.js +0 -18
  491. package/src/console/ui-next/dist/assets/request-meta-DV0ywz7t.js +0 -1
  492. package/src/console/ui-next/dist/assets/shortcut-JQIZlWfm.js +0 -1
  493. package/src/console/ui-next/dist/assets/shortcut-keys-DKxNTe_m.js +0 -1
  494. package/src/console/ui-next/dist/assets/skeleton-D-czQJT6.js +0 -1
  495. package/src/console/ui-next/dist/assets/store-page-02xOiqIK.js +0 -41
  496. package/src/console/ui-next/dist/assets/trace-detail-sheet-B09O8rA6.js +0 -2
  497. package/src/console/ui-next/dist/assets/tree-expand-toggle-BtyhmWb4.js +0 -55
  498. package/src/console/ui-next/dist/assets/units-page-4rHOePuE.js +0 -1
  499. package/src/console/ui-next/dist/assets/useMutation-B8EO02Ej.js +0 -1
  500. package/src/console/ui-next/dist/assets/useRender-BE2A9BWC.js +0 -1
  501. package/src/console/ui-next/dist/assets/vault-page-DISPgxLM.js +0 -2
  502. package/src/console/ui-next/dist/assets/xyflow-D7n4g6go.js +0 -7
  503. package/src/console/ui-next/dist/assets/xyflow-DZ0Ws1xk.css +0 -1
  504. package/src/docker/ollama-pull.ts +0 -232
  505. package/src/docker/recipes/llama-cpp.ts +0 -298
  506. package/src/docker/recipes/ollama.ts +0 -44
  507. package/src/docker/recipes/sglang.ts +0 -55
  508. package/src/docker/recipes/vllm.ts +0 -44
  509. package/src/drivers/ai-ollama-tools.integration.test.ts +0 -109
  510. package/src/drivers/ai-ollama.integration.test.ts +0 -184
  511. package/src/drivers/ai-ollama.ts +0 -389
  512. package/src/drivers/ollama.ts +0 -14
@@ -0,0 +1,41 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,r as n}from"./react-dom-Ddte4I-Q.js";import{A as r,a as i,c as a,d as o,f as s,i as c,l,m as u,n as d,o as f,p,r as m,s as h,t as g,u as _}from"./xyflow-yApv7D4e.js";import{Ar as v,Cr as y,Dr as b,E as x,Er as S,Et as C,F as w,I as T,Mr as E,Or as D,R as O,Tr as k,Yi as A,_i as j,_r as M,a as N,ar as P,br as F,c as I,ci as L,cr as R,di as z,dr as B,er as V,fr as H,gi as ee,ha as te,hi as ne,i as re,ir as U,jr as ie,kr as ae,l as oe,li as se,lr as ce,mi as le,mr as ue,nr as de,o as W,or as fe,pi as pe,pr as me,rr as he,s as ge,sr as _e,t as ve,tr as ye,u as be,ui as xe,ur as Se,vi as Ce,vr as we,wr as Te,x as G,xr as Ee}from"./shortcut-keys-3ILd8oGn.js";import{a as De,c as Oe,i as ke,l as K,o as Ae,s as je,t as q}from"./call-pii-button-CVAONPii.js";import{_ as Me,a as Ne,b as Pe,c as Fe,d as Ie,f as Le,h as Re,i as ze,l as Be,m as Ve,n as He,o as Ue,p as We,r as Ge,s as J,t as Ke,u as qe,v as Je,x as Ye,y as Xe}from"./element-icons-BI8cJgdh.js";import{a as Ze,i as Qe,n as $e,o as et,r as tt,s as nt,t as rt}from"./collapsible-D2A6NJ-3.js";import{a as it,c as at,i as ot,n as st,o as ct,r as lt,s as ut}from"./duration-tone-Cgk_h5ja.js";import{a as dt,c as ft,d as pt,f as mt,i as ht,n as gt,r as _t,s as vt,t as yt,u as bt}from"./highlighted-json-MYZQtRnw.js";import{A as xt,B as St,C as Ct,D as wt,E as Tt,F as Et,H as Dt,I as Ot,L as kt,M as At,N as jt,O as Mt,P as Nt,R as Pt,S as Ft,T as It,U as Lt,V as Rt,W as zt,_ as Bt,a as Vt,b as Ht,c as Ut,d as Wt,f as Gt,g as Kt,h as qt,i as Jt,j as Yt,k as Xt,l as Zt,m as Qt,n as $t,o as en,p as tn,r as nn,s as rn,t as an,u as on,v as sn,w as cn,x as ln,y as un,z as dn}from"./replica-lag-CSh2dzrb.js";import{n as fn,r as pn,t as mn}from"./UserIcon-DaE2PB5_.js";import{t as hn}from"./FileExportIcon-Ck-5od4R.js";import{n as gn}from"./dagre.esm-B1_XeuLP.js";import{$ as _n,A as vn,B as yn,C as bn,D as xn,E as Sn,F as Cn,G as wn,H as Tn,I as En,J as Dn,K as On,L as kn,M as An,N as jn,O as Mn,P as Nn,Q as Pn,R as Fn,S as In,T as Ln,U as Rn,V as zn,W as Bn,X as Vn,Y as Hn,Z as Un,_ as Wn,a as Gn,at as Kn,b as qn,c as Jn,ct as Yn,et as Xn,f as Zn,g as Qn,h as $n,i as er,it as tr,j as nr,k as rr,l as ir,lt as ar,m as or,n as sr,nt as cr,o as lr,ot as ur,q as dr,r as fr,rt as pr,s as mr,st as hr,t as gr,tt as _r,u as vr,ut as yr,v as br,w as xr,x as Sr,y as Cr,z as wr}from"./tree-expand-toggle-CW8y5A2h.js";import{t as Tr}from"./MoreHorizontalCircle01Icon-gMNGsE37.js";import{t as Er}from"./PlusSignIcon-CwG3nxfu.js";import{a as Dr,c as Or,d as kr,i as Ar,l as jr,n as Mr,o as Nr,r as Pr,s as Fr,t as Ir,u as Lr,v as Rr}from"./dropdown-menu-4h2LOVXM.js";import{$ as zr,E as Br,J as Vr,Q as Hr,R as Ur,X as Wr,Y as Gr,Z as Kr,_t as qr,at as Jr,bt as Yr,c as Xr,d as Zr,et as Qr,i as $r,it as ei,l as ti,n as ni,nt as ri,o as ii,q as ai,r as oi,s as si,st as ci,tt as li,yt as ui}from"./index-DXP2dBIF.js";import{t as di}from"./explorer-empty-CJs5A-wm.js";import{a as fi,c as Y,d as pi,f as mi,i as hi,l as gi,n as X,o as _i,p as vi,r as yi,s as bi,t as xi}from"./detail-header-DVWNjWjg.js";import{n as Si,t as Ci}from"./copy-inline-button-CAYD18cr.js";import{t as wi}from"./agent-disclosure-U1rdfblp.js";var Ti=[[`path`,{d:`M17.5798 9.71016C17.0765 9.57314 16.5468 9.5 16 9.5C13.4668 9.5 11.3002 11.0699 10.4202 13.2898M17.5798 9.71016C20.1271 10.4036 22 12.7331 22 15.5C22 18.8137 19.3137 21.5 16 21.5C14.4633 21.5 13.0615 20.9223 12 19.9722M17.5798 9.71016C17.851 9.02618 18 8.2805 18 7.5C18 4.18629 15.3137 1.5 12 1.5C8.68629 1.5 6 4.18629 6 7.5C6 8.2805 6.14903 9.02618 6.42018 9.71016M10.4202 13.2898C10.149 13.9738 10 14.7195 10 15.5C10 17.277 10.7725 18.8736 12 19.9722M10.4202 13.2898C8.59146 12.792 7.11029 11.451 6.42018 9.71016M6.42018 9.71016C3.87294 10.4036 2 12.7331 2 15.5C2 18.8137 4.68629 21.5 8 21.5C9.53671 21.5 10.9385 20.9223 12 19.9722`,stroke:`currentColor`,strokeLinecap:`round`,strokeWidth:`1.5`,key:`0`}]],Ei=[[`ellipse`,{cx:`12`,cy:`5`,rx:`8`,ry:`3`,stroke:`currentColor`,strokeWidth:`1.5`,key:`0`}],[`path`,{d:`M7 10.842C7.60158 11.0229 8.27434 11.1718 9 11.282`,stroke:`currentColor`,strokeLinecap:`round`,strokeWidth:`1.5`,key:`1`}],[`path`,{d:`M20 12C20 13.6569 16.4183 15 12 15C7.58172 15 4 13.6569 4 12`,stroke:`currentColor`,strokeWidth:`1.5`,key:`2`}],[`path`,{d:`M7 17.842C7.60158 18.0229 8.27434 18.1718 9 18.282`,stroke:`currentColor`,strokeLinecap:`round`,strokeWidth:`1.5`,key:`3`}],[`path`,{d:`M20 5V19C20 20.6569 16.4183 22 12 22C7.58172 22 4 20.6569 4 19V5`,stroke:`currentColor`,strokeWidth:`1.5`,key:`4`}]],Di=[[`path`,{d:`M20 15.0057V10.6606C20 9.84276 20 9.43383 19.8478 9.06613C19.6955 8.69843 19.4065 8.40927 18.8284 7.83096L14.0919 3.09236C13.593 2.59325 13.3436 2.3437 13.0345 2.19583C12.9702 2.16508 12.9044 2.13778 12.8372 2.11406C12.5141 2 12.1614 2 11.4558 2C8.21082 2 6.58831 2 5.48933 2.88646C5.26731 3.06554 5.06508 3.26787 4.88607 3.48998C4 4.58943 4 6.21265 4 9.45908V14.0052C4 17.7781 4 19.6645 5.17157 20.8366C6.11466 21.7801 7.52043 21.9641 10 22M13 2.50022V3.00043C13 5.83009 13 7.24492 13.8787 8.12398C14.7574 9.00304 16.1716 9.00304 19 9.00304H19.5`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}],[`path`,{d:`M15 22C14.3932 21.4102 12 19.8403 12 19C12 18.1597 14.3932 16.5898 15 16M13 19H20`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`1`}]],Oi=[[`path`,{d:`M8 14H10M14 14H16M8 18H10M14 18H16`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}],[`path`,{d:`M13 2.5V3C13 5.82843 13 7.24264 13.8787 8.12132C14.7574 9 16.1716 9 19 9H19.5M20 10.6569V14C20 17.7712 20 19.6569 18.8284 20.8284C17.6569 22 15.7712 22 12 22C8.22876 22 6.34315 22 5.17157 20.8284C4 19.6569 4 17.7712 4 14V9.45584C4 6.21082 4 4.58831 4.88607 3.48933C5.06508 3.26731 5.26731 3.06508 5.48933 2.88607C6.58831 2 8.21082 2 11.4558 2C12.1614 2 12.5141 2 12.8372 2.11401C12.9044 2.13772 12.9702 2.165 13.0345 2.19575C13.3436 2.34355 13.593 2.593 14.0919 3.09188L18.8284 7.82843C19.4065 8.40649 19.6955 8.69552 19.8478 9.06306C20 9.4306 20 9.83935 20 10.6569Z`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`1`}]],ki=[[`path`,{d:`M8 22V19C8 17.1144 8 16.1716 8.58579 15.5858C9.17157 15 10.1144 15 12 15C13.8856 15 14.8284 15 15.4142 15.5858C16 16.1716 16 17.1144 16 19V22`,stroke:`currentColor`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}],[`path`,{d:`M10 7H14`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`1`}],[`path`,{d:`M3 11.8584C3 7.28199 3 4.99376 4.38674 3.54394C4.43797 3.49038 4.49038 3.43797 4.54394 3.38674C5.99376 2 8.28199 2 12.8584 2C13.943 2 14.4655 2.00376 14.9628 2.18936C15.4417 2.3681 15.8429 2.70239 16.6452 3.37099L18.8411 5.20092C19.9027 6.08561 20.4335 6.52795 20.7168 7.13266C21 7.73737 21 8.42833 21 9.81025V13C21 16.7497 21 18.6246 20.0451 19.9389C19.7367 20.3634 19.3634 20.7367 18.9389 21.0451C17.6246 22 15.7497 22 12 22C8.25027 22 6.3754 22 5.06107 21.0451C4.6366 20.7367 4.26331 20.3634 3.95491 19.9389C3 18.6246 3 16.7497 3 13V11.8584Z`,stroke:`currentColor`,strokeWidth:`1.5`,key:`2`}]],Ai=[[`path`,{d:`M5 19C5.26413 19.9564 5.79671 21 7.18729 21C9.59365 21 10.1952 19 12 12C13.8048 5 14.4064 3 16.8127 3C18.2033 3 18.7359 4.04358 19 5`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}],[`path`,{d:`M9 10H17`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`1`}]],ji=[[`path`,{d:`M2 20C2 19.0572 2 18.5858 2.29289 18.2929C2.58579 18 3.05719 18 4 18H5C5.94281 18 6.41421 18 6.70711 18.2929C7 18.5858 7 19.0572 7 20C7 20.9428 7 21.4142 6.70711 21.7071C6.41421 22 5.94281 22 5 22H4C3.05719 22 2.58579 22 2.29289 21.7071C2 21.4142 2 20.9428 2 20Z`,stroke:`currentColor`,strokeWidth:`1.5`,key:`0`}],[`path`,{d:`M17 20C17 19.0572 17 18.5858 17.2929 18.2929C17.5858 18 18.0572 18 19 18H20C20.9428 18 21.4142 18 21.7071 18.2929C22 18.5858 22 19.0572 22 20C22 20.9428 22 21.4142 21.7071 21.7071C21.4142 22 20.9428 22 20 22H19C18.0572 22 17.5858 22 17.2929 21.7071C17 21.4142 17 20.9428 17 20Z`,stroke:`currentColor`,strokeWidth:`1.5`,key:`1`}],[`path`,{d:`M19.5 17.5C19.5 14.1907 18.8525 13.5 15.75 13.5H14.5M4.5 17.5C4.5 14.1907 5.1475 13.5 8.25 13.5H9.5M12 7V11`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`2`}],[`path`,{d:`M10 2H14C15.8152 2 16 2.92494 16 4.5C16 6.07506 15.8152 7 14 7H10C8.1848 7 8 6.07506 8 4.5C8 2.92494 8.1848 2 10 2Z`,stroke:`currentColor`,strokeWidth:`1.5`,key:`3`}],[`path`,{d:`M14.5 13.5C14.5 14.8807 13.3807 16 12 16C10.6193 16 9.5 14.8807 9.5 13.5C9.5 12.1193 10.6193 11 12 11C13.3807 11 14.5 12.1193 14.5 13.5Z`,stroke:`currentColor`,strokeWidth:`1.5`,key:`4`}]],Mi=[[`path`,{d:`M11.0991 3.00012C7.45013 3.00669 5.53932 3.09629 4.31817 4.31764C3.00034 5.63568 3.00034 7.75704 3.00034 11.9997C3.00034 16.2424 3.00034 18.3638 4.31817 19.6818C5.63599 20.9999 7.75701 20.9999 11.9991 20.9999C16.241 20.9999 18.3621 20.9999 19.6799 19.6818C20.901 18.4605 20.9906 16.5493 20.9972 12.8998`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}],[`path`,{d:`M20.556 3.49612L11.0487 13.0586M20.556 3.49612C20.062 3.00151 16.7343 3.04761 16.0308 3.05762M20.556 3.49612C21.05 3.99074 21.0039 7.32273 20.9939 8.02714`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`1`}]],Ni=[[`path`,{d:`M22 10V9.21749C22 7.27787 22 6.30807 21.4142 5.7055C20.8284 5.10294 19.8856 5.10294 18 5.10294H15.9214C15.004 5.10294 14.9964 5.10116 14.1715 4.68834L10.8399 3.02114C9.44884 2.32504 8.75332 1.97699 8.01238 2.00118C7.27143 2.02537 6.59877 2.41808 5.25345 3.20351L4.02558 3.92037C3.03739 4.49729 2.54329 4.78576 2.27164 5.26564C2 5.74553 2 6.32993 2 7.49873V15.7157C2 17.2514 2 18.0193 2.34226 18.4467C2.57001 18.731 2.88916 18.9222 3.242 18.9856C3.77226 19.0808 4.42148 18.7018 5.71987 17.9437C6.60156 17.429 7.45011 16.8944 8.50487 17.0394C9.38869 17.1608 10.21 17.7185 11 18.1138`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}],[`path`,{d:`M8 2L8 17`,stroke:`currentColor`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`1`}],[`path`,{d:`M15 5V9.5`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`2`}],[`path`,{d:`M18.3083 21.6835C18.0915 21.8865 17.8017 22 17.5001 22C17.1985 22 16.9087 21.8865 16.6919 21.6835C14.7063 19.813 12.0455 17.7235 13.3431 14.6898C14.0447 13.0496 15.7289 12 17.5001 12C19.2713 12 20.9555 13.0496 21.6571 14.6898C22.9531 17.7196 20.2988 19.8194 18.3083 21.6835Z`,stroke:`currentColor`,strokeWidth:`1.5`,key:`3`}],[`path`,{d:`M17.625 16.5H17.5M17.75 16.5C17.75 16.6381 17.6381 16.75 17.5 16.75C17.3619 16.75 17.25 16.6381 17.25 16.5C17.25 16.3619 17.3619 16.25 17.5 16.25C17.6381 16.25 17.75 16.3619 17.75 16.5Z`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`4`}]],Pi=[[`path`,{d:`M11.9967 12.5V12M11.9967 6.5V6M11.9967 18.5V18M12.9967 12.5C12.9967 11.9477 12.549 11.5 11.9967 11.5C11.4444 11.5 10.9967 11.9477 10.9967 12.5C10.9967 13.0523 11.4444 13.5 11.9967 13.5C12.549 13.5 12.9967 13.0523 12.9967 12.5ZM12.9967 6.5C12.9967 5.94772 12.549 5.5 11.9967 5.5C11.4444 5.5 10.9967 5.94772 10.9967 6.5C10.9967 7.05228 11.4444 7.5 11.9967 7.5C12.549 7.5 12.9967 7.05228 12.9967 6.5ZM12.9967 18.5C12.9967 17.9477 12.549 17.5 11.9967 17.5C11.4444 17.5 10.9967 17.9477 10.9967 18.5C10.9967 19.0523 11.4444 19.5 11.9967 19.5C12.549 19.5 12.9967 19.0523 12.9967 18.5Z`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}]],Fi=[[`path`,{d:`M7 9.5C7 10.8807 5.88071 12 4.5 12C3.11929 12 2 10.8807 2 9.5C2 8.11929 3.11929 7 4.5 7C5.88071 7 7 8.11929 7 9.5ZM7 9.5V2C7.33333 2.5 7.6 4.6 10 5`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}],[`circle`,{cx:`10.5`,cy:`19.5`,r:`2.5`,stroke:`currentColor`,strokeWidth:`1.5`,key:`1`}],[`circle`,{cx:`20`,cy:`18`,r:`2`,stroke:`currentColor`,strokeWidth:`1.5`,key:`2`}],[`path`,{d:`M13 19.5L13 11C13 10.09 13 9.63502 13.2466 9.35248C13.4932 9.06993 13.9938 9.00163 14.9949 8.86504C18.0085 8.45385 20.2013 7.19797 21.3696 6.42937C21.6498 6.24509 21.7898 6.15295 21.8949 6.20961C22 6.26627 22 6.43179 22 6.76283V17.9259`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`3`}],[`path`,{d:`M13 13C17.8 13 21 10.6667 22 10`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`4`}]],Ii=[[`path`,{d:`M12.828 6.00096C12.9388 5.68791 12.999 5.35099 12.999 5C12.999 3.34315 11.6559 2 9.99904 2C8.34219 2 6.99904 3.34315 6.99904 5C6.99904 5.35099 7.05932 5.68791 7.17008 6.00096C4.88532 6.0093 3.66601 6.09039 2.87772 6.87868C2.08951 7.66689 2.00836 8.88603 2 11.1704C2.31251 11.06 2.64876 11 2.99904 11C4.6559 11 5.99904 12.3431 5.99904 14C5.99904 15.6569 4.6559 17 2.99904 17C2.64876 17 2.31251 16.94 2 16.8296C2.00836 19.114 2.08951 20.3331 2.87772 21.1213C3.66593 21.9095 4.88508 21.9907 7.16941 21.999C7.05908 21.6865 6.99904 21.3503 6.99904 21C6.99904 19.3431 8.34219 18 9.99904 18C11.6559 18 12.999 19.3431 12.999 21C12.999 21.3503 12.939 21.6865 12.8287 21.999C15.113 21.9907 16.3322 21.9095 17.1204 21.1213C17.9086 20.333 17.9897 19.1137 17.9981 16.829C18.3111 16.9397 18.648 17 18.999 17C20.6559 17 21.999 15.6569 21.999 14C21.999 12.3431 20.6559 11 18.999 11C18.648 11 18.3111 11.0603 17.9981 11.171C17.9897 8.88627 17.9086 7.66697 17.1204 6.87868C16.3321 6.09039 15.1128 6.0093 12.828 6.00096Z`,stroke:`currentColor`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}]],Li=[[`path`,{d:`M12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3C15.3313 3 18.2398 4.80989 19.796 7.5`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}],[`path`,{d:`M20.9991 3V4.27816C20.9991 6.47004 20.9991 7.56599 20.2918 8.16512C19.5846 8.76425 18.5036 8.58408 16.3415 8.22373L14.9991 8`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`1`}]],Ri=[[`path`,{d:`M18.7088 3.49534C16.8165 2.55382 14.5009 2 12 2C9.4991 2 7.1835 2.55382 5.29116 3.49534C4.36318 3.95706 3.89919 4.18792 3.4496 4.91378C3 5.63965 3 6.34248 3 7.74814V11.2371C3 16.9205 7.54236 20.0804 10.173 21.4338C10.9067 21.8113 11.2735 22 12 22C12.7265 22 13.0933 21.8113 13.8269 21.4338C16.4576 20.0804 21 16.9205 21 11.2371L21 7.74814C21 6.34249 21 5.63966 20.5504 4.91378C20.1008 4.18791 19.6368 3.95706 18.7088 3.49534Z`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}],[`path`,{d:`M15 11C15 12.6568 13.6569 14 12 14C10.3431 14 9 12.6568 9 11C9 9.34314 10.3431 8 12 8C13.6569 8 15 9.34314 15 11Z`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`1`}]],zi=[[`path`,{d:`M8.12901 11.1313L12.128 6.1907C12.4408 5.80431 13.027 6.0448 13.027 6.55951V10.3836C13.027 10.6919 13.2569 10.9419 13.5405 10.9419H15.4855C15.9274 10.9419 16.1629 11.5083 15.871 11.8689L11.872 16.8095C11.5592 17.1959 10.973 16.9554 10.973 16.4407V12.6167C10.973 12.3083 10.7431 12.0584 10.4595 12.0584H8.51449C8.07264 12.0584 7.83711 11.4919 8.12901 11.1313Z`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}],[`path`,{d:`M21 11.1835V8.28041C21 6.64041 21 5.82041 20.5959 5.28541C20.1918 4.75042 19.2781 4.49068 17.4507 3.97122C16.2022 3.61632 15.1016 3.18875 14.2223 2.79841C13.0234 2.26622 12.424 2.00012 12 2.00012C11.576 2.00012 10.9766 2.26622 9.77771 2.79841C8.89839 3.18875 7.79784 3.61632 6.54933 3.97122C4.72193 4.49068 3.80822 4.75042 3.40411 5.28541C3 5.82041 3 6.64041 3 8.28041V11.1835C3 16.8086 8.06277 20.1836 10.594 21.5195C11.2011 21.8399 11.5046 22.0001 12 22.0001C12.4954 22.0001 12.7989 21.8399 13.406 21.5195C15.9372 20.1836 21 16.8086 21 11.1835Z`,stroke:`currentColor`,strokeLinecap:`round`,strokeWidth:`1.5`,key:`1`}]],Bi=[[`path`,{d:`M3.89124 20.1088C2.5 18.7175 2.5 16.4783 2.5 12C2.5 7.52166 2.5 5.28249 3.89124 3.89124C5.28249 2.5 7.52166 2.5 12 2.5C16.4783 2.5 18.7175 2.5 20.1088 3.89124C21.5 5.28249 21.5 7.52166 21.5 12C21.5 16.4783 21.5 18.7175 20.1088 20.1088C18.7175 21.5 16.4783 21.5 12 21.5C7.52166 21.5 5.28249 21.5 3.89124 20.1088Z`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}],[`path`,{d:`M2.5 9L21.5 9`,stroke:`currentColor`,strokeWidth:`1.5`,key:`1`}],[`path`,{d:`M2.5 13L21.5 13`,stroke:`currentColor`,strokeWidth:`1.5`,key:`2`}],[`path`,{d:`M2.5 17L21.5 17`,stroke:`currentColor`,strokeWidth:`1.5`,key:`3`}],[`path`,{d:`M12 21.5L12 9`,stroke:`currentColor`,strokeLinecap:`round`,strokeWidth:`1.5`,key:`4`}]],Vi=[[`path`,{d:`M12 21C16.9706 21 21 16.9706 21 12C21 7.02944 16.9706 3 12 3C8.66873 3 5.76018 4.80989 4.20404 7.5`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}],[`path`,{d:`M3 3V4.27816C3 6.47004 3 7.56599 3.70725 8.16512C4.4145 8.76425 5.49553 8.58408 7.6576 8.22373L9 8`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`1`}]],Hi=[[`path`,{d:`M8.62814 12.6736H8.16918C6.68545 12.6736 5.94358 12.6736 5.62736 12.1844C5.31114 11.6953 5.61244 11.0138 6.21504 9.65083L8.02668 5.55323C8.57457 4.314 8.84852 3.69438 9.37997 3.34719C9.91142 3 10.5859 3 11.935 3H14.0244C15.6632 3 16.4826 3 16.7916 3.53535C17.1007 4.0707 16.6942 4.78588 15.8811 6.21623L14.8092 8.10188C14.405 8.81295 14.2029 9.16849 14.2057 9.45952C14.2094 9.83775 14.4105 10.1862 14.7354 10.377C14.9854 10.5239 15.3927 10.5239 16.2074 10.5239C17.2373 10.5239 17.7523 10.5239 18.0205 10.7022C18.3689 10.9338 18.5513 11.3482 18.4874 11.7632C18.4382 12.0826 18.0918 12.4656 17.399 13.2317L11.8639 19.3523C10.7767 20.5545 10.2331 21.1556 9.86807 20.9654C9.50303 20.7751 9.67833 19.9822 10.0289 18.3962L10.7157 15.2896C10.9826 14.082 11.1161 13.4782 10.7951 13.0759C10.4741 12.6736 9.85877 12.6736 8.62814 12.6736Z`,stroke:`currentColor`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}]],Ui=e=>!e.isLayoutDirty&&e.willUpdate(!1);function Wi(){let e=new Set,t=new WeakMap,n=()=>e.forEach(Ui);return{add:r=>{e.add(r),t.set(r,r.addEventListener(`willUpdate`,n))},remove:r=>{e.delete(r);let i=t.get(r);i&&(i(),t.delete(r)),n()},dirty:n}}var Z=e(n(),1),Gi=(0,Z.createContext)(null);function Ki(){let e=(0,Z.useRef)(!1);return ai(()=>(e.current=!0,()=>{e.current=!1}),[]),e}function qi(){let e=Ki(),[t,n]=(0,Z.useState)(0),r=(0,Z.useCallback)(()=>{e.current&&n(t+1)},[t]);return[(0,Z.useCallback)(()=>Ur.postRender(r),[r]),t]}var Q=r(),Ji=e=>e===!0,Yi=e=>Ji(e===!0)||e===`id`,Xi=({children:e,id:t,inherit:n=!0})=>{let r=(0,Z.useContext)(Gr),i=(0,Z.useContext)(Gi),[a,o]=qi(),s=(0,Z.useRef)(null),c=r.id||i;s.current===null&&(Yi(n)&&c&&(t=t?c+`-`+t:c),s.current={id:t,group:Ji(n)&&r.group||Wi()});let l=(0,Z.useMemo)(()=>({...s.current,forceRender:a}),[o]);return(0,Q.jsx)(Gr.Provider,{value:l,children:e})};function Zi({children:e,...t}){let n=(0,Z.useContext)(Zr);t={...n,...t},t.transition=Br(t.transition,n.transition),t.isStatic=Vr(()=>t.isStatic);let r=(0,Z.useMemo)(()=>t,[JSON.stringify(t.transition),t.transformPagePoint,t.reducedMotion,t.skipAnimations,t.isValidProp]);return(0,Q.jsx)(Zr.Provider,{value:r,children:e})}var Qi=e(t(),1);function $i({className:e,orientation:t=`horizontal`,...n}){return(0,Q.jsx)(Rr,{"data-slot":`separator`,orientation:t,className:S(`shrink-0 bg-border data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch`,e),...n})}function ea(e){if(e.facet!==`files`)return!1;let t=e.children[0];return e.children.length===1&&t!==void 0&&t.name===e.name}function ta(e){return e===`memory`||e===`fs`||e===`s3`?e:`files`}function na(e){switch(e){case`memory`:return`This process`;case`fs`:return`Local disk`;case`s3`:return`Object store`;default:return`Files driver`}}var ra=[`sql`,`kv`,`files`,`index`];function ia(e){return ra.includes(e)}var aa={sql:`SQL`,kv:`KV`,files:`Files`,index:`Index`},oa={sql:{icon:Ei,label:aa.sql,wellClass:`border-emerald-500/35 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`},kv:{icon:Re,label:aa.kv,wellClass:`border-amber-500/35 bg-amber-500/10 text-amber-700 dark:text-amber-400`},files:{icon:Je,label:aa.files,wellClass:`border-sky-500/35 bg-sky-500/10 text-sky-600 dark:text-sky-400`},index:{icon:ei,label:aa.index,wellClass:`border-violet-500/35 bg-violet-500/10 text-violet-700 dark:text-violet-400`}};function sa(e){return ra.map(t=>({facet:t,label:aa[t],stores:e.filter(e=>e.facet===t).map(e=>({store:e,children:e.children}))})).filter(e=>e.stores.length>0)}function ca(e,t){let n=t.trim().toLowerCase();if(!n)return[...e];let r=[];for(let t of e){let e=t.name.toLowerCase().includes(n)||t.ref.toLowerCase().includes(n)||(t.description?.toLowerCase().includes(n)??!1),i=t.children.filter(t=>e||t.name.toLowerCase().includes(n)||ur(t).toLowerCase().includes(n)||t.effectRef.toLowerCase().includes(n));(e||i.length>0)&&r.push({...t,children:e?t.children:i})}return r}function la(e,t){for(let n of e)for(let e of n.children)if(e.effectRef===t)return{store:n,child:e};return null}function ua(e){if(e.facet===`sql`)return!1;let t=e.children[0];return e.children.length===1&&t!==void 0&&t.name===e.name}function da(e,t){return e===t?null:t}function fa(e){return`facet:${e}`}function pa(e){return`${e}/tables`}function ma(e,t){let n=t[e];return n===void 0?e.startsWith(`facet:`):n}function ha(e){let t=[];for(let n of e){t.push(fa(n.facet));for(let e of n.stores)ua(e.store)||(t.push(e.store.ref),e.store.facet===`sql`&&t.push(pa(e.store.ref)))}return t}function ga(e,t){let n=la(e,t);if(!n)return[];let r=[fa(n.store.facet)];return ua(n.store)?r:(r.push(n.store.ref),n.store.facet===`sql`&&!Kn(n.child)&&r.push(pa(n.store.ref)),r)}function _a(e){for(let t of ra)for(let n of e){if(n.facet!==t)continue;let e=n.children.find(e=>!Kn(e));if(e)return e.effectRef}return null}var va=`oke_store_hidden_facets`;function ya(e){return Array.isArray(e)?new Set(e.filter(e=>typeof e==`string`&&ia(e))):new Set}function ba(){try{if(typeof localStorage>`u`)return new Set;let e=localStorage.getItem(va);return e?ya(JSON.parse(e)):new Set}catch{return new Set}}function xa(e){try{if(typeof localStorage>`u`)return;localStorage.setItem(va,JSON.stringify([...e]))}catch{}}function Sa(e,t){return e.filter(e=>!t.has(e.facet))}var Ca={duration:0},wa={type:`spring`,duration:.4,bounce:.3},Ta={hidden:{},show:{transition:{staggerChildren:.035,delayChildren:.05}}},Ea={hidden:{opacity:0,y:-6,filter:`blur(3px)`},show:{opacity:1,y:0,filter:`blur(0px)`}},Da=(0,Z.createContext)(null);function Oa(e){let t=(0,Z.useContext)(Da);if(!t)throw Error(`${e} must be used within <Select>`);return t}function ka({value:e,defaultValue:t,onValueChange:n,disabled:r=!1,className:i,children:a}){let o=ti()??!1,s=(0,Z.useId)(),c=(0,Z.useRef)(null),[l,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(t),[p,m]=(0,Z.useState)(()=>new Map),[h,g]=(0,Z.useState)(`bottom`),_=e!==void 0,v=_?e:d,y=(0,Z.useCallback)(e=>{_||f(e),n?.(e),u(!1)},[_,n]),b=(0,Z.useCallback)((e,t)=>{m(n=>n.get(e)===t?n:new Map(n).set(e,t))},[]),x=(0,Z.useCallback)(e=>{m(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]);(0,Z.useEffect)(()=>{if(!l)return;let e=e=>{e.key===`Escape`&&u(!1)},t=e=>{c.current&&!c.current.contains(e.target)&&u(!1)};return window.addEventListener(`keydown`,e),window.addEventListener(`pointerdown`,t),()=>{window.removeEventListener(`keydown`,e),window.removeEventListener(`pointerdown`,t)}},[l]);let C=(0,Z.useMemo)(()=>({value:v,open:l,setOpen:u,select:y,register:b,unregister:x,labelFor:e=>e===void 0?void 0:p.get(e),reduce:o,triggerId:`${s}-trigger`,listId:`${s}-list`,disabled:r,placement:h,setPlacement:g}),[v,l,y,b,x,p,o,s,r,h]);return(0,Q.jsx)(Da.Provider,{value:C,children:(0,Q.jsx)(`div`,{ref:c,className:S(`relative`,i),"data-slot":`motion-select`,children:a})})}function Aa({className:e,children:t,"aria-label":n,flat:r=!1}){let i=Oa(`SelectTrigger`),a=i.placement===`top`,o=i.open?[0,0,12]:[12,0,12],s=i.reduce?{duration:0}:i.open?{duration:.6,times:[0,.4,1],ease:Wr}:{duration:.42,times:[0,.5,1],ease:Wr};return(0,Q.jsxs)(Xr.button,{type:`button`,id:i.triggerId,disabled:i.disabled,"aria-label":n,"aria-haspopup":`listbox`,"aria-expanded":i.open,"aria-controls":i.listId,onClick:()=>i.setOpen(!i.open),initial:!1,animate:r?{borderTopLeftRadius:0,borderTopRightRadius:0,borderBottomLeftRadius:0,borderBottomRightRadius:0}:{borderTopLeftRadius:a?o:12,borderTopRightRadius:a?o:12,borderBottomLeftRadius:a?12:o,borderBottomRightRadius:a?12:o},transition:{borderTopLeftRadius:a?s:Ca,borderTopRightRadius:a?s:Ca,borderBottomLeftRadius:a?Ca:s,borderBottomRightRadius:a?Ca:s},className:S(`relative z-10 flex w-full items-center justify-between gap-2 text-sm text-foreground outline-none transition-colors`,`disabled:pointer-events-none disabled:opacity-50`,r?`rounded-none border-0 bg-transparent px-4 py-0 shadow-none hover:bg-transparent focus-visible:ring-0`:`rounded-xl border border-border bg-background px-3 py-2 hover:border-border focus-visible:ring-2 focus-visible:ring-ring/50`,e),children:[t,(0,Q.jsx)(Xr.span,{"aria-hidden":!0,animate:{rotate:i.open?180:0},transition:i.reduce?{duration:0}:wa,className:`text-muted-foreground`,children:(0,Q.jsx)(b,{icon:et,className:`size-3.5`})})]})}function ja({placeholder:e,className:t}){let n=Oa(`SelectValue`),r=n.labelFor(n.value);return(0,Q.jsx)(`span`,{className:S(r?`text-foreground`:`text-muted-foreground`,t),children:r??e??`Select`})}function Ma({className:e,children:t}){let n=Oa(`SelectContent`),r=(0,Z.useRef)(null),[i,a]=(0,Z.useState)(0),o=n.open,{setPlacement:s}=n;(0,Z.useLayoutEffect)(()=>{let e=r.current;if(!e)return;let t=()=>a(e.offsetHeight);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()}),(0,Z.useLayoutEffect)(()=>{if(!o)return;let e=document.getElementById(n.triggerId),t=r.current;if(!e||!t)return;let i=e.getBoundingClientRect(),a=t.offsetHeight,c=window.innerHeight-i.bottom,l=i.top;s(c<a+16&&l>c?`top`:`bottom`)},[o,n.triggerId,s]);let c=n.placement===`top`,l=o?8:0,u=o?12:0,d=o?{type:`spring`,duration:.6,bounce:.5,delay:.12}:{type:`spring`,duration:.3,bounce:.1},f=o?{duration:.3,ease:Wr,delay:.14}:{duration:.16,ease:Wr};return(0,Q.jsx)(Xr.div,{id:n.listId,role:`listbox`,"aria-labelledby":n.triggerId,"aria-hidden":!o,inert:!o,initial:!1,animate:n.reduce?{opacity:+!!o,height:o?i:0}:{opacity:+!!o,height:o?i:0,marginTop:c?0:l,marginBottom:c?l:0,borderTopLeftRadius:c?12:u,borderTopRightRadius:c?12:u,borderBottomLeftRadius:c?u:12,borderBottomRightRadius:c?u:12},transition:n.reduce?{duration:.12}:{opacity:o?{duration:.18}:{duration:.16,delay:.12},height:o?{type:`spring`,duration:.42,bounce:.14}:{duration:.26,ease:Wr,delay:.14},marginTop:c?Ca:d,marginBottom:c?d:Ca,borderTopLeftRadius:c?Ca:f,borderTopRightRadius:c?Ca:f,borderBottomLeftRadius:c?f:Ca,borderBottomRightRadius:c?f:Ca},style:{transformOrigin:c?`bottom`:`top`,overflow:`hidden`,pointerEvents:o?`auto`:`none`},className:S(`absolute right-0 left-0 z-20 rounded-xl border border-border bg-background shadow-lg`,c?`bottom-full`:`top-full`,e),children:(0,Q.jsx)(Xr.div,{ref:r,variants:n.reduce?void 0:Ta,initial:!1,animate:o?`show`:`hidden`,className:`p-1`,children:t})})}function Na({value:e,disabled:t=!1,className:n,children:r}){let i=Oa(`SelectItem`),a=i.value===e,o=typeof r==`string`?r:e,s=i.register,c=i.unregister;return(0,Z.useLayoutEffect)(()=>(s(e,o),()=>c(e)),[s,c,e,o]),(0,Q.jsx)(Xr.li,{variants:i.reduce?void 0:Ea,children:(0,Q.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":a,disabled:t,onClick:()=>i.select(e),className:S(`flex w-full items-center justify-between gap-2 rounded-lg px-2.5 py-1.5 text-left text-sm outline-none transition-colors`,a?`bg-muted text-foreground`:`text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:bg-muted`,`disabled:pointer-events-none disabled:opacity-50`,n),children:[r,a?(0,Q.jsx)(b,{icon:D,className:`size-3.5 shrink-0`,"aria-hidden":!0}):null]})})}function Pa(e){if(!e.error)return null;let t=Error(e.error.message??e.error.code);return t.code=e.error.code,t.data=e.error.data,t}function Fa(){let e=te();return Yr({mutationFn:async e=>{let t=await se(e),n=Pa(t);if(n)throw n;if(!t.data)throw Error(`Empty store edit`);return t.data},onSuccess:async(t,n)=>{n.commit&&await Promise.all([e.invalidateQueries({queryKey:_r}),e.invalidateQueries({queryKey:Dt})])}})}function Ia(){let e=te();return Yr({mutationFn:async e=>{let t=await L(e),n=Pa(t);if(n)throw n;if(!t.data)throw Error(`Empty store delete`);return t.data},onSuccess:async()=>{await Promise.all([e.invalidateQueries({queryKey:_r}),e.invalidateQueries({queryKey:Dt})])}})}var La={type:`spring`,stiffness:800,damping:80,mass:4};function Ra({checked:e,onCheckedChange:t,disabled:n,label:r,ariaLabel:i,className:a,size:o=`default`}){let s=(0,Z.useId)(),c=(0,Z.useRef)(null),l=ti(),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(!1),m=o===`sm`;(0,Z.useEffect)(()=>{c.current&&!l&&n&&u&&ot(c.current,{x:[0,-2,2,-1,0]},{delay:.2,duration:.6})},[n,u,l]);let h=!n&&f&&u&&!l;return(0,Q.jsx)(Zi,{transition:l?{duration:0}:La,children:(0,Q.jsxs)(`span`,{className:S(`inline-flex items-center gap-2`,a),children:[(0,Q.jsx)(Xr.button,{id:s,type:`button`,role:`switch`,"aria-checked":e,"aria-label":i,disabled:n,onClick:()=>{n||t(!e)},onPointerDown:()=>{d(!0),p(!0)},onPointerUp:()=>d(!1),onPointerLeave:()=>d(!1),initial:!1,"data-state":e?`checked`:`unchecked`,className:S(`group peer inline-flex shrink-0 cursor-pointer items-center rounded-full outline-none transition-colors duration-200`,`focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background`,`disabled:cursor-not-allowed disabled:opacity-60`,m?`h-4 w-7 px-0.5`:`h-7 w-12 px-1`,e?`justify-end bg-primary`:`justify-start bg-muted-foreground/60`),children:(0,Q.jsx)(Xr.div,{ref:c,layout:!0,animate:{scale:h?.9:1},className:S(`pointer-events-none block rounded-full bg-background shadow-md`,m?`h-3 w-3`:`h-5 w-5`),children:(0,Q.jsx)(`div`,{className:S(m?`size-3`:`size-5`,h&&(e?`ml-1`:`mr-1`)),"aria-hidden":!0})})}),r?(0,Q.jsx)(`label`,{htmlFor:s,className:`text-sm`,children:r}):null]})})}function za({open:e,extraCount:t=0,onOpenChange:n,controls:r}){return(0,Q.jsxs)(vi,{active:e||t>0,extraCount:t,"aria-expanded":e,"aria-controls":r,onClick:()=>n(!e),children:[(0,Q.jsx)(b,{icon:gn,className:`size-3`,"aria-hidden":!0}),`Advanced`]})}function Ba({templates:e,selectedId:t,onSelect:n}){let r=e.find(e=>e.id===t)??null;return(0,Q.jsx)(_i,{label:`Templates`,hint:r?.detail??`Pick a starter, or fill the fields.`,children:e.map(e=>(0,Q.jsx)(fi,{active:e.id===t,onClick:()=>n(e),children:e.title},e.id))})}var Va=[{name:`plpgsql`,version:`1.0`,comment:`PL/pgSQL procedural language`,source:`builtin`,category:`language`},{name:`pgcrypto`,version:`1.3`,comment:`Cryptographic functions`,source:`builtin`,category:`contrib`},{name:`uuid-ossp`,version:`1.1`,comment:`UUID generation (OSSP)`,source:`builtin`,category:`contrib`},{name:`citext`,version:`1.6`,comment:`Case-insensitive text`,source:`builtin`,category:`contrib`},{name:`hstore`,version:`1.8`,comment:`Key-value store in a column`,source:`builtin`,category:`contrib`},{name:`pg_trgm`,version:`1.6`,comment:`Trigram text similarity`,source:`builtin`,category:`contrib`},{name:`btree_gin`,version:`1.3`,comment:`GIN support for common types`,source:`builtin`,category:`contrib`},{name:`btree_gist`,version:`1.7`,comment:`GiST support for common types`,source:`builtin`,category:`contrib`},{name:`unaccent`,version:`1.1`,comment:`Text search dictionary that removes accents`,source:`builtin`,category:`contrib`},{name:`ltree`,version:`1.3`,comment:`Hierarchical tree-like data type`,source:`builtin`,category:`contrib`},{name:`cube`,version:`1.5`,comment:`Multidimensional cubes`,source:`builtin`,category:`contrib`},{name:`earthdistance`,version:`1.2`,comment:`Great-circle distances on Earth`,source:`builtin`,category:`contrib`},{name:`fuzzystrmatch`,version:`1.2`,comment:`Fuzzy string matching`,source:`builtin`,category:`contrib`},{name:`intarray`,version:`1.5`,comment:`Functions for 1-D arrays of integers`,source:`builtin`,category:`contrib`},{name:`isn`,version:`1.2`,comment:`International product numbering types`,source:`builtin`,category:`contrib`},{name:`lo`,version:`1.1`,comment:`Large Object maintenance`,source:`builtin`,category:`contrib`},{name:`tablefunc`,version:`1.0`,comment:`Crosstab and table functions`,source:`builtin`,category:`contrib`},{name:`tcn`,version:`1.0`,comment:`Triggered change notifications`,source:`builtin`,category:`contrib`},{name:`tsm_system_rows`,version:`1.0`,comment:`TABLESAMPLE method SYSTEM_ROWS`,source:`builtin`,category:`contrib`},{name:`tsm_system_time`,version:`1.0`,comment:`TABLESAMPLE method SYSTEM_TIME`,source:`builtin`,category:`contrib`},{name:`xml2`,version:`1.1`,comment:`XPath querying and XSLT`,source:`builtin`,category:`contrib`},{name:`postgres_fdw`,version:`1.1`,comment:`Foreign-data wrapper for PostgreSQL`,source:`builtin`,category:`contrib`},{name:`file_fdw`,version:`1.0`,comment:`Foreign-data wrapper for files`,source:`builtin`,category:`contrib`},{name:`dblink`,version:`1.2`,comment:`Connect to other PostgreSQL databases`,source:`builtin`,category:`contrib`},{name:`amcheck`,version:`1.4`,comment:`Verify relation integrity`,source:`builtin`,category:`contrib`},{name:`bloom`,version:`1.0`,comment:`Bloom-filter index access method`,source:`builtin`,category:`contrib`},{name:`dict_int`,version:`1.0`,comment:`Text search dictionary for integers`,source:`builtin`,category:`contrib`},{name:`dict_xsyn`,version:`1.0`,comment:`Text search dictionary for extended synonym`,source:`builtin`,category:`contrib`},{name:`pageinspect`,version:`1.12`,comment:`Inspect contents of database pages`,source:`builtin`,category:`contrib`},{name:`pg_buffercache`,version:`1.5`,comment:`Examine shared buffer cache`,source:`builtin`,category:`contrib`},{name:`pg_freespacemap`,version:`1.2`,comment:`Examine the free space map`,source:`builtin`,category:`contrib`},{name:`pg_prewarm`,version:`1.2`,comment:`Prewarm relation data`,source:`builtin`,category:`contrib`},{name:`pg_stat_statements`,version:`1.11`,comment:`Track planning and execution statistics`,source:`builtin`,category:`contrib`},{name:`pg_surgery`,version:`1.0`,comment:`Low-level heap surgery`,source:`builtin`,category:`contrib`},{name:`pg_visibility`,version:`1.2`,comment:`Examine visibility map`,source:`builtin`,category:`contrib`},{name:`pgrowlocks`,version:`1.2`,comment:`Show row-level locking information`,source:`builtin`,category:`contrib`},{name:`pgstattuple`,version:`1.5`,comment:`Tuple-level statistics`,source:`builtin`,category:`contrib`},{name:`sslinfo`,version:`1.2`,comment:`Information about SSL certificates`,source:`builtin`,category:`contrib`},{name:`vector`,version:`0.8.6`,comment:`Vector similarity search (pgvector)`,source:`builtin`,category:`search`}];function $(e,t,n,r,i,a){return{name:e,version:t,comment:n,source:`library`,category:r,tags:i,...a&&a.length>0?{requires:a}:{}}}var Ha=[$(`timescaledb`,`2.17.0`,`Time-series hypertables, compression, and continuous aggregates`,`time`,[`timescale`,`hypertable`,`iot`,`metrics`]),$(`timescaledb_toolkit`,`1.19.0`,`Timescale hyperfunctions — locf, gapfill, stats`,`time`,[`timescale`,`hyperfunctions`,`analytics`],[`timescaledb`]),$(`pg_partman`,`5.2.0`,`Partition maintenance for time- and serial-based tables`,`time`,[`partition`,`retention`]),$(`pg_ivm`,`1.9`,`Incremental view maintenance for materialized views`,`time`,[`materialized`,`ivm`,`refresh`]),$(`temporal_tables`,`1.2.2`,`System-period temporal tables (SQL:2011 style)`,`time`,[`history`,`versioning`,`audit`]),$(`pg_cron`,`1.6`,`Cron-based job scheduler inside the database`,`jobs`,[`cron`,`schedule`,`jobs`]),$(`pg_later`,`0.3.0`,`Fire-and-forget SQL jobs after the current transaction`,`jobs`,[`async`,`queue`,`later`]),$(`pg_background`,`1.2`,`Run commands in a background worker`,`jobs`,[`worker`,`background`]),$(`postgis`,`3.5.0`,`Geographic objects and spatial indexes`,`geo`,[`gis`,`geo`,`geometry`,`geography`,`spatial`]),$(`postgis_topology`,`3.5.0`,`PostGIS topology types and functions`,`geo`,[`gis`,`topology`],[`postgis`]),$(`postgis_raster`,`3.5.0`,`PostGIS raster types and functions`,`geo`,[`gis`,`raster`,`coverage`],[`postgis`]),$(`postgis_sfcgal`,`3.5.0`,`3D / solid geometry via SFCGAL`,`geo`,[`gis`,`3d`,`sfcgal`],[`postgis`]),$(`address_standardizer`,`3.5.0`,`Parse and normalize street addresses`,`geo`,[`gis`,`geocode`,`address`]),$(`postgis_tiger_geocoder`,`3.5.0`,`TIGER geocoder for US addresses`,`geo`,[`gis`,`geocode`,`tiger`],[`postgis`,`address_standardizer`]),$(`pgrouting`,`3.7.0`,`Routing algorithms on PostGIS networks`,`geo`,[`gis`,`routing`,`shortest-path`],[`postgis`]),$(`h3`,`4.1.0`,`Uber H3 hexagonal hierarchical spatial index`,`geo`,[`gis`,`hex`,`uber`]),$(`mobilitydb`,`1.2.0`,`Temporal and spatiotemporal types for moving objects`,`geo`,[`gis`,`trajectory`,`temporal`],[`postgis`]),$(`pointcloud`,`1.2.5`,`LIDAR / point-cloud storage (PDAL)`,`geo`,[`gis`,`lidar`,`pdal`]),$(`rum`,`1.3`,`GIN-like access method for faster full-text search`,`search`,[`fts`,`full-text`,`gin`]),$(`pg_search`,`0.15.0`,`ParadeDB BM25 full-text search`,`search`,[`paradedb`,`bm25`,`fts`]),$(`pgroonga`,`3.2.5`,`Groonga full-text search (CJK-friendly)`,`search`,[`fts`,`cjk`,`japanese`]),$(`pg_bigm`,`1.2`,`Bigram full-text search (LIKE acceleration)`,`search`,[`fts`,`bigram`,`like`]),$(`zhparser`,`2.2`,`Chinese text search parser`,`search`,[`fts`,`chinese`,`cjk`]),$(`zombodb`,`3000.2.7`,`Elasticsearch-backed indexes from Postgres`,`search`,[`elasticsearch`,`fts`]),$(`vchord`,`0.4.3`,`VectorChord — disk-based vector index`,`search`,[`vector`,`embedding`,`ann`]),$(`vectorscale`,`0.7.1`,`Timescale vector index (StreamingDiskANN)`,`search`,[`vector`,`timescale`,`ann`]),$(`age`,`1.5.0`,`Apache AGE graph queries (openCypher)`,`graph`,[`graph`,`cypher`,`opencypher`]),$(`citus`,`12.1`,`Distributed Postgres — shard and scale out`,`scale`,[`shard`,`distributed`,`microsoft`]),$(`citus_columnar`,`12.1`,`Citus columnar storage for analytics`,`scale`,[`columnar`,`olap`,`citus`],[`citus`]),$(`pg_repack`,`1.5.1`,`Online table bloat cleanup without exclusive locks`,`scale`,[`bloat`,`vacuum`,`reindex`]),$(`pg_squeeze`,`1.8`,`Automatic bloat cleanup as a background worker`,`scale`,[`bloat`,`vacuum`]),$(`hypopg`,`1.4.1`,`Hypothetical indexes for EXPLAIN without creating them`,`scale`,[`explain`,`index`,`what-if`]),$(`index_advisor`,`0.2.0`,`Suggest indexes from a query via hypothetical indexes`,`scale`,[`index`,`advisor`,`hypopg`],[`hypopg`]),$(`pg_hint_plan`,`1.7.0`,`Planner hints in SQL comments`,`scale`,[`planner`,`hint`,`explain`]),$(`pg_stat_kcache`,`2.3.0`,`Filesystem and CPU stats per query`,`scale`,[`stats`,`observability`]),$(`pg_qualstats`,`2.1.1`,`Predicate statistics for missing-index hints`,`scale`,[`stats`,`index`]),$(`pg_wait_sampling`,`1.1.6`,`Sample wait events for lock analysis`,`scale`,[`waits`,`locks`,`observability`]),$(`pg_stat_monitor`,`2.1.0`,`Percona query-performance monitor`,`scale`,[`stats`,`percona`,`observability`]),$(`pgaudit`,`17.0`,`Session and object audit logging`,`security`,[`audit`,`compliance`,`logging`]),$(`pgsodium`,`3.1.9`,`Libsodium cryptography helpers`,`security`,[`crypto`,`encryption`,`libsodium`]),$(`pgjwt`,`0.2.0`,`Create and verify JSON Web Tokens in SQL`,`security`,[`jwt`,`auth`,`token`]),$(`anon`,`2.1.0`,`PostgreSQL Anonymizer — masking and dumping`,`security`,[`pii`,`mask`,`gdpr`,`anonymizer`]),$(`credcheck`,`2.8`,`Password complexity and reuse checks`,`security`,[`password`,`auth`]),$(`set_user`,`4.1.0`,`Privilege bridging with audit trail`,`security`,[`sudo`,`privilege`,`audit`]),$(`pg_tle`,`1.5.0`,`Trusted Language Extensions (AWS)`,`security`,[`tle`,`aws`,`sandbox`]),$(`pg_net`,`0.14.0`,`Async HTTP from SQL (Supabase)`,`http`,[`http`,`webhook`,`supabase`]),$(`http`,`1.6`,`Synchronous HTTP client from SQL`,`http`,[`http`,`rest`,`curl`]),$(`wrappers`,`0.4.5`,`Supabase FDW framework (Stripe, Firebase, S3…)`,`http`,[`fdw`,`supabase`,`stripe`]),$(`pg_graphql`,`1.5.11`,`GraphQL API generated from the schema`,`http`,[`graphql`,`api`,`supabase`]),$(`pgmq`,`1.5.1`,`Lightweight message queue in Postgres`,`http`,[`queue`,`mq`,`jobs`]),$(`pg_jsonschema`,`0.3.3`,`Validate JSON against JSON Schema`,`http`,[`json`,`schema`,`validate`]),$(`mysql_fdw`,`1.2`,`Foreign-data wrapper for MySQL / MariaDB`,`fdw`,[`mysql`,`mariadb`,`fdw`]),$(`mongo_fdw`,`5.5.2`,`Foreign-data wrapper for MongoDB`,`fdw`,[`mongodb`,`fdw`]),$(`tds_fdw`,`2.0.4`,`Foreign-data wrapper for SQL Server / Sybase`,`fdw`,[`mssql`,`sqlserver`,`fdw`]),$(`oracle_fdw`,`2.7.0`,`Foreign-data wrapper for Oracle`,`fdw`,[`oracle`,`fdw`]),$(`sqlite_fdw`,`2.5.0`,`Foreign-data wrapper for SQLite`,`fdw`,[`sqlite`,`fdw`]),$(`redis_fdw`,`1.0`,`Foreign-data wrapper for Redis`,`fdw`,[`redis`,`fdw`]),$(`duckdb_fdw`,`1.1.0`,`Foreign-data wrapper for DuckDB`,`fdw`,[`duckdb`,`olap`,`fdw`]),$(`pg_duckdb`,`0.3.0`,`DuckDB engine inside Postgres`,`fdw`,[`duckdb`,`olap`,`analytics`]),$(`ogr_fdw`,`1.1.5`,`GDAL/OGR spatial foreign tables`,`fdw`,[`gis`,`gdal`,`shapefile`,`fdw`]),$(`plpython3u`,`1.0`,`Untrusted Python 3 procedural language`,`lang`,[`python`,`pl`]),$(`plperl`,`1.0`,`Perl procedural language`,`lang`,[`perl`,`pl`]),$(`pltcl`,`1.0`,`Tcl procedural language`,`lang`,[`tcl`,`pl`]),$(`plv8`,`3.2.3`,`JavaScript (V8) procedural language`,`lang`,[`javascript`,`v8`,`pl`]),$(`plrust`,`1.2.8`,`Trusted Rust procedural language`,`lang`,[`rust`,`pl`]),$(`plpgsql_check`,`2.7.15`,`Static analysis for PL/pgSQL functions`,`lang`,[`lint`,`plpgsql`]),$(`hll`,`2.18`,`HyperLogLog distinct-count sketches`,`analytics`,[`cardinality`,`sketch`,`approx`]),$(`tdigest`,`1.4.2`,`t-digest quantiles and percentiles`,`analytics`,[`quantile`,`percentile`,`sketch`]),$(`topn`,`2.7.0`,`Approximate most-frequent values`,`analytics`,[`topk`,`sketch`,`timescale`]),$(`datasketches`,`1.7.0`,`Apache DataSketches — HLL, Theta, KLL`,`analytics`,[`sketch`,`apache`,`approx`]),$(`pg_uuidv7`,`1.6.0`,`UUIDv7 generators (time-ordered)`,`analytics`,[`uuid`,`id`]),$(`pg_idkit`,`0.2.4`,`UUID, ULID, KSUID, TypeID generators`,`analytics`,[`uuid`,`ulid`,`ksuid`]),$(`pg_hashids`,`1.3.0`,`YouTube-style hashids from integers`,`analytics`,[`hashid`,`shortid`])];[...Va,...Ha];function Ua(e){return/^[0-9]+(\.[0-9]+)*$/.test(e)}var Wa={plpgsql:`PL/pgSQL`,pgcrypto:`Crypto`,"uuid-ossp":`UUID OSSP`,citext:`CIText`,hstore:`Hstore`,pg_trgm:`Trigram`,btree_gin:`B-tree GIN`,btree_gist:`B-tree GiST`,unaccent:`Unaccent`,ltree:`Ltree`,cube:`Cube`,earthdistance:`Earth Distance`,fuzzystrmatch:`Fuzzy Match`,intarray:`Intarray`,isn:`ISN`,lo:`Large Objects`,tablefunc:`Tablefunc`,tcn:`TCN`,tsm_system_rows:`System Rows`,tsm_system_time:`System Time`,xml2:`XML2`,postgres_fdw:`Postgres FDW`,file_fdw:`File FDW`,dblink:`DB Link`,amcheck:`AM Check`,bloom:`Bloom`,dict_int:`Dict Int`,dict_xsyn:`Dict Xsyn`,pageinspect:`Page Inspect`,pg_buffercache:`Buffer Cache`,pg_freespacemap:`Free Space Map`,pg_prewarm:`Prewarm`,pg_stat_statements:`Stat Statements`,pg_surgery:`Surgery`,pg_visibility:`Visibility`,pgrowlocks:`Row Locks`,pgstattuple:`Stat Tuple`,sslinfo:`SSL Info`,vector:`pgvector`,timescaledb:`Timescale`,timescaledb_toolkit:`Timescale Toolkit`,pg_partman:`Partman`,pg_ivm:`IVM`,temporal_tables:`Temporal Tables`,pg_cron:`Cron`,pg_later:`Later`,pg_background:`Background`,postgis:`PostGIS`,postgis_topology:`PostGIS Topology`,postgis_raster:`PostGIS Raster`,postgis_sfcgal:`PostGIS SFCGAL`,address_standardizer:`Address Standardizer`,postgis_tiger_geocoder:`PostGIS Tiger Geocoder`,pgrouting:`pgRouting`,h3:`H3`,mobilitydb:`MobilityDB`,pointcloud:`Pointcloud`,rum:`RUM`,pg_search:`ParadeDB Search`,pgroonga:`PGroonga`,pg_bigm:`Bigm`,zhparser:`Zhparser`,zombodb:`ZomboDB`,vchord:`VectorChord`,vectorscale:`Vectorscale`,age:`Apache AGE`,citus:`Citus`,citus_columnar:`Citus Columnar`,pg_repack:`Repack`,pg_squeeze:`Squeeze`,hypopg:`HypoPG`,index_advisor:`Index Advisor`,pg_hint_plan:`Hint Plan`,pg_stat_kcache:`Stat Kcache`,pg_qualstats:`Qualstats`,pg_wait_sampling:`Wait Sampling`,pg_stat_monitor:`Stat Monitor`,pgaudit:`pgAudit`,pgsodium:`Sodium`,pgjwt:`JWT`,anon:`Anonymizer`,credcheck:`Credcheck`,set_user:`Set User`,pg_tle:`TLE`,pg_net:`Net`,http:`HTTP`,wrappers:`Wrappers`,pg_graphql:`GraphQL`,pgmq:`Queues`,pg_jsonschema:`JSON Schema`,mysql_fdw:`MySQL FDW`,mongo_fdw:`MongoDB FDW`,tds_fdw:`TDS FDW`,oracle_fdw:`Oracle FDW`,sqlite_fdw:`SQLite FDW`,redis_fdw:`Redis FDW`,duckdb_fdw:`DuckDB FDW`,pg_duckdb:`DuckDB`,ogr_fdw:`OGR FDW`,plpython3u:`PL/Python 3`,plperl:`PL/Perl`,pltcl:`PL/Tcl`,plv8:`PL/V8`,plrust:`PL/Rust`,plpgsql_check:`PL/pgSQL Check`,hll:`HyperLogLog`,tdigest:`t-digest`,topn:`TopN`,datasketches:`DataSketches`,pg_uuidv7:`UUIDv7`,pg_idkit:`IDkit`,pg_hashids:`Hashids`},Ga={fdw:`FDW`,jwt:`JWT`,http:`HTTP`,ivm:`IVM`,tle:`TLE`,hll:`HLL`,age:`AGE`,rum:`RUM`,h3:`H3`,postgis:`PostGIS`,duckdb:`DuckDB`,gin:`GIN`,gist:`GiST`};function Ka(e){return Wa[e]||e.replace(/^pg_/,``).split(/[_-]+/).filter(e=>e.length>0).map(e=>Ga[e]??e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}var qa=`https://www.postgresql.org/docs/current`,Ja={plpgsql:`plpgsql`,pgcrypto:`pgcrypto`,"uuid-ossp":`uuid-ossp`,citext:`citext`,hstore:`hstore`,pg_trgm:`pgtrgm`,btree_gin:`btree-gin`,btree_gist:`btree-gist`,unaccent:`unaccent`,ltree:`ltree`,cube:`cube`,earthdistance:`earthdistance`,fuzzystrmatch:`fuzzystrmatch`,intarray:`intarray`,isn:`isn`,lo:`lo`,tablefunc:`tablefunc`,tcn:`tcn`,tsm_system_rows:`tsm-system-rows`,tsm_system_time:`tsm-system-time`,xml2:`xml2`,postgres_fdw:`postgres-fdw`,file_fdw:`file-fdw`,dblink:`dblink`,amcheck:`amcheck`,bloom:`bloom`,dict_int:`dict-int`,dict_xsyn:`dict-xsyn`,pageinspect:`pageinspect`,pg_buffercache:`pgbuffercache`,pg_freespacemap:`pgfreespacemap`,pg_prewarm:`pgprewarm`,pg_stat_statements:`pgstatstatements`,pg_surgery:`pgsurgery`,pg_visibility:`pgvisibility`,pgrowlocks:`pgrowlocks`,pgstattuple:`pgstattuple`,sslinfo:`sslinfo`,plpython3u:`plpython`,plperl:`plperl`,pltcl:`pltcl`},Ya={vector:`https://github.com/pgvector/pgvector`,timescaledb:`https://github.com/timescale/timescaledb`,timescaledb_toolkit:`https://github.com/timescale/timescaledb-toolkit`,pg_partman:`https://github.com/pgpartman/pg_partman`,pg_ivm:`https://github.com/sraoss/pg_ivm`,temporal_tables:`https://github.com/arkhipov/temporal_tables`,pg_cron:`https://github.com/citusdata/pg_cron`,pg_later:`https://github.com/supabase/pg_later`,pg_background:`https://github.com/vibhorkum/pg_background`,postgis:`https://postgis.net`,postgis_topology:`https://postgis.net/docs/Topology.html`,postgis_raster:`https://postgis.net/docs/RT_reference.html`,postgis_sfcgal:`https://postgis.net/docs/reference.html#reference_sfcgal`,address_standardizer:`https://postgis.net/docs/manual-dev/Address_Standardizer.html`,postgis_tiger_geocoder:`https://postgis.net/docs/Extras.html#Tiger_Geocoder`,pgrouting:`https://pgrouting.org`,h3:`https://github.com/zachasme/h3-pg`,mobilitydb:`https://github.com/MobilityDB/MobilityDB`,pointcloud:`https://github.com/pgpointcloud/pointcloud`,rum:`https://github.com/postgrespro/rum`,pg_search:`https://github.com/paradedb/paradedb`,pgroonga:`https://pgroonga.github.io`,pg_bigm:`https://github.com/pgbigm/pg_bigm`,zhparser:`https://github.com/amutu/zhparser`,zombodb:`https://github.com/zombodb/zombodb`,vchord:`https://github.com/tensorchord/VectorChord`,vectorscale:`https://github.com/timescale/pgvectorscale`,age:`https://age.apache.org`,citus:`https://github.com/citusdata/citus`,citus_columnar:`https://github.com/citusdata/citus`,pg_repack:`https://github.com/reorg/pg_repack`,pg_squeeze:`https://github.com/cybertec-postgresql/pg_squeeze`,hypopg:`https://github.com/HypoPG/hypopg`,index_advisor:`https://github.com/supabase/index_advisor`,pg_hint_plan:`https://github.com/ossc-db/pg_hint_plan`,pg_stat_kcache:`https://github.com/powa-team/pg_stat_kcache`,pg_qualstats:`https://github.com/powa-team/pg_qualstats`,pg_wait_sampling:`https://github.com/postgrespro/pg_wait_sampling`,pg_stat_monitor:`https://github.com/percona/pg_stat_monitor`,pgaudit:`https://github.com/pgaudit/pgaudit`,pgsodium:`https://github.com/michelp/pgsodium`,pgjwt:`https://github.com/michelp/pgjwt`,anon:`https://postgresql-anonymizer.readthedocs.io`,credcheck:`https://github.com/HexaCluster/credcheck`,set_user:`https://github.com/pgaudit/set_user`,pg_tle:`https://github.com/aws/pg_tle`,pg_net:`https://github.com/supabase/pg_net`,http:`https://github.com/pramsey/pgsql-http`,wrappers:`https://github.com/supabase/wrappers`,pg_graphql:`https://github.com/supabase/pg_graphql`,pgmq:`https://github.com/pgmq/pgmq`,pg_jsonschema:`https://github.com/supabase/pg_jsonschema`,mysql_fdw:`https://github.com/enterprisedb/mysql_fdw`,mongo_fdw:`https://github.com/enterprisedb/mongo_fdw`,tds_fdw:`https://github.com/tds-fdw/tds_fdw`,oracle_fdw:`https://github.com/laurenz/oracle_fdw`,sqlite_fdw:`https://github.com/pgspider/sqlite_fdw`,redis_fdw:`https://github.com/pg-redis-fdw/redis_fdw`,duckdb_fdw:`https://github.com/alitrack/duckdb_fdw`,pg_duckdb:`https://github.com/duckdb/pg_duckdb`,ogr_fdw:`https://github.com/pramsey/pgsql-ogr-fdw`,plv8:`https://github.com/plv8/plv8`,plrust:`https://github.com/tcdi/plrust`,plpgsql_check:`https://github.com/okbob/plpgsql_check`,hll:`https://github.com/citusdata/postgresql-hll`,tdigest:`https://github.com/tvondra/tdigest`,topn:`https://github.com/timescale/pg_topn`,datasketches:`https://github.com/apache/datasketches-postgresql`,pg_uuidv7:`https://github.com/fboulnois/pg_uuidv7`,pg_idkit:`https://github.com/gaeljw/pg_idkit`,pg_hashids:`https://github.com/iCyberon/pg_hashids`};function Xa(e){let t=Ya[e];if(t)return t;let n=Ja[e];return n?`${qa}/${n}.html`:null}var Za={language:`Language`,contrib:`Contrib`,time:`Time series`,geo:`Geospatial`,jobs:`Jobs`,search:`Search`,graph:`Graph`,scale:`Scale`,security:`Security`,http:`HTTP`,fdw:`Foreign data`,lang:`Languages`,analytics:`Analytics`};function Qa(e){return`"${e.replaceAll(`"`,``)}"`}var $a=Ka,eo=[`timescaledb`,`pg_cron`,`postgis`],to={timescaledb:`Timescale`,timescaledb_toolkit:`Timescale`,vectorscale:`Timescale`,topn:`Timescale`,pg_cron:`Citus Data`,citus:`Microsoft`,citus_columnar:`Microsoft`,postgis:`PostGIS Project`,postgis_topology:`PostGIS Project`,postgis_raster:`PostGIS Project`,postgis_sfcgal:`PostGIS Project`,postgis_tiger_geocoder:`PostGIS Project`,pgrouting:`pgRouting`,pg_search:`ParadeDB`,pgmq:`pgmq`,pg_net:`Supabase`,index_advisor:`Supabase`,wrappers:`Supabase`,pg_graphql:`Supabase`,age:`Apache`,datasketches:`Apache`,pg_duckdb:`DuckDB`,duckdb_fdw:`DuckDB`,anon:`PostgreSQL Anonymizer`,pg_stat_monitor:`Percona`};function no(e){return to[e]}function ro(e){let t=new Map(e.map(e=>[e.name,e]));return eo.flatMap(e=>{let n=t.get(e);return n?[n]:[]})}var io=[`time`,`jobs`,`geo`,`search`,`graph`,`scale`,`security`,`http`,`fdw`,`lang`,`analytics`];function ao(e){return[e.name,$a(e.name),e.comment,e.category,Za[e.category],...e.tags??[],...e.requires??[]].join(` `).toLowerCase()}function oo(e,t){let n=t.trim().toLowerCase().split(/\s+/).filter(e=>e.length>0);return n.length===0?e:e.filter(e=>{let t=ao(e);return n.every(e=>t.includes(e))})}function so(e){return io.flatMap(t=>{let n=e.filter(e=>e.category===t);return n.length===0?[]:[{category:t,label:Za[t],items:n}]})}var co={pg_cron:`After install, schedule jobs with cron.schedule(). HTTP job types need pg_net.`,timescaledb:`After install, convert time-series tables with create_hypertable().`,timescaledb_toolkit:`Hyperfunctions on top of Timescale — needs timescaledb first.`,postgis:`Adds geometry / geography types and spatial indexes.`,pg_net:`Lets SQL send async HTTP. Required for webhook-style cron jobs.`,pgmq:`Lightweight queue tables in Postgres. Pair with pg_cron to drain jobs.`,pg_graphql:`Exposes a GraphQL schema from your tables.`};function lo(e,t){let n=[`CREATE EXTENSION IF NOT EXISTS ${Qa(e)}`],r=[],i=t?.schema?.trim()??``;i!==``&&uo(i)&&r.push(`SCHEMA ${Dn(i)}`);let a=t?.version?.trim()??``;return a!==``&&Ua(a)&&r.push(`VERSION '${a}'`),t?.cascade===!0&&r.push(`CASCADE`),r.length>0&&n.push(`WITH ${r.join(` `)}`),`${n.join(` `)};`}function uo(e){let t=e.trim();return On(t)&&t.toLowerCase()!==`pg_catalog`}function fo(e){return+!!e.schema?.trim()+ +!!e.version?.trim()+ +(e.cascade===!0)}function po(e,t,n){let r=[...e.requires??[],e.name].map(e=>({name:e,title:$a(e),already:t.has(e)})),i=r.filter(e=>!e.already),a=i.length>0?i.map(t=>lo(t.name,t.name===e.name?n:void 0)).join(`
2
+ `):`-- ${e.name} is already installed`,o=co[e.name];return{items:r,sql:a,...o?{note:o}:{}}}var mo={timescaledb:Ye,pg_cron:pt,postgis:Ni},ho=[{value:`all`,label:`All`},...io.map(e=>({value:e,label:Za[e]}))];function go({open:e,onOpenChange:t,storeRef:n,presentNames:r}){let i=Fa(),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(`all`),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(null),[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)(`extensions`),[_,v]=(0,Z.useState)(!1),[y,C]=(0,Z.useState)(``),[w,T]=(0,Z.useState)(``),[E,D]=(0,Z.useState)(!1),O=(0,Z.useMemo)(()=>new Set(r),[r]),k=(0,Z.useMemo)(()=>{let e=oo(Ha,a);return s===`all`?e:e.filter(e=>e.category===s)},[a,s]),A=s===`all`&&a.trim()===``,j=(0,Z.useMemo)(()=>A?ro(Ha):[],[A]),M=(0,Z.useMemo)(()=>{if(!A)return k;let e=new Set(j.map(e=>e.name));return k.filter(t=>!e.has(t.name))},[A,j,k]),N=(0,Z.useMemo)(()=>so(M),[M]),P=(0,Z.useMemo)(()=>({...y.trim()===``?{}:{schema:y.trim()},...w.trim()===``?{}:{version:w.trim()},...E?{cascade:!0}:{}}),[y,w,E]),F=(0,Z.useMemo)(()=>p?po(p,O,P):null,[p,O,P]),I=e=>{O.has(e.name)||(u(null),g(`extensions`),v(!1),C(``),T(``),D(!1),m(e))},L=async()=>{if(!p||!F)return;let e=F.items.filter(e=>!e.already).map(e=>e.name);if(e.length===0){m(null);return}u(null),f(p.name);try{for(let t of e)await i.mutateAsync({ref:n,child:`extensions`,id:t,patch:{enabled:!0,...t===p.name?P:{}},commit:!0});m(null)}catch(e){u(e instanceof Error?e.message:String(e))}finally{f(null)}};return(0,Q.jsx)(re,{open:e,onOpenChange:e=>{e||(o(``),c(`all`),u(null),f(null),m(null),g(`extensions`),v(!1),C(``),T(``),D(!1)),t(e)},children:(0,Q.jsx)(W,{side:`right`,showOverlay:!1,className:`gap-0 p-0 data-[side=right]:sm:max-w-3xl`,"data-slot":`extension-library-sheet`,children:p&&F?(0,Q.jsx)(_o,{ext:p,plan:F,tab:h,advancedOpen:_,extraCount:fo(P),schema:y,version:w,cascade:E,error:l,pending:d!==null,onTab:g,onAdvanced:v,onSchema:C,onVersion:T,onCascade:D,onBack:()=>{m(null),u(null)},onConfirm:()=>void L()}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(oe,{className:`gap-1 border-b border-border/50`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3 pr-8`,children:[(0,Q.jsx)(be,{className:`text-sm`,children:`Extend this store`}),(0,Q.jsxs)(`p`,{className:`text-[10px] tabular-nums text-muted-foreground`,children:[k.length,` pack`,k.length===1?``:`s`,a.trim()?` matching “${a.trim()}”`:``]})]}),(0,Q.jsxs)(ge,{className:`text-[11px]`,children:[`External packs — Timescale, PostGIS, cron, FDWs. Install reviews`,` `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`CREATE EXTENSION`}),` first.`]})]}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center border-b border-border/50`,children:[(0,Q.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,Q.jsx)(b,{icon:ei,className:`pointer-events-none absolute top-1/2 left-3 size-3.5 -translate-y-1/2 text-muted-foreground`,"aria-hidden":!0}),(0,Q.jsx)(x,{value:a,onChange:e=>o(e.target.value),placeholder:`Search packs…`,"aria-label":`Search library`,flat:!0,className:S(yi,`font-mono`),autoFocus:!0})]}),(0,Q.jsxs)(Hn,{items:ho,value:s,onValueChange:e=>{e==null||Array.isArray(e)||c(e===`all`?`all`:e)},children:[(0,Q.jsx)(_n,{"aria-label":`Category`,size:`sm`,className:`h-8 shrink-0 gap-1 border-0 bg-transparent px-1.5 shadow-none ring-0 text-[11px] dark:bg-transparent dark:hover:bg-transparent [&_svg:not([class*='size-'])]:size-3.5`,children:(0,Q.jsx)(Xn,{children:e=>{let t=String(e??`all`),n=t===`all`?`All`:Za[t];return(0,Q.jsxs)(`span`,{children:[`Category · `,n]})}})}),(0,Q.jsx)(Vn,{align:`end`,alignItemWithTrigger:!1,className:`min-w-44`,children:(0,Q.jsx)(Un,{children:ho.map(e=>(0,Q.jsx)(Pn,{value:e.value,className:`text-[11px]`,children:e.label},e.value))})})]})]}),l?(0,Q.jsx)(`p`,{className:`border-b border-border/50 px-4 py-2 text-[11px] text-destructive`,role:`alert`,children:l}):null,(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:k.length===0?(0,Q.jsx)(`p`,{className:`px-4 py-8 text-center text-[11px] text-muted-foreground`,children:`No matching packs.`}):(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5 px-4 py-4`,children:[j.length>0?(0,Q.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(bo,{children:`Popular`}),(0,Q.jsx)(`ul`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-3`,children:j.map(e=>(0,Q.jsx)(xo,{ext:e,installed:O.has(e.name),pending:d===e.name,disabled:d!==null,onAdd:()=>I(e)},e.name))})]}):null,N.map(e=>(0,Q.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(bo,{children:e.label}),(0,Q.jsx)(`ul`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:e.items.map(e=>(0,Q.jsx)(So,{ext:e,installed:O.has(e.name),pending:d===e.name,disabled:d!==null,onAdd:()=>I(e)},e.name))})]},e.category))]})})]})]})})})}function _o({ext:e,plan:t,tab:n,advancedOpen:r,extraCount:i,schema:a,version:o,cascade:s,error:c,pending:l,onTab:u,onAdvanced:d,onSchema:f,onVersion:p,onCascade:m,onBack:h,onConfirm:g}){let _=$a(e.name),v=e.name===`timescaledb`||e.name===`pg_cron`||e.name===`postgis`?mo[e.name]:Ii;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(oe,{className:`gap-2 border-b border-border/50`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:h,className:`flex w-fit items-center gap-1 text-[11px] text-muted-foreground hover:text-foreground`,children:[(0,Q.jsx)(b,{icon:at,className:`size-3.5`}),`Library`]}),(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsx)(`div`,{className:`flex size-9 items-center justify-center rounded-full border border-border/50 bg-muted/20`,children:(0,Q.jsx)(b,{icon:v,className:`size-4`,"aria-hidden":!0})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(be,{className:`text-sm`,children:[`Install `,_]}),(0,Q.jsx)(ge,{className:`text-[11px]`,children:`Review and configure this pack`})]})]})]}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto px-4 py-4`,children:[(0,Q.jsx)(`p`,{className:`text-[11px] font-medium text-foreground`,children:`Installs`}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-[11px] text-muted-foreground`,children:`What this pack will run on the store`}),(0,Q.jsxs)(`div`,{className:`mt-3 flex items-center gap-4`,role:`tablist`,"aria-label":`Install preview`,children:[(0,Q.jsx)(vo,{active:n===`extensions`,onClick:()=>u(`extensions`),children:`Extensions`}),(0,Q.jsx)(vo,{active:n===`sql`,onClick:()=>u(`sql`),children:`SQL`})]}),n===`extensions`?(0,Q.jsx)(`ul`,{className:`mt-3 divide-y divide-border/50 rounded-lg border border-border/50`,children:t.items.map(e=>(0,Q.jsxs)(`li`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,Q.jsx)(`span`,{className:`font-mono text-[12px] text-foreground`,children:e.name}),e.already?(0,Q.jsx)(wo,{}):(0,Q.jsx)(Qe,{variant:`outline`,className:`h-5 rounded-md border-amber-500/40 bg-amber-500/10 px-1.5 text-[9px] font-semibold tracking-wide text-amber-800 uppercase dark:text-amber-400`,children:`Required`})]},e.name))}):(0,Q.jsx)(`pre`,{className:`mt-3 overflow-x-auto rounded-lg border border-border/50 bg-muted/15 px-3 py-2.5 font-mono text-[11px] leading-relaxed text-foreground`,children:t.sql}),t.note?(0,Q.jsx)(`p`,{className:`mt-3 text-[11px] leading-snug text-muted-foreground`,children:t.note}):null,(0,Q.jsxs)(`div`,{className:`mt-4 flex items-center justify-between`,children:[(0,Q.jsx)(`span`,{className:`text-[10px] font-semibold tracking-[0.12em] text-muted-foreground uppercase`,children:`Options`}),(0,Q.jsx)(za,{open:r,extraCount:i,onOpenChange:d,controls:`sql-extension-advanced`})]}),r?(0,Q.jsxs)(`div`,{id:`sql-extension-advanced`,className:`mt-3 flex flex-col gap-3`,children:[(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1.5 block text-[10px] font-semibold tracking-[0.12em] text-muted-foreground uppercase`,children:`Schema`}),(0,Q.jsx)(x,{value:a,onChange:e=>f(e.target.value),placeholder:`engine default`,className:`h-8 font-mono text-[12px]`})]}),(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1.5 block text-[10px] font-semibold tracking-[0.12em] text-muted-foreground uppercase`,children:`Version`}),(0,Q.jsx)(x,{value:o,onChange:e=>p(e.target.value),placeholder:`packaged default`,className:`h-8 font-mono text-[12px]`})]}),(0,Q.jsxs)(`label`,{className:`flex items-center justify-between gap-3`,children:[(0,Q.jsx)(`span`,{className:`text-[12px] text-foreground`,children:`CASCADE`}),(0,Q.jsx)(Ra,{size:`sm`,checked:s,onCheckedChange:m,ariaLabel:`CASCADE required extensions`})]}),(0,Q.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:"`pg_catalog` is refused. Schema and version apply to this pack only."})]}):null,c?(0,Q.jsx)(`p`,{className:`mt-3 text-[11px] text-destructive`,role:`alert`,children:c}):null]}),(0,Q.jsxs)(I,{children:[(0,Q.jsx)(gi,{split:!0,onClick:h,children:`Cancel`}),(0,Q.jsx)(gi,{variant:`default`,disabled:l,"data-slot":`extension-library-install`,"data-name":e.name,onClick:g,children:l?`Installing…`:`Install pack`})]})]})}function vo({active:e,onClick:t,children:n}){return(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":e,onClick:t,className:S(`px-2 py-1.5 text-[10px] font-semibold tracking-[0.08em] uppercase transition-colors hover:bg-muted/50`,e?`text-foreground`:`text-muted-foreground hover:text-foreground`),children:n})}function yo({name:e,title:t,className:n}){let r=Xa(e);return r?(0,Q.jsxs)(`a`,{href:r,target:`_blank`,rel:`noreferrer`,className:S(`group/ext-link inline-flex max-w-full items-center gap-1 font-medium tracking-tight text-foreground underline-offset-2 hover:underline`,n),children:[(0,Q.jsx)(`span`,{className:`truncate`,children:t}),(0,Q.jsx)(b,{icon:Mi,className:`size-3 shrink-0 text-muted-foreground/50 group-hover/ext-link:text-muted-foreground`,"aria-hidden":!0})]}):(0,Q.jsx)(`p`,{className:S(`font-medium tracking-tight text-foreground`,n),children:t})}function bo({children:e}){return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`p`,{className:`text-[10px] font-semibold tracking-[0.12em] text-muted-foreground uppercase`,children:e}),(0,Q.jsx)(`div`,{className:`h-px min-w-0 flex-1 bg-border/50`,"aria-hidden":!0})]})}function xo({ext:e,installed:t,pending:n,disabled:r,onAdd:i}){let a=e.name,o=$a(e.name),s=no(e.name);return(0,Q.jsxs)(`li`,{className:`flex flex-col gap-3 rounded-xl border border-border/50 bg-muted/10 p-3`,children:[(0,Q.jsx)(`div`,{className:`flex size-8 items-center justify-center rounded-lg border border-border/40 bg-background`,children:(0,Q.jsx)(b,{icon:mo[a],className:`size-4 text-foreground`,"aria-hidden":!0})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(yo,{name:e.name,title:o,className:`text-[13px]`}),(0,Q.jsx)(`p`,{className:`font-mono text-[11px] text-muted-foreground`,children:e.name}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-[11px] leading-snug text-muted-foreground`,children:e.comment}),(0,Q.jsx)(Co,{tags:e.tags})]}),(0,Q.jsxs)(`div`,{className:`mt-auto flex items-end justify-between gap-2`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`p`,{className:`text-[9px] font-semibold tracking-[0.12em] text-muted-foreground uppercase`,children:Za[e.category]}),s?(0,Q.jsxs)(`p`,{className:`truncate text-[10px] text-muted-foreground/80`,children:[`Built by `,s]}):null]}),(0,Q.jsx)(To,{installed:t,pending:n,disabled:r,name:e.name,onAdd:i})]})]})}function So({ext:e,installed:t,pending:n,disabled:r,onAdd:i}){let a=no(e.name);return(0,Q.jsxs)(`li`,{className:`flex flex-col gap-2 rounded-xl border border-border/50 px-3 py-2.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(yo,{name:e.name,title:$a(e.name),className:`text-[13px]`}),(0,Q.jsx)(`p`,{className:`font-mono text-[11px] text-muted-foreground`,children:e.name}),(0,Q.jsx)(Co,{tags:e.tags})]}),t?(0,Q.jsx)(wo,{}):null]}),(0,Q.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:e.comment}),e.requires&&e.requires.length>0?(0,Q.jsxs)(`p`,{className:`font-mono text-[10px] text-muted-foreground/80`,children:[`needs `,e.requires.join(` + `)]}):null,(0,Q.jsxs)(`div`,{className:`mt-auto flex items-end justify-between gap-2 pt-1`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`p`,{className:`text-[9px] font-semibold tracking-[0.12em] text-muted-foreground uppercase`,children:Za[e.category]}),a?(0,Q.jsxs)(`p`,{className:`truncate text-[10px] text-muted-foreground/80`,children:[`Built by `,a]}):null]}),t?null:(0,Q.jsx)(To,{installed:!1,pending:n,disabled:r,name:e.name,onAdd:i})]})]})}function Co({tags:e}){return!e||e.length===0?null:(0,Q.jsx)(`p`,{className:`mt-1 flex flex-wrap gap-1`,children:e.slice(0,4).map(e=>(0,Q.jsx)(`span`,{className:`rounded border border-border/40 px-1 py-px font-mono text-[9px] text-muted-foreground/80`,children:e},e))})}function wo(){return(0,Q.jsx)(Qe,{variant:`outline`,className:`h-5 rounded-md border-emerald-500/30 bg-emerald-500/10 px-1.5 text-[9px] font-semibold tracking-wide text-emerald-700 uppercase dark:text-emerald-400`,children:`Installed`})}function To({installed:e,pending:t,disabled:n,name:r,onAdd:i}){return e?(0,Q.jsx)(wo,{}):(0,Q.jsx)(G,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 shrink-0 px-2 text-[11px]`,disabled:n,"data-slot":`extension-library-add`,"data-name":r,onClick:i,children:t?`Installing…`:`Install`})}var Eo=`github-light`,Do=`github-dark`;function Oo(e){return gt.includes(e)}var ko=new Map;function Ao(e,t){return`${t}\u0000${e}`}function jo(){let{theme:e}=ii(),[t,n]=(0,Z.useState)(()=>e===`dark`);return(0,Z.useEffect)(()=>{let t=document.documentElement,r=()=>{if(e===`dark`){n(!0);return}if(e===`light`){n(!1);return}n(t.classList.contains(`dark`))};if(r(),e!==`system`)return;let i=window.matchMedia(`(prefers-color-scheme: dark)`);return i.addEventListener(`change`,r),()=>i.removeEventListener(`change`,r)},[e]),t}function Mo(e,t){let n=Ao(e,t),r=ko.get(n),[i,a]=(0,Z.useState)(r?{key:n,code:e,language:t,lines:r}:null);return(0,Z.useEffect)(()=>{if(t===`text`||t===`diff`||!Oo(t)){a({key:n,code:e,language:t,lines:[]});return}let r=ko.get(n);if(r){a({key:n,code:e,language:t,lines:r});return}let i=!1;return _t().then(n=>n.codeToTokensWithThemes(e,{lang:t,themes:{light:Eo,dark:Do}})).then(r=>{if(i)return;let o=r.map(e=>e.map(e=>({content:e.content,offset:e.offset,light:e.variants.light?.color,dark:e.variants.dark?.color})));ko.set(n,o),a({key:n,code:e,language:t,lines:o})}).catch(()=>{i||a({key:n,code:e,language:t,lines:[]})}),()=>{i=!0}},[e,n,t]),i?.key===n||i?.language===t&&e.startsWith(i.code)?i.lines.length===0?null:i.lines:null}function No({code:e,tokens:t,className:n}){let r=jo();return(0,Q.jsx)(`code`,{className:S(`font-mono text-[inherit]`,n),children:t?t.map(e=>(0,Q.jsx)(`span`,{style:{color:(r?e.dark:e.light)??e.light??e.dark},children:e.content},`${e.offset}-${e.content}`)):e})}function Po({code:e,language:t=`bash`,className:n}){let r=Mo(e,t),i=0,a=e.split(`
3
+ `).map(e=>{let t={content:e,offset:i};return i+=e.length+1,t});return(0,Q.jsx)(`pre`,{className:S(`m-0 overflow-x-auto whitespace-pre font-mono text-xs leading-5 text-foreground/85`,n),children:a.map((e,t)=>(0,Q.jsxs)(Z.Fragment,{children:[(0,Q.jsx)(No,{code:e.content,tokens:r?.[t]}),t<a.length-1?`
4
+ `:null]},`${e.offset}-${e.content}`))})}var Fo=[`INSERT`,`UPDATE`,`DELETE`],Io=[{id:`read`,label:`Read`,icon:li},{id:`write`,label:`Write`,icon:fn},{id:`both`,label:`Both`,icon:Ve}];function Lo({open:e,onOpenChange:t,storeRef:n,tables:r,manifest:i=null}){let a=Fa(),o=wn(e),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(`sql`),[d,f]=(0,Z.useState)(r[0]??``),[p,m]=(0,Z.useState)(``),[h,g]=(0,Z.useState)(`SELECT`),[_,v]=(0,Z.useState)(`PERMISSIVE`),[y,C]=(0,Z.useState)(`true`),[w,T]=(0,Z.useState)(`true`),[E,D]=(0,Z.useState)(!0),[O,k]=(0,Z.useState)(null),[A,j]=(0,Z.useState)(!1),[M,P]=(0,Z.useState)(``),[F,L]=(0,Z.useState)(null),[z,B]=(0,Z.useState)(!1),[V,H]=(0,Z.useState)(``),[ee,te]=(0,Z.useState)([]),[ne,U]=(0,Z.useState)(()=>Mn(`read`)),ie=rr(h),se=jn(h),ce=(0,Z.useMemo)(()=>En(i,n,d),[i,n,d]),le=(0,Z.useMemo)(()=>ce.map(e=>e.sqlName),[ce]),ue=nr(le),de=p!==``&&le.includes(p)?p:ue??``,fe=F!==null&&Fn(In.find(e=>e.id===F)??{})||se.using&&xn(y)||se.withCheck&&xn(w),pe=le.length>0&&fe,me=(se.using&&Sn(y)||se.withCheck&&Sn(w))&&de===``,he=(0,Z.useMemo)(()=>$n(br(i),o.data??null),[i,o.data]),_e=(0,Z.useMemo)(()=>({gates:ee,actions:ne,roles:[]}),[ee,ne]),ve=(0,Z.useMemo)(()=>{try{let e=dr({name:s||`policy_name`,table:d||`table`,command:h,behavior:_,roles:`public`,using:se.using?y:``,withCheck:se.withCheck?w:``});return{sql:Nn(e,E),code:An(e)}}catch{return null}},[s,d,h,_,se,y,w,E]),ye=(e,t)=>t===``?e:xr(e,t),xe=e=>{let t=Fn(e)?de:``;L(e.id),c(e.name),g(e.command),v(e.behavior??`PERMISSIVE`),U(t=>qn(t,e.command)),C(ye(e.using??`true`,t)),T(ye(e.withCheck??`true`,t)),t!==``&&m(t)},Se=e=>{let t=kn(i,n,e),r=(p!==``&&t.includes(p)?p:null)??nr(t)??``;f(e),m(r);let a=de||`owner`;C(e=>Cn(e,a,r)),T(e=>Cn(e,a,r))},Ce=e=>{let t=de||`owner`;m(e),C(n=>Cn(n,t,e)),T(n=>Cn(n,t,e))},we=e=>{let t=Ln(e,h);g(t),U(Mn(e)),te([])},Te=e=>{g(e),U(t=>qn(t,e))},G=e=>{te(t=>{let n=t.includes(e)?t.filter(t=>t!==e):[...t,e],r=vn(n);return C(r),T(r),n})},Ee=async()=>{if(k(null),me){k(`Pick a column on ${d} that stores the user id.`);return}try{let e=dr({name:s,table:d,command:h,behavior:_,roles:`public`,using:se.using?y:``,withCheck:se.withCheck?w:``});await a.mutateAsync({ref:n,child:`policies`,id:`${e.table}:${e.name}`,patch:{create:!0,name:e.name,table:e.table,command:e.command,behavior:e.behavior,roles:e.roles.join(`, `),...e.using===void 0?{}:{using:e.using},...e.withCheck===void 0?{}:{withCheck:e.withCheck},enableRls:E},commit:!0}),t(!1)}catch(e){k(e instanceof Error?e.message:String(e))}};return(0,Q.jsx)(re,{open:e,onOpenChange:e=>{e||B(!1),t(e)},children:(0,Q.jsxs)(W,{side:`right`,showCloseButton:!1,className:`flex-col gap-0 overflow-hidden rounded-none bg-popover p-0 shadow-lg sm:flex-row sm:items-stretch data-[side=right]:w-auto data-[side=right]:max-w-[calc(100vw-1.5rem)] data-[side=right]:sm:max-w-none`,"data-slot":`rls-policy-sheet`,children:[(0,Q.jsxs)(`div`,{className:`relative flex min-h-0 w-full flex-1 flex-col sm:w-[28rem] sm:flex-none`,"data-slot":`rls-policy-form-sheet`,children:[(0,Q.jsxs)(oe,{className:`flex-row items-stretch gap-0 border-b border-border/60 p-0`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start gap-3 p-4`,children:[(0,Q.jsx)(`div`,{className:`flex size-9 items-center justify-center rounded-full border border-border/50 bg-muted/20`,children:(0,Q.jsx)(b,{icon:Ve,className:`size-4`,"aria-hidden":!0})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(be,{className:`text-sm`,children:`Create policy`}),(0,Q.jsx)(ge,{className:`text-[11px]`,children:"Review the `CREATE POLICY` SQL before it runs"})]})]}),(0,Q.jsx)(`span`,{className:`w-px shrink-0 self-stretch bg-border/60`,"aria-hidden":!0}),(0,Q.jsxs)(N,{className:S(R,`min-w-11`),"data-slot":`rls-policy-form-close`,"aria-label":`Close`,children:[(0,Q.jsx)(b,{icon:ae,className:`size-4`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]}),(0,Q.jsxs)(Ne,{orientation:`vertical`,className:`min-h-0 flex-1`,children:[(0,Q.jsx)(ze,{defaultSize:`68%`,minSize:`28%`,className:`min-h-0`,children:(0,Q.jsxs)(`div`,{className:`h-full min-h-0 overflow-y-auto`,"data-slot":`rls-policy-form-scroll`,children:[(0,Q.jsxs)(`div`,{className:`border-b border-border/50`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-4 pt-2.5`,children:[(0,Q.jsx)(`p`,{className:`text-[10px] font-semibold tracking-[0.12em] text-muted-foreground uppercase`,children:`Policy name`}),(0,Q.jsxs)(vi,{active:z,"aria-expanded":z,"aria-controls":z?`rls-policy-templates-sheet`:void 0,onClick:()=>B(e=>!e),children:[(0,Q.jsx)(b,{icon:ct,className:`size-3`,"aria-hidden":!0}),`Templates`]})]}),(0,Q.jsx)(x,{value:s,onChange:e=>c(e.target.value),placeholder:`read_all`,"aria-label":`Policy name`,flat:!0,className:S(X,`font-mono`)})]}),(0,Q.jsxs)(pi,{children:[(0,Q.jsx)(Y,{label:`Table`,split:`start`,children:(0,Q.jsxs)(ka,{value:d,onValueChange:Se,children:[(0,Q.jsx)(Aa,{flat:!0,className:S(X,`font-mono`),children:(0,Q.jsx)(ja,{placeholder:`Select a table`})}),(0,Q.jsx)(Ma,{children:r.map(e=>(0,Q.jsx)(Na,{value:e,className:`font-mono text-[12px]`,children:e},e))})]})}),(0,Q.jsx)(Y,{label:`Behavior`,split:`end`,children:(0,Q.jsxs)(ka,{value:_,onValueChange:e=>v(e),children:[(0,Q.jsx)(Aa,{flat:!0,className:X,children:(0,Q.jsx)(ja,{})}),(0,Q.jsxs)(Ma,{children:[(0,Q.jsx)(Na,{value:`PERMISSIVE`,children:`Permissive`}),(0,Q.jsx)(Na,{value:`RESTRICTIVE`,children:`Restrictive`})]})]})})]}),(0,Q.jsx)(hi,{label:`Gate`,hint:`Who this policy pairs with`}),(0,Q.jsx)(Bo,{advanced:A,onAdvancedChange:j,mode:ie,onModeChange:we,catalog:he,query:V,onQueryChange:H,selection:_e,onToggleGate:G}),A||ie===`write`?(0,Q.jsx)(Xo,{commands:A?Sr:Fo,value:h,onChange:Te}):null,(0,Q.jsx)(hi,{label:`Rows`,hint:se.using&&se.withCheck?`Existing rows and new rows`:se.withCheck?`New rows`:`Existing rows`}),pe?(0,Q.jsx)(Y,{label:`Column`,hint:`compared to oke.user()`,children:(0,Q.jsxs)(ka,{value:de,onValueChange:Ce,children:[(0,Q.jsx)(Aa,{flat:!0,className:S(X,`font-mono`),"data-slot":`rls-identity-column`,children:(0,Q.jsx)(ja,{placeholder:`Select a column`})}),(0,Q.jsx)(Ma,{children:ce.map(e=>(0,Q.jsx)(Na,{value:e.sqlName,children:(0,Q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(Ae,{primaryKey:e.primaryKey,foreignKey:e.foreignKey,unique:e.unique,inferred:e.inferred}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[12px]`,children:e.sqlName})]})},e.sqlName))})]})}):null,se.using?(0,Q.jsx)(Y,{label:`USING`,children:(0,Q.jsx)(x,{value:y,onChange:e=>C(e.target.value),placeholder:`true`,flat:!0,className:S(X,`font-mono`)})}):null,se.withCheck?(0,Q.jsx)(Y,{label:`WITH CHECK`,children:(0,Q.jsx)(x,{value:w,onChange:e=>T(e.target.value),placeholder:`true`,flat:!0,className:S(X,`font-mono`)})}):null]})}),(0,Q.jsx)(Ge,{withHandle:!0,"data-slot":`rls-policy-sql-handle`}),(0,Q.jsx)(ze,{defaultSize:`32%`,minSize:`16%`,className:`min-h-0`,children:(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-muted/15`,"data-slot":`rls-policy-sql-dock`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 py-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,className:S(`text-[10px] font-semibold tracking-[0.12em] uppercase`,l===`sql`?`text-foreground`:`text-muted-foreground`),onClick:()=>u(`sql`),children:`SQL`}),(0,Q.jsx)(`button`,{type:`button`,className:S(`text-[10px] font-semibold tracking-[0.12em] uppercase`,l===`code`?`text-foreground`:`text-muted-foreground`),onClick:()=>u(`code`),children:`Code`})]}),(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:`Enable RLS`}),(0,Q.jsx)(Ra,{size:`sm`,checked:E,onCheckedChange:D,ariaLabel:`Enable RLS on this table`})]})]}),ve?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 pb-3`,children:(0,Q.jsx)(Po,{code:l===`sql`?ve.sql:ve.code,language:l===`sql`?`sql`:`typescript`,className:`overflow-visible whitespace-pre-wrap break-words text-[11px] leading-relaxed`})}):(0,Q.jsx)(`p`,{className:`min-h-0 flex-1 px-4 pb-3 text-[11px] text-muted-foreground`,children:`Fill name, table, and an expression.`}),me?(0,Q.jsxs)(bi,{slot:`rls-owner-missing`,children:[`Pick a column on `,d,` — this table has no owner / owner_email / creator_email guess.`]}):null,O?(0,Q.jsx)(bi,{children:O}):null]})})]}),(0,Q.jsxs)(I,{children:[(0,Q.jsx)(gi,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(gi,{variant:`default`,disabled:a.isPending||!ve||me,onClick:()=>void Ee(),children:a.isPending?`Creating…`:`Create policy`})]})]}),z?(0,Q.jsx)(`aside`,{id:`rls-policy-templates-sheet`,className:`flex h-80 w-full shrink-0 flex-col border-t border-border/50 sm:h-auto sm:w-80 sm:border-t-0 sm:border-l`,"data-slot":`rls-policy-templates-sheet`,children:(0,Q.jsx)(zo,{query:M,onQueryChange:P,selectedId:F,onSelect:xe,onClose:()=>B(!1)})}):null]})})}var Ro={SELECT:`bg-emerald-500/15 text-emerald-800 dark:text-emerald-300`,INSERT:`bg-amber-500/15 text-amber-800 dark:text-amber-300`,UPDATE:`bg-sky-500/15 text-sky-800 dark:text-sky-300`,DELETE:`bg-rose-500/15 text-rose-800 dark:text-rose-300`,ALL:`bg-muted text-muted-foreground`};function zo({query:e,onQueryChange:t,selectedId:n,onSelect:r,onClose:i}){let a=bn(In,e);return(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,"data-slot":`rls-policy-templates`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-stretch border-b border-border/60`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`p`,{className:`px-3 pt-2.5 text-[10px] font-semibold tracking-[0.12em] text-muted-foreground uppercase`,children:`Templates`}),(0,Q.jsxs)(`label`,{className:`relative block`,children:[(0,Q.jsx)(b,{icon:ei,className:`pointer-events-none absolute top-1/2 left-3 size-3.5 -translate-y-1/2 text-muted-foreground`,"aria-hidden":!0}),(0,Q.jsx)(x,{value:e,onChange:e=>t(e.target.value),placeholder:`Search templates`,"aria-label":`Search templates`,flat:!0,className:S(yi,`font-mono`)})]})]}),(0,Q.jsx)(`span`,{className:`w-px shrink-0 self-stretch bg-border/60`,"aria-hidden":!0}),(0,Q.jsx)(`button`,{type:`button`,className:S(R,`min-w-11`),onClick:i,"aria-label":`Close templates`,"data-slot":`rls-policy-templates-close`,children:(0,Q.jsx)(b,{icon:ae,className:`size-4`,"aria-hidden":!0})})]}),(0,Q.jsx)(`ul`,{className:`min-h-0 flex-1 overflow-y-auto p-2`,children:a.length===0?(0,Q.jsx)(`li`,{className:`px-2 py-3 text-[10px] text-muted-foreground`,children:`No matching templates.`}):a.map(e=>{let t=e.id===n;return(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:()=>r(e),className:S(`flex w-full flex-col gap-1.5 rounded-lg px-2.5 py-2 text-left`,t?`bg-muted ring-1 ring-foreground`:`hover:bg-muted/50`),children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(`span`,{className:S(`rounded px-1.5 py-px font-mono text-[9px] font-semibold tracking-wide`,Ro[e.command]),children:e.command}),e.behavior===`RESTRICTIVE`?(0,Q.jsx)(`span`,{className:`rounded border border-border/60 px-1 py-px text-[9px] font-semibold tracking-[0.08em] text-muted-foreground uppercase`,children:`Restrictive`}):null,t?(0,Q.jsx)(b,{icon:D,className:`ml-auto size-3.5 shrink-0`}):null]}),(0,Q.jsx)(`span`,{className:`text-[12px] font-medium text-foreground`,children:e.title}),(0,Q.jsx)(`span`,{className:`text-[10px] leading-snug text-muted-foreground`,children:e.detail})]})},e.id)})})]})}function Bo({advanced:e,onAdvancedChange:t,mode:n,onModeChange:r,catalog:i,query:a,onQueryChange:o,selection:s,onToggleGate:c}){let l=Cr(s);return(0,Q.jsxs)(`div`,{className:S(!e&&`border-b border-border/50`),children:[(0,Q.jsx)(Vo,{mode:n,onChange:r,advanced:e,extraCount:l,onAdvancedChange:t}),e?(0,Q.jsx)(Wo,{catalog:i,query:a,onQueryChange:o,selection:s,onToggleGate:c}):null]})}function Vo({mode:e,onChange:t,advanced:n,extraCount:r,onAdvancedChange:i}){let a=(0,Z.useId)(),o=ti();return(0,Q.jsx)(Xi,{id:a,children:(0,Q.jsxs)(`div`,{role:`group`,"aria-label":`Gate`,className:S(`flex w-full items-center`,n&&`border-b border-border/50`),children:[Io.map(r=>{let a=!n&&e===r.id;return(0,Q.jsxs)(Ho,{active:a,reduceMotion:o,onClick:()=>{i(!1),t(r.id)},children:[(0,Q.jsx)(b,{icon:r.icon,className:`size-3.5`,"aria-hidden":!0}),r.label]},r.id)}),(0,Q.jsxs)(Ho,{active:n,reduceMotion:o,"aria-expanded":n,"aria-controls":`rls-gate-advanced`,onClick:()=>i(!n),children:[(0,Q.jsx)(b,{icon:gn,className:`size-3.5`,"aria-hidden":!0}),`Advanced`,r>0?(0,Q.jsx)(`span`,{className:`flex h-3.5 min-w-3.5 items-center justify-center rounded-full bg-foreground/10 px-1 text-[9px] font-semibold tabular-nums`,children:r}):null]})]})})}function Ho({active:e,reduceMotion:t,onClick:n,children:r,...i}){return(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":e,onClick:n,className:S(`relative inline-flex h-8 min-w-0 flex-1 items-center justify-center gap-1.5 overflow-hidden rounded-none px-2 text-[11px] font-medium outline-none select-none`,`focus-visible:ring-2 focus-visible:ring-ring/50`,e?`text-foreground`:`text-muted-foreground hover:bg-muted/50 hover:text-foreground`),...i,children:[e?(0,Q.jsx)(Xr.span,{layoutId:`rls-gate-pill`,className:`absolute inset-0 z-0 bg-muted`,style:{borderRadius:0},transition:t?{duration:0}:Kr}):null,(0,Q.jsx)(`span`,{className:`relative z-10 inline-flex items-center gap-1.5`,children:r})]})}var Uo={SELECT:`USING on existing rows`,INSERT:`WITH CHECK on new rows`,UPDATE:`USING and WITH CHECK`,DELETE:`USING on existing rows`,ALL:`Every command`};function Wo({catalog:e,query:t,onQueryChange:n,selection:r,onToggleGate:i}){let a=or(e,t),o=Qn(a),s=Wn(a),c=t.trim()!==``;return(0,Q.jsxs)(`div`,{id:`rls-gate-advanced`,className:`flex flex-col`,children:[(0,Q.jsxs)(`label`,{className:`relative block border-b border-border/50`,children:[(0,Q.jsx)(b,{icon:ei,className:`pointer-events-none absolute top-1/2 left-4 size-3.5 -translate-y-1/2 text-muted-foreground`,"aria-hidden":!0}),(0,Q.jsx)(x,{value:t,onChange:e=>n(e.target.value),placeholder:`Search policy or scope`,"aria-label":`Search policy or scope`,flat:!0,className:S(yi,`font-mono`)})]}),r.gates.length>0?(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1 border-b border-border/50 px-4 py-1.5`,children:r.gates.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>i(e),className:`inline-flex items-center gap-1 rounded-md bg-muted px-1.5 py-0.5 font-mono text-[10px] text-foreground hover:bg-muted/70`,"aria-label":`Remove ${e}`,children:[e,(0,Q.jsx)(b,{icon:ae,className:`size-2.5`,"aria-hidden":!0})]},e))}):null,(0,Q.jsxs)(Go,{empty:c?`No matches.`:`No policy or scope gates declared.`,hasRows:o.length+s.length>0,children:[o.length>0?(0,Q.jsx)(Ko,{label:`Policy`,hint:`gate.policy`}):null,o.map(e=>(0,Q.jsx)(qo,{icon:Jo(e.variant),label:e.name,detail:Yo(e),selected:r.gates.includes(e.name),onSelect:()=>i(e.name),pressed:!0},e.name)),s.length>0?(0,Q.jsx)(Ko,{label:`Scope`,hint:`gate.scope`}):null,s.map(e=>(0,Q.jsx)(qo,{icon:Jo(e.variant),label:e.name,detail:Yo(e),selected:r.gates.includes(e.name),onSelect:()=>i(e.name),pressed:!0},e.name))]})]})}function Go({empty:e,hasRows:t,children:n}){return t?(0,Q.jsx)(`ul`,{className:`max-h-40 overflow-y-auto border-b border-border/50`,children:n}):(0,Q.jsx)(`p`,{className:`border-b border-border/50 px-4 py-3 text-[10px] text-muted-foreground`,children:e})}function Ko({label:e,hint:t}){return(0,Q.jsx)(`li`,{className:`sticky top-0 z-10 border-b border-border/50 bg-muted/80 px-4 py-1 backdrop-blur-sm`,children:(0,Q.jsxs)(`p`,{className:`flex items-baseline gap-2 text-[10px] font-semibold tracking-[0.08em] text-muted-foreground uppercase`,children:[e,(0,Q.jsx)(`span`,{className:`font-mono font-normal tracking-normal text-muted-foreground/70 lowercase`,children:t})]})})}function qo({icon:e,label:t,detail:n,selected:r,onSelect:i,pressed:a=!1}){return(0,Q.jsx)(`li`,{className:`border-b border-border/50 last:border-b-0`,children:(0,Q.jsxs)(`button`,{type:`button`,role:a?`checkbox`:`radio`,"aria-checked":r,"aria-pressed":a?r:void 0,onClick:i,className:S(`flex w-full items-start gap-2 px-4 py-1.5 text-left`,r?`bg-muted`:`hover:bg-muted/40`),children:[(0,Q.jsx)(`span`,{className:S(`mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-sm`,r?`bg-foreground text-background`:`bg-muted text-muted-foreground`),"aria-hidden":!0,children:(0,Q.jsx)(b,{icon:e,className:`size-3`})}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block truncate font-mono text-[12px] font-medium text-foreground`,children:t}),(0,Q.jsx)(`span`,{className:`mt-0.5 block text-[10px] leading-snug text-muted-foreground`,children:n})]}),r?(0,Q.jsx)(b,{icon:D,className:`mt-0.5 size-3.5 shrink-0`,"aria-hidden":!0}):null]})})}function Jo(e){return e===`public`?mn:e===`scope`?Re:Ve}function Yo(e){return e.description?e.description:e.variant===`public`?`Intentionally unauthenticated`:e.variant===`scope`?`auth.scopes.has("${e.name}")`:`ABAC policy`}function Xo({commands:e,value:t,onChange:n}){return(0,Q.jsx)(_i,{label:`FOR`,hint:Uo[t],children:e.map(e=>(0,Q.jsx)(fi,{active:t===e,onClick:()=>n(e),children:e},e))})}function Zo(e){if(!e.error)return null;let t=e.error.data,n=t&&typeof t==`object`&&`ref`in t&&typeof t.ref==`string`?t.ref:null,r=Error(n??e.error.message??e.error.code);return r.code=e.error.code,r.data=e.error.data,r}function Qo(){return Yr({mutationFn:async e=>{let t=await ne(e),n=Zo(t);if(n)throw n;if(!t.data)throw Error(`Empty SQL result`);return t.data}})}function $o({value:e,onChange:t,label:n,className:r,onSubmit:i}){let a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=e.endsWith(`
5
+ `)?e:`${e}\n`;return(0,Q.jsxs)(`div`,{className:S(`relative min-h-56 bg-muted/15`,r),children:[(0,Q.jsx)(`div`,{ref:a,className:`pointer-events-none absolute inset-0 overflow-hidden`,children:(0,Q.jsx)(Nt,{code:s,language:`sql`,className:`overflow-visible whitespace-pre-wrap break-words px-4 py-3 text-[11px] leading-5`})}),(0,Q.jsx)(`textarea`,{ref:o,value:e,onChange:e=>t(e.target.value),onScroll:()=>{let e=o.current,t=a.current;e&&t&&(t.scrollTop=e.scrollTop,t.scrollLeft=e.scrollLeft)},onKeyDown:e=>{i&&(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),i())},spellCheck:!1,autoCorrect:`off`,autoCapitalize:`off`,"aria-label":n,"data-slot":`sql-style-editor`,className:`absolute inset-0 h-full w-full resize-none overflow-auto bg-transparent px-4 py-3 font-mono text-[11px] leading-5 break-words whitespace-pre-wrap text-transparent caret-foreground outline-none`})]})}var es=[{id:`plpgsql-void`,title:`PL/pgSQL`,detail:`RETURNS void — empty body you fill in.`,returns:`void`,language:`plpgsql`,body:`BEGIN
6
+ -- Write your function logic here
7
+ END;`},{id:`trigger-fn`,title:`Trigger function`,detail:`RETURNS trigger — use with CREATE TRIGGER.`,returns:`trigger`,language:`plpgsql`,body:`BEGIN
8
+ RETURN NEW;
9
+ END;`},{id:`sql-scalar`,title:`SQL scalar`,detail:`LANGUAGE sql — a single SELECT.`,returns:`text`,language:`sql`,body:` SELECT NULL;`},{id:`sql-immutable`,title:`Immutable SQL`,detail:`LANGUAGE sql IMMUTABLE — safe for indexes.`,returns:`text`,language:`sql`,volatility:`IMMUTABLE`,body:` SELECT $1;`,args:`value text`}];function ts(e){let t=e.orReplace===!0?`OR REPLACE `:``,n=is(e.args)?e.args.trim():``,r=is(e.returns)?e.returns.trim():``,i=[`CREATE ${t}FUNCTION ${ss(e.name)}(${n})`,`RETURNS ${r||`void`}`,`LANGUAGE ${e.language}`];e.volatility!==void 0&&e.volatility!==`VOLATILE`&&i.push(e.volatility),e.leakproof===!0&&i.push(`LEAKPROOF`),e.strict===!0&&i.push(`STRICT`),e.security===`DEFINER`&&i.push(`SECURITY DEFINER`),(e.parallel===`RESTRICTED`||e.parallel===`SAFE`)&&i.push(`PARALLEL ${e.parallel}`),typeof e.cost==`number`&&Number.isFinite(e.cost)&&e.cost>0&&i.push(`COST ${e.cost}`),typeof e.rows==`number`&&Number.isFinite(e.rows)&&e.rows>0&&i.push(`ROWS ${e.rows}`);let a=e.searchPath?.trim()??``;a!==``&&is(a)&&i.push(`SET search_path TO ${a}`),i.push(`AS $$`);let o=e.body.replace(/^\n/,``).replace(/\n$/,``);return i.push(o.length>0?o:as(e.language)),i.push(`$$;`),i.join(`
10
+ `)}ts({name:`function_name`,args:``,returns:`void`,language:`plpgsql`,body:`BEGIN
11
+ -- Write your function logic here
12
+ END;`});function ns(e){return/^\s*CREATE\s+(OR\s+REPLACE\s+)?FUNCTION\b/i.test(e)}function rs(e){return/AS\s+\$\$\n?([\s\S]*?)\n?\$\$;?\s*$/i.exec(e)?.[1]??null}function is(e){let t=e.trim();return t.length<=2e3&&!/;/.test(t)&&!/--/.test(t)&&!/\/\*/.test(t)}function as(e){return e===`sql`?` SELECT NULL;`:`BEGIN
13
+ -- Write your function logic here
14
+ END;`}function os(e){return+(e.security===`DEFINER`)+ +(e.strict===!0)+ +(e.leakproof===!0)+ +(e.parallel===`RESTRICTED`||e.parallel===`SAFE`)+ +!!e.searchPath?.trim()+ +(typeof e.cost==`number`&&e.cost>0)+ +(typeof e.rows==`number`&&e.rows>0)}function ss(e){let t=e.trim().replace(/\(\s*\)$/,``);return(t.length>0?t:`function_name`).split(`.`).map(e=>Dn(e)).join(`.`)}var cs=[`plpgsql`,`sql`],ls=[`VOLATILE`,`STABLE`,`IMMUTABLE`],us=[`INVOKER`,`DEFINER`],ds=[`UNSAFE`,`RESTRICTED`,`SAFE`];function fs(){return`BEGIN
15
+ -- Write your function logic here
16
+ END;`}function ps({open:e,onOpenChange:t,storeRef:n}){let r=te(),{mutate:i,isPending:a,reset:o}=Qo(),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(``),[d,f]=(0,Z.useState)(`void`),[p,m]=(0,Z.useState)(`plpgsql`),[h,g]=(0,Z.useState)(`VOLATILE`),[_,v]=(0,Z.useState)(!1),[y,C]=(0,Z.useState)(!1),[w,T]=(0,Z.useState)(`INVOKER`),[E,D]=(0,Z.useState)(!1),[O,k]=(0,Z.useState)(!1),[A,j]=(0,Z.useState)(`UNSAFE`),[M,N]=(0,Z.useState)(``),[P,F]=(0,Z.useState)(``),[L,R]=(0,Z.useState)(``),[z,B]=(0,Z.useState)(``),[V,H]=(0,Z.useState)(null),[ee,ne]=(0,Z.useState)(null),U=(e,t=z)=>{let n=e.name??s,r=e.args??l,i=e.returns??d,a=e.language??p,o=e.volatility??h,c=e.orReplace??_,u=e.security??w,f=e.strict??E,m=e.leakproof??O,g=e.parallel??A,v=e.searchPath??M,y=Number(e.cost??P),b=Number(e.rows??L);B(ts({name:n.trim()||`function_name`,args:r,returns:i,language:a,volatility:o,body:e.body??rs(t)??fs(),orReplace:c,security:u,strict:f,leakproof:m,parallel:g,...v.trim()===``?{}:{searchPath:v},...Number.isFinite(y)&&y>0?{cost:y}:{},...Number.isFinite(b)&&b>0?{rows:b}:{}}))};(0,Z.useEffect)(()=>{e&&(c(``),u(``),f(`void`),m(`plpgsql`),g(`VOLATILE`),v(!1),C(!1),T(`INVOKER`),D(!1),k(!1),j(`UNSAFE`),N(``),F(``),R(``),ne(null),H(null),B(ts({name:`function_name`,args:``,returns:`void`,language:`plpgsql`,body:fs()})),o())},[e,o]);let ie=e=>{ne(e.id);let t=s.trim()===``?e.id.replaceAll(`-`,`_`):s;f(e.returns),m(e.language),g(e.volatility??`VOLATILE`),u(e.args??``),s.trim()===``&&c(t),U({name:t,args:e.args??``,returns:e.returns,language:e.language,volatility:e.volatility??`VOLATILE`,body:e.body},z)},ae=()=>{if(!ns(z)){H(`This sheet runs CREATE FUNCTION only`);return}H(null),i({ref:n,sql:z,allowWrite:!0},{onSuccess:()=>{r.invalidateQueries({queryKey:_r}),t(!1)},onError:e=>H(e instanceof Error?e.message:String(e))})};return(0,Q.jsx)(re,{open:e,onOpenChange:t,children:(0,Q.jsxs)(W,{side:`right`,className:`flex w-full flex-col gap-0 overflow-hidden data-[side=right]:sm:max-w-xl`,"data-slot":`sql-function-sheet`,onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),a||ae())},children:[(0,Q.jsx)(oe,{className:`shrink-0 gap-2 border-b border-border/50`,children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsx)(`div`,{className:`flex size-9 items-center justify-center rounded-full border border-border/50 bg-muted/20`,children:(0,Q.jsx)(b,{icon:Ai,className:`size-4`,"aria-hidden":!0})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(be,{className:`text-sm`,children:`New function`}),(0,Q.jsx)(ge,{className:`text-[11px]`,children:"Review the `CREATE FUNCTION` SQL before it runs"})]})]})}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:[(0,Q.jsx)(Ba,{templates:es,selectedId:ee,onSelect:ie}),(0,Q.jsx)(Y,{label:`Function name`,children:(0,Q.jsx)(x,{value:s,onChange:e=>{let t=e.target.value;c(t),U({name:t})},placeholder:`function_name`,flat:!0,className:S(X,`font-mono`)})}),(0,Q.jsxs)(pi,{children:[(0,Q.jsx)(Y,{label:`Arguments`,split:`start`,children:(0,Q.jsx)(x,{value:l,onChange:e=>{let t=e.target.value;u(t),U({args:t})},placeholder:`optional — id text`,flat:!0,className:S(X,`font-mono`)})}),(0,Q.jsx)(Y,{label:`Returns`,split:`end`,children:(0,Q.jsx)(x,{value:d,onChange:e=>{let t=e.target.value;f(t),U({returns:t})},placeholder:`void`,flat:!0,className:S(X,`font-mono`)})})]}),(0,Q.jsx)(_i,{label:`Language`,children:cs.map(e=>(0,Q.jsx)(fi,{active:p===e,onClick:()=>{m(e),U({language:e})},children:e},e))}),(0,Q.jsx)(_i,{label:`Volatility`,children:ls.map(e=>(0,Q.jsx)(fi,{active:h===e,onClick:()=>{g(e),U({volatility:e})},children:e},e))}),(0,Q.jsx)(mi,{label:`Replace if it already exists`,children:(0,Q.jsx)(Ra,{size:`sm`,checked:_,onCheckedChange:e=>{v(e),U({orReplace:e})},ariaLabel:`Replace if it already exists`})}),(0,Q.jsx)(hi,{label:`Options`,children:(0,Q.jsx)(za,{open:y,extraCount:os({security:w,strict:E,leakproof:O,parallel:A,searchPath:M,cost:Number(P),rows:Number(L)}),onOpenChange:C,controls:`sql-function-advanced`})}),y?(0,Q.jsxs)(`div`,{id:`sql-function-advanced`,children:[(0,Q.jsx)(_i,{label:`Security`,children:us.map(e=>(0,Q.jsx)(fi,{active:w===e,onClick:()=>{T(e),U({security:e})},children:e},e))}),(0,Q.jsx)(_i,{label:`Parallel`,children:ds.map(e=>(0,Q.jsx)(fi,{active:A===e,onClick:()=>{j(e),U({parallel:e})},children:e},e))}),(0,Q.jsxs)(pi,{children:[(0,Q.jsx)(mi,{label:`STRICT`,className:`border-r border-b-0`,children:(0,Q.jsx)(Ra,{size:`sm`,checked:E,onCheckedChange:e=>{D(e),U({strict:e})},ariaLabel:`STRICT`})}),(0,Q.jsx)(mi,{label:`LEAKPROOF`,className:`border-b-0`,children:(0,Q.jsx)(Ra,{size:`sm`,checked:O,onCheckedChange:e=>{k(e),U({leakproof:e})},ariaLabel:`LEAKPROOF`})})]}),(0,Q.jsx)(Y,{label:`SET search_path`,children:(0,Q.jsx)(x,{value:M,onChange:e=>{let t=e.target.value;N(t),U({searchPath:t})},placeholder:`public, pg_temp`,flat:!0,className:S(X,`font-mono`)})}),(0,Q.jsxs)(pi,{children:[(0,Q.jsx)(Y,{label:`COST`,split:`start`,children:(0,Q.jsx)(x,{value:P,onChange:e=>{let t=e.target.value;F(t),U({cost:t})},placeholder:`optional`,inputMode:`decimal`,flat:!0,className:S(X,`font-mono`)})}),(0,Q.jsx)(Y,{label:`ROWS`,split:`end`,children:(0,Q.jsx)(x,{value:L,onChange:e=>{let t=e.target.value;R(t),U({rows:t})},placeholder:`optional`,inputMode:`decimal`,flat:!0,className:S(X,`font-mono`)})})]})]}):null]}),(0,Q.jsxs)(`div`,{className:`shrink-0 border-t border-border/50`,"data-slot":`sql-function-sql-dock`,children:[(0,Q.jsx)(hi,{label:`SQL`,hint:`Editable before it runs`}),(0,Q.jsx)($o,{value:z,onChange:B,onSubmit:a?void 0:ae,label:`CREATE FUNCTION SQL`,className:`min-h-36 max-h-48`}),V?(0,Q.jsx)(bi,{slot:`sql-function-error`,children:V}):null]}),(0,Q.jsxs)(I,{children:[(0,Q.jsx)(gi,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(gi,{variant:`default`,disabled:a||!ns(z),onClick:ae,"data-slot":`sql-function-submit`,children:a?`Creating…`:`Create function`})]})]})})}var ms=[{id:`single-column`,title:`Single column`,detail:`B-tree on one column — the usual lookup index.`,columns:`column_name`},{id:`unique`,title:`Unique`,detail:`UNIQUE B-tree — reject duplicate values.`,columns:`column_name`,unique:!0},{id:`partial`,title:`Partial`,detail:`B-tree with WHERE — index only matching rows.`,columns:`column_name`,where:`true`},{id:`gin`,title:`GIN`,detail:`USING gin — jsonb, arrays, and full-text.`,columns:`column_name`,method:`gin`}];function hs(e){let t=e.unique===!0?`UNIQUE `:``,n=e.concurrently===!0?`CONCURRENTLY `:``,r=e.ifNotExists===!0?`IF NOT EXISTS `:``,i=e.method!==void 0&&e.method!==`btree`?` USING ${e.method}`:``,a=[`CREATE ${t}INDEX ${n}${r}${Dn(e.name)}`,` ON ${Dn(e.table)}${i}`,` (${ys(e.columns)})`],o=e.include?.trim()??``;o!==``&&vs(o)&&a.push(` INCLUDE (${ys(o)})`),e.nullsNotDistinct===!0&&a.push(` NULLS NOT DISTINCT`);let s=e.with?.trim()??``;s!==``&&vs(s)&&a.push(` WITH (${s})`);let c=e.where?.trim()??``;return c!==``&&vs(c)&&a.push(` WHERE ${c}`),`${a.join(`
17
+ `)};`}function gs(e){return+(e.concurrently===!0)+ +!!e.include?.trim()+ +(e.nullsNotDistinct===!0)+ +!!e.with?.trim()}hs({name:`index_name`,table:`table_name`,columns:`column_name`});function _s(e){return/^\s*CREATE\s+(UNIQUE\s+)?INDEX\b/i.test(e)}function vs(e){let t=e.trim();return t.length>0&&t.length<=2e3&&!/;/.test(t)&&!/--/.test(t)&&!/\/\*/.test(t)}function ys(e){if(!vs(e))return Dn(`column_name`);let t=e.split(`,`).map(e=>e.trim()).filter(e=>e.length>0);return t.length===0?Dn(`column_name`):t.map(e=>On(e)?Dn(e):e).join(`, `)}var bs=[`btree`,`hash`,`gin`,`gist`,`brin`];function xs({open:e,onOpenChange:t,storeRef:n,tables:r}){let i=te(),{mutate:a,isPending:o,reset:s}=Qo(),[c,l]=(0,Z.useState)(``),[u,d]=(0,Z.useState)(r[0]??``),[f,p]=(0,Z.useState)(`column_name`),[m,h]=(0,Z.useState)(`btree`),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(!1),[C,w]=(0,Z.useState)(``),[T,E]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(!1),[k,A]=(0,Z.useState)(``),[j,M]=(0,Z.useState)(!1),[N,P]=(0,Z.useState)(``),[F,L]=(0,Z.useState)(``),[R,z]=(0,Z.useState)(null),[B,V]=(0,Z.useState)(null),H=(0,Z.useMemo)(()=>hs({name:c.trim()||`index_name`,table:u.trim()||`table_name`,columns:f,method:m,unique:g,ifNotExists:v,concurrently:D,nullsNotDistinct:j,...C.trim()===``?{}:{where:C},...k.trim()===``?{}:{include:k},...N.trim()===``?{}:{with:N}}),[c,u,f,m,g,v,C,D,k,j,N]);(0,Z.useEffect)(()=>{if(!e)return;let t=r[0]??``;l(``),d(t),p(`column_name`),h(`btree`),_(!1),y(!1),w(``),E(!1),O(!1),A(``),M(!1),P(``),V(null),z(null),L(hs({name:`index_name`,table:t||`table_name`,columns:`column_name`})),s()},[e,r,s]),(0,Z.useEffect)(()=>{L(H)},[H]);let ee=e=>{V(e.id),p(e.columns),h(e.method??`btree`),_(e.unique===!0),w(e.where??``),c.trim()===``&&l(e.id.replaceAll(`-`,`_`))},ne=()=>{if(!_s(F)){z(`This sheet runs CREATE INDEX only`);return}z(null),a({ref:n,sql:F,allowWrite:!0},{onSuccess:()=>{i.invalidateQueries({queryKey:_r}),t(!1)},onError:e=>z(e instanceof Error?e.message:String(e))})};return(0,Q.jsx)(re,{open:e,onOpenChange:t,children:(0,Q.jsxs)(W,{side:`right`,className:`flex w-full flex-col gap-0 overflow-hidden data-[side=right]:sm:max-w-xl`,"data-slot":`sql-index-sheet`,onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),o||ne())},children:[(0,Q.jsx)(oe,{className:`shrink-0 gap-2 border-b border-border/50`,children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsx)(`div`,{className:`flex size-9 items-center justify-center rounded-full border border-border/50 bg-muted/20`,children:(0,Q.jsx)(b,{icon:Re,className:`size-4`,"aria-hidden":!0})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(be,{className:`text-sm`,children:`Create index`}),(0,Q.jsx)(ge,{className:`text-[11px]`,children:"Review the `CREATE INDEX` SQL before it runs"})]})]})}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:[(0,Q.jsx)(Ba,{templates:ms,selectedId:B,onSelect:ee}),(0,Q.jsxs)(pi,{children:[(0,Q.jsx)(Y,{label:`Index name`,split:`start`,children:(0,Q.jsx)(x,{value:c,onChange:e=>l(e.target.value),placeholder:`index_name`,flat:!0,className:S(X,`font-mono`)})}),(0,Q.jsx)(Y,{label:`Table`,split:`end`,children:(0,Q.jsxs)(ka,{value:u,onValueChange:d,children:[(0,Q.jsx)(Aa,{flat:!0,className:S(X,`font-mono`),children:(0,Q.jsx)(ja,{placeholder:`Select a table`})}),(0,Q.jsx)(Ma,{children:r.map(e=>(0,Q.jsx)(Na,{value:e,className:`font-mono text-[12px]`,children:e},e))})]})})]}),(0,Q.jsx)(Y,{label:`Columns`,children:(0,Q.jsx)(x,{value:f,onChange:e=>p(e.target.value),placeholder:`column_name`,flat:!0,className:S(X,`font-mono`)})}),(0,Q.jsx)(_i,{label:`Method`,children:bs.map(e=>(0,Q.jsx)(fi,{active:m===e,onClick:()=>h(e),children:e},e))}),(0,Q.jsx)(Y,{label:`WHERE`,children:(0,Q.jsx)(x,{value:C,onChange:e=>w(e.target.value),placeholder:`optional`,flat:!0,className:S(X,`font-mono`)})}),(0,Q.jsxs)(pi,{children:[(0,Q.jsx)(mi,{label:`Unique`,className:`border-r border-b-0`,children:(0,Q.jsx)(Ra,{size:`sm`,checked:g,onCheckedChange:_,ariaLabel:`Unique`})}),(0,Q.jsx)(mi,{label:`Skip if it exists`,className:`border-b-0`,children:(0,Q.jsx)(Ra,{size:`sm`,checked:v,onCheckedChange:y,ariaLabel:`Skip if it already exists`})})]}),(0,Q.jsx)(hi,{label:`Options`,children:(0,Q.jsx)(za,{open:T,extraCount:gs({concurrently:D,include:k,nullsNotDistinct:j,with:N}),onOpenChange:E,controls:`sql-index-advanced`})}),T?(0,Q.jsxs)(`div`,{id:`sql-index-advanced`,children:[(0,Q.jsx)(mi,{label:`Concurrently`,children:(0,Q.jsx)(Ra,{size:`sm`,checked:D,onCheckedChange:O,ariaLabel:`Create index concurrently`})}),(0,Q.jsx)(Y,{label:`INCLUDE`,children:(0,Q.jsx)(x,{value:k,onChange:e=>A(e.target.value),placeholder:`covering columns`,flat:!0,className:S(X,`font-mono`)})}),(0,Q.jsx)(mi,{label:`NULLS NOT DISTINCT`,children:(0,Q.jsx)(Ra,{size:`sm`,checked:j,onCheckedChange:M,ariaLabel:`NULLS NOT DISTINCT`})}),(0,Q.jsx)(Y,{label:`WITH`,children:(0,Q.jsx)(x,{value:N,onChange:e=>P(e.target.value),placeholder:`fillfactor = 70`,flat:!0,className:S(X,`font-mono`)})})]}):null]}),(0,Q.jsxs)(`div`,{className:`shrink-0 border-t border-border/50`,"data-slot":`sql-index-sql-dock`,children:[(0,Q.jsx)(hi,{label:`SQL`,hint:`Editable before it runs`}),(0,Q.jsx)($o,{value:F,onChange:L,onSubmit:o?void 0:ne,label:`CREATE INDEX SQL`,className:`min-h-36 max-h-48`}),R?(0,Q.jsx)(bi,{slot:`sql-index-error`,children:R}):null]}),(0,Q.jsxs)(I,{children:[(0,Q.jsx)(gi,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(gi,{variant:`default`,disabled:o||!_s(F),onClick:ne,"data-slot":`sql-index-submit`,children:o?`Creating…`:`Create index`})]})]})})}var Ss=[{id:`after-insert`,title:`After insert`,detail:`AFTER INSERT for each row — run a function when a row is added.`,timing:`AFTER`,events:[`INSERT`],level:`ROW`},{id:`after-update`,title:`After update`,detail:`AFTER UPDATE for each row — react when a row changes.`,timing:`AFTER`,events:[`UPDATE`],level:`ROW`},{id:`before-delete`,title:`Before delete`,detail:`BEFORE DELETE for each row — inspect or block a delete.`,timing:`BEFORE`,events:[`DELETE`],level:`ROW`},{id:`after-write`,title:`After write`,detail:`AFTER INSERT OR UPDATE OR DELETE — one function for any write.`,timing:`AFTER`,events:[`INSERT`,`UPDATE`,`DELETE`],level:`ROW`}];function Cs(e){let t=Ds(e.events,e.updateOf),n=[`CREATE ${e.orReplace===!0?`OR REPLACE `:``}${e.constraint===!0?`CONSTRAINT `:``}TRIGGER ${Dn(e.name)}`,` ${e.timing} ${t}`,` ON ${Dn(e.table)}`];e.constraint===!0&&e.defer===`deferred`?n.push(` DEFERRABLE INITIALLY DEFERRED`):e.constraint===!0&&e.defer===`immediate`&&n.push(` DEFERRABLE INITIALLY IMMEDIATE`);let r=Os(e.referencingOld,e.referencingNew);r!==``&&n.push(` ${r}`),n.push(` FOR EACH ${e.level}`);let i=e.when?.trim()??``;i!==``&&Ts(i)&&n.push(` WHEN (${i})`);let a=e.functionArgs!==void 0&&Ts(e.functionArgs.trim())?e.functionArgs.trim():``;return n.push(` EXECUTE FUNCTION ${ks(e.functionName)}(${a});`),n.join(`
18
+ `)}Cs({name:`trigger_name`,table:`table_name`,timing:`AFTER`,events:[`INSERT`,`UPDATE`,`DELETE`],level:`ROW`,functionName:`function_name`});function ws(e){return/^\s*CREATE\s+(OR\s+REPLACE\s+)?(CONSTRAINT\s+)?TRIGGER\b/i.test(e)}function Ts(e){let t=e.trim();return t.length>0&&t.length<=2e3&&!/;/.test(t)&&!/--/.test(t)&&!/\/\*/.test(t)}function Es(e){return+(e.constraint===!0)+(e.defer===void 0?0:1)+ +!!e.updateOf?.trim()+ +!!e.referencingOld?.trim()+ +!!e.referencingNew?.trim()+ +!!e.functionArgs?.trim()+ +!!e.events.includes(`TRUNCATE`)}function Ds(e,t){let n=e.length>0?e:[`INSERT`],r=t?.trim()??``;return n.map(e=>e===`UPDATE`&&r!==``&&Ts(r)?`UPDATE OF ${r}`:e).join(` OR `)}function Os(e,t){let n=[],r=e?.trim()??``,i=t?.trim()??``;return r!==``&&Ts(r)&&n.push(`OLD TABLE AS ${Dn(r)}`),i!==``&&Ts(i)&&n.push(`NEW TABLE AS ${Dn(i)}`),n.length>0?`REFERENCING ${n.join(` `)}`:``}function ks(e){let t=e.trim().replace(/\(\s*\)$/,``);return(t.length>0?t:`function_name`).split(`.`).map(e=>Dn(e)).join(`.`)}var As=[`BEFORE`,`AFTER`,`INSTEAD OF`],js=[`INSERT`,`UPDATE`,`DELETE`],Ms=[`ROW`,`STATEMENT`],Ns=[{id:`immediate`,label:`IMMEDIATE`},{id:`deferred`,label:`DEFERRED`}];function Ps({open:e,onOpenChange:t,storeRef:n,tables:r}){let i=te(),{mutate:a,isPending:o,reset:s}=Qo(),[c,l]=(0,Z.useState)(``),[u,d]=(0,Z.useState)(r[0]??``),[f,p]=(0,Z.useState)(`AFTER`),[m,h]=(0,Z.useState)([`INSERT`]),[g,_]=(0,Z.useState)(`ROW`),[v,y]=(0,Z.useState)(``),[C,w]=(0,Z.useState)(``),[T,E]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(!1),[k,A]=(0,Z.useState)(!1),[j,M]=(0,Z.useState)(null),[N,P]=(0,Z.useState)(``),[F,L]=(0,Z.useState)(``),[R,z]=(0,Z.useState)(``),[B,V]=(0,Z.useState)(``),[H,ee]=(0,Z.useState)(``),[ne,U]=(0,Z.useState)(null),[ie,ae]=(0,Z.useState)(null),se=(0,Z.useMemo)(()=>Cs({name:c.trim()||`trigger_name`,table:u.trim()||`table_name`,timing:f,events:m,level:g,functionName:v.trim()||`function_name`,orReplace:T,constraint:k,...C.trim()===``?{}:{when:C},...j===null?{}:{defer:j},...N.trim()===``?{}:{updateOf:N},...F.trim()===``?{}:{referencingOld:F},...R.trim()===``?{}:{referencingNew:R},...B.trim()===``?{}:{functionArgs:B}}),[c,u,f,m,g,v,C,T,k,j,N,F,R,B]);(0,Z.useEffect)(()=>{if(!e)return;let t=r[0]??``;l(``),d(t),p(`AFTER`),h([`INSERT`]),_(`ROW`),y(``),w(``),E(!1),O(!1),A(!1),M(null),P(``),L(``),z(``),V(``),ae(null),U(null),ee(Cs({name:`trigger_name`,table:t||`table_name`,timing:`AFTER`,events:[`INSERT`],level:`ROW`,functionName:`function_name`})),s()},[e,r,s]),(0,Z.useEffect)(()=>{ee(se)},[se]);let ce=e=>{ae(e.id),p(e.timing),h(e.events),_(e.level),c.trim()===``&&l(e.id.replaceAll(`-`,`_`))},le=e=>{if(m.includes(e)){if(m.length===1)return;h(m.filter(t=>t!==e));return}let t=[...m,e];h(t),e===`TRUNCATE`&&_(`STATEMENT`)},ue=()=>{if(!ws(H)){U(`This sheet runs CREATE TRIGGER only`);return}U(null),a({ref:n,sql:H,allowWrite:!0},{onSuccess:()=>{i.invalidateQueries({queryKey:_r}),t(!1)},onError:e=>U(e instanceof Error?e.message:String(e))})};return(0,Q.jsx)(re,{open:e,onOpenChange:t,children:(0,Q.jsxs)(W,{side:`right`,className:`flex w-full flex-col gap-0 overflow-hidden data-[side=right]:sm:max-w-xl`,"data-slot":`sql-trigger-sheet`,onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),o||ue())},children:[(0,Q.jsx)(oe,{className:`shrink-0 gap-2 border-b border-border/50`,children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsx)(`div`,{className:`flex size-9 items-center justify-center rounded-full border border-border/50 bg-muted/20`,children:(0,Q.jsx)(b,{icon:Hi,className:`size-4`,"aria-hidden":!0})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(be,{className:`text-sm`,children:`New trigger`}),(0,Q.jsx)(ge,{className:`text-[11px]`,children:"Review the `CREATE TRIGGER` SQL before it runs"})]})]})}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:[(0,Q.jsx)(Ba,{templates:Ss,selectedId:ie,onSelect:ce}),(0,Q.jsxs)(pi,{children:[(0,Q.jsx)(Y,{label:`Trigger name`,split:`start`,children:(0,Q.jsx)(x,{value:c,onChange:e=>l(e.target.value),placeholder:`trigger_name`,flat:!0,className:S(X,`font-mono`)})}),(0,Q.jsx)(Y,{label:`Table`,split:`end`,children:(0,Q.jsxs)(ka,{value:u,onValueChange:d,children:[(0,Q.jsx)(Aa,{flat:!0,className:S(X,`font-mono`),children:(0,Q.jsx)(ja,{placeholder:`Select a table`})}),(0,Q.jsx)(Ma,{children:r.map(e=>(0,Q.jsx)(Na,{value:e,className:`font-mono text-[12px]`,children:e},e))})]})})]}),(0,Q.jsx)(_i,{label:`Timing`,children:As.map(e=>(0,Q.jsx)(fi,{active:f===e,onClick:()=>p(e),children:e},e))}),(0,Q.jsx)(_i,{label:`Events`,children:js.map(e=>(0,Q.jsx)(fi,{active:m.includes(e),onClick:()=>le(e),children:e},e))}),(0,Q.jsx)(_i,{label:`For each`,children:Ms.map(e=>(0,Q.jsx)(fi,{active:g===e,onClick:()=>_(e),children:e},e))}),(0,Q.jsxs)(pi,{children:[(0,Q.jsx)(Y,{label:`Function`,split:`start`,children:(0,Q.jsx)(x,{value:v,onChange:e=>y(e.target.value),placeholder:`function_name`,flat:!0,className:S(X,`font-mono`)})}),(0,Q.jsx)(Y,{label:`WHEN`,split:`end`,children:(0,Q.jsx)(x,{value:C,onChange:e=>w(e.target.value),placeholder:`optional`,flat:!0,className:S(X,`font-mono`)})})]}),(0,Q.jsx)(mi,{label:`Replace if it already exists`,children:(0,Q.jsx)(Ra,{size:`sm`,checked:T,onCheckedChange:E,ariaLabel:`Replace if it already exists`})}),(0,Q.jsx)(hi,{label:`Options`,children:(0,Q.jsx)(za,{open:D,extraCount:Es({constraint:k,...j===null?{}:{defer:j},updateOf:N,referencingOld:F,referencingNew:R,functionArgs:B,events:m}),onOpenChange:O,controls:`sql-trigger-advanced`})}),D?(0,Q.jsxs)(`div`,{id:`sql-trigger-advanced`,children:[(0,Q.jsx)(_i,{label:`Also fire on`,children:(0,Q.jsx)(fi,{active:m.includes(`TRUNCATE`),onClick:()=>le(`TRUNCATE`),children:`TRUNCATE`})}),m.includes(`UPDATE`)?(0,Q.jsx)(Y,{label:`UPDATE OF`,children:(0,Q.jsx)(x,{value:N,onChange:e=>P(e.target.value),placeholder:`column_name`,flat:!0,className:S(X,`font-mono`)})}):null,(0,Q.jsx)(Y,{label:`Function args`,children:(0,Q.jsx)(x,{value:B,onChange:e=>V(e.target.value),placeholder:`optional`,flat:!0,className:S(X,`font-mono`)})}),(0,Q.jsx)(mi,{label:`CONSTRAINT`,children:(0,Q.jsx)(Ra,{size:`sm`,checked:k,onCheckedChange:e=>{A(e),e||M(null)},ariaLabel:`CONSTRAINT trigger`})}),k?(0,Q.jsx)(_i,{label:`Defer`,children:Ns.map(e=>(0,Q.jsx)(fi,{active:j===e.id,onClick:()=>M(j===e.id?null:e.id),children:e.label},e.id))}):null,(0,Q.jsxs)(pi,{children:[(0,Q.jsx)(Y,{label:`OLD TABLE AS`,split:`start`,children:(0,Q.jsx)(x,{value:F,onChange:e=>L(e.target.value),placeholder:`optional`,flat:!0,className:S(X,`font-mono`)})}),(0,Q.jsx)(Y,{label:`NEW TABLE AS`,split:`end`,children:(0,Q.jsx)(x,{value:R,onChange:e=>z(e.target.value),placeholder:`optional`,flat:!0,className:S(X,`font-mono`)})})]})]}):null]}),(0,Q.jsxs)(`div`,{className:`shrink-0 border-t border-border/50`,"data-slot":`sql-trigger-sql-dock`,children:[(0,Q.jsx)(hi,{label:`SQL`,hint:`Editable before it runs`}),(0,Q.jsx)($o,{value:H,onChange:ee,onSubmit:o?void 0:ue,label:`CREATE TRIGGER SQL`,className:`min-h-36 max-h-48`}),ne?(0,Q.jsx)(bi,{slot:`sql-trigger-error`,children:ne}):null]}),(0,Q.jsxs)(I,{children:[(0,Q.jsx)(gi,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(gi,{variant:`default`,disabled:o||!ws(H),onClick:ue,"data-slot":`sql-trigger-submit`,children:o?`Creating…`:`Create trigger`})]})]})})}function Fs({open:e,onOpenChange:t,phrase:n,title:r,description:i,willNotFire:a,pending:o=!1,error:s,onConfirm:c}){return(0,Q.jsx)(Si,{open:e,onOpenChange:t,phrase:n,title:r,description:i,pending:o,error:s,slot:`store-confirm-sheet`,onConfirm:c,children:a&&(a.signals.length>0||a.channels.length>0)?(0,Q.jsx)(`div`,{className:`px-4 py-3`,children:(0,Q.jsxs)(`div`,{className:`rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-800 dark:text-amber-300`,role:`status`,"data-slot":`will-not-fire`,children:[(0,Q.jsx)(`p`,{className:`font-medium`,children:`This direct edit will not fire:`}),a.signals.length>0?(0,Q.jsxs)(`p`,{children:[`signals: `,a.signals.join(`, `)]}):null,a.channels.length>0?(0,Q.jsxs)(`p`,{children:[`channels: `,a.channels.join(`, `)]}):null]})}):null})}var Is=`M5 13l4 4L19 7`,Ls=`M6 12h12`;function Rs({checked:e,onCheckedChange:t,disabled:n,indeterminate:r,label:i,className:a,id:o,"aria-label":s,"aria-describedby":c}){let l=(0,Z.useId)(),u=o??l,d=ti(),f=e||r,p=r?Ls:Is;return(0,Q.jsxs)(`label`,{htmlFor:u,className:S(`inline-flex items-center gap-3`,n?`cursor-not-allowed`:`cursor-pointer`,a),children:[(0,Q.jsx)(Xr.button,{id:u,type:`button`,role:`checkbox`,"aria-checked":r?`mixed`:e,"aria-label":s,"aria-describedby":c,disabled:n,onClick:()=>{n||t(!e)},whileTap:d||n?void 0:{scale:.94},transition:{duration:.12,ease:Wr},"data-state":e?`checked`:r?`indeterminate`:`unchecked`,className:S(`relative inline-flex size-4 shrink-0 items-center justify-center overflow-hidden rounded-sm border-2 outline-none transition-colors duration-200`,`focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background`,`disabled:cursor-not-allowed disabled:opacity-60`,f?`border-foreground bg-foreground text-background`:`border-muted-foreground/40 bg-background hover:border-muted-foreground`),children:(0,Q.jsx)(it,{initial:!1,children:f?(0,Q.jsxs)(Xr.svg,{className:`pointer-events-none absolute inset-0 m-auto block size-2.5`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:3,strokeLinecap:`round`,strokeLinejoin:`round`,initial:d?{opacity:1}:{opacity:0,scale:.5},animate:d?{opacity:1}:{opacity:1,scale:1},exit:d?{opacity:0}:{opacity:0,scale:.5},transition:d?{duration:0}:{duration:.16,ease:Wr},"aria-hidden":!0,children:[(0,Q.jsx)(`title`,{children:r?`Partially selected`:`Selected`}),(0,Q.jsx)(Xr.path,{d:p,initial:d?{pathLength:1}:{pathLength:0},animate:{pathLength:1},transition:d?{duration:0}:{duration:r?.2:.3,ease:Wr,delay:.04}})]},r?`indeterminate`:`checked`):null})}),i?(0,Q.jsx)(`span`,{children:i}):null]})}function zs({className:e,...t}){return(0,Q.jsx)(`nav`,{"aria-label":`breadcrumb`,"data-slot":`breadcrumb`,className:S(e),...t})}function Bs({className:e,...t}){return(0,Q.jsx)(`ol`,{"data-slot":`breadcrumb-list`,className:S(`flex flex-wrap items-center gap-1.5 text-sm wrap-break-word text-muted-foreground`,e),...t})}function Vs({className:e,...t}){return(0,Q.jsx)(`li`,{"data-slot":`breadcrumb-item`,className:S(`inline-flex items-center gap-1`,e),...t})}function Hs({className:e,render:t,...n}){return $r({defaultTagName:`a`,props:C({className:S(`transition-colors hover:text-foreground`,e)},n),render:t,state:{slot:`breadcrumb-link`}})}function Us({className:e,...t}){return(0,Q.jsx)(`span`,{"data-slot":`breadcrumb-page`,role:`link`,"aria-disabled":`true`,"aria-current":`page`,className:S(`font-normal text-foreground`,e),...t})}function Ws({children:e,className:t,...n}){return(0,Q.jsx)(`li`,{"data-slot":`breadcrumb-separator`,role:`presentation`,"aria-hidden":`true`,className:S(`[&>svg]:size-3.5`,t),...n,children:e??(0,Q.jsx)(b,{icon:ut,className:`cn-rtl-flip`})})}function Gs(e){return e.length===0||e.startsWith(`/`)||e.includes(`..`)?!1:/^[\x20-\x7E]+$/.test(e)}function Ks(e,t=`file`){let n=e.normalize(`NFKD`).replace(/\p{M}/gu,``).toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/-+/g,`-`).replace(/^[-.]+|[-.]+$/g,``);return n.length>0?n:t}function qs(e){let t=e.replace(/^\/+|\/+$/g,``).split(`/`).filter(e=>e.length>0);return t.length===0?``:`${t.map(e=>Gs(e)?e:Ks(e,`folder`)).join(`/`)}/`}function Js(e){let t=e.replace(/\/+$/,``),n=t.lastIndexOf(`/`),r=n===-1?t:t.slice(n+1),i=r.lastIndexOf(`.`);if(i<=0||i===r.length-1)return``;let a=r.slice(i+1).toLowerCase();return/^[a-z0-9]+$/.test(a)?`.${a}`:``}function Ys(){let e=new Uint8Array(4);return crypto.getRandomValues(e),[...e].map(e=>e.toString(16).padStart(2,`0`)).join(``)}function Xs(e,t=``,n=Ys()){let r=Js(e),i=e.replace(/\/+$/,``),a=i.lastIndexOf(`/`),o=a===-1?i:i.slice(a+1),s=r.length>0?o.slice(0,-r.length):o;return`${qs(t)}${Ks(s)}-${n}${r}`}var Zs=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`avif`,`bmp`,`ico`]),Qs=new Set([`txt`,`md`,`csv`,`tsv`,`log`,`json`,`xml`,`yml`,`yaml`,`toml`,`ini`,`cfg`,`conf`]),$s=new Set(`ts.tsx.js.jsx.mjs.cjs.css.html.htm.sql.go.rs.py.rb.sh.bash.zsh.java.kt.c.h.cpp.hpp.swift.proto.graphql.vue.svelte`.split(`.`)),ec=new Set([`mp4`,`webm`,`mov`,`m4v`,`ogv`]),tc=new Set([`mp3`,`wav`,`ogg`,`m4a`,`aac`,`flac`,`opus`,`oga`]),nc=new Set([`zip`,`tar`,`gz`,`tgz`,`7z`]);function rc(e){let t=e.replace(/\/+$/,``),n=t.lastIndexOf(`/`);return n===-1?t:t.slice(n+1)}function ic(e){let t=rc(e),n=t.lastIndexOf(`.`);return n<=0||n===t.length-1?``:t.slice(n+1).toLowerCase()}function ac(e){let t=ic(e);return t===`pdf`?`pdf`:t===`patch`||t===`diff`?`patch`:Zs.has(t)?`image`:ec.has(t)?`video`:tc.has(t)?`audio`:nc.has(t)?`archive`:$s.has(t)?`code`:Qs.has(t)?`text`:`binary`}function oc(e){switch(e){case`image`:return`Image`;case`text`:return`Text`;case`code`:return`Code`;case`pdf`:return`PDF`;case`patch`:return`Patch`;case`video`:return`Video`;case`audio`:return`Audio`;case`archive`:return`Archive`;case`binary`:return`Binary`}}function sc(e){return e===`text`||e===`code`||e===`patch`}function cc(e,t){return e===`pdf`?`application/pdf`:t}function lc(e){switch(e){case`image`:return`image`;case`text`:case`code`:case`patch`:return`text`;case`pdf`:return`pdf`;case`video`:return`video`;case`audio`:return`audio`;default:return`none`}}function uc(e,t){if(ic(t)!==`json`)return e;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function dc(e){let t=e.replace(/^\/+/,``).replace(/\/+$/,``);return t.length===0?``:`${t}/`}function fc(e){let t=dc(e);if(t.length===0)return``;let n=t.slice(0,-1),r=n.lastIndexOf(`/`);return r===-1?``:`${n.slice(0,r+1)}`}function pc(e){let t=dc(e);if(t.length===0)return[];let n=t.slice(0,-1).split(`/`),r=[],i=``;for(let e of n)i=`${i}${e}/`,r.push({name:e,prefix:i});return r}function mc(e,t){let n=pc(e),r=n[0];return r&&r.name===t?n.slice(1):n}function hc(e,t){let n=dc(t),r=new Map,i=[];for(let t of e){if(n.length>0&&!t.key.startsWith(n))continue;let e=t.key.slice(n.length);if(e.length===0)continue;let a=e.indexOf(`/`);if(a===-1){i.push({kind:`file`,name:t.originalName??e,key:t.key,sizeBytes:t.sizeBytes??0,warnings:t.warnings??[]});continue}let o=e.slice(0,a);if(o.length===0)continue;let s=`${n}${o}/`,c=r.get(s),l=t.sizeBytes??0,u=[...t.warnings??[]];c?(c.objectCount+=1,c.sizeBytes+=l,c.warnings.push(...u)):r.set(s,{name:o,prefix:s,objectCount:1,sizeBytes:l,warnings:u})}let a=[...r.values()].map(e=>({kind:`folder`,name:e.name,prefix:e.prefix,objectCount:e.objectCount,sizeBytes:e.sizeBytes,warnings:e.warnings})).sort((e,t)=>e.name.localeCompare(t.name));return i.sort((e,t)=>e.name.localeCompare(t.name)),{folders:a,files:i}}function gc(e,t){let n=t.trim().toLowerCase();return n.length===0?[]:e.filter(e=>{let t=(e.originalName??rc(e.key)).toLowerCase();return e.key.toLowerCase().includes(n)||t.includes(n)}).map(e=>({kind:`file`,name:e.originalName??rc(e.key),key:e.key,sizeBytes:e.sizeBytes??0,warnings:e.warnings??[]})).sort((e,t)=>e.key.localeCompare(t.key))}function _c(e,t){let n=dc(t);return n.length===0?e.map(e=>e.key):e.filter(e=>e.key.startsWith(n)).map(e=>e.key)}var vc={folder:`border-sky-500/35 bg-sky-500/10 text-sky-700 dark:text-sky-400`,image:`border-violet-500/35 bg-violet-500/10 text-violet-700 dark:text-violet-400`,text:`border-border/60 bg-muted/50 text-muted-foreground`,code:`border-emerald-500/35 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`,pdf:`border-rose-500/35 bg-rose-500/10 text-rose-700 dark:text-rose-400`,patch:`border-amber-500/35 bg-amber-500/10 text-amber-700 dark:text-amber-400`,video:`border-fuchsia-500/35 bg-fuchsia-500/10 text-fuchsia-700 dark:text-fuchsia-400`,audio:`border-teal-500/35 bg-teal-500/10 text-teal-700 dark:text-teal-400`,archive:`border-orange-500/35 bg-orange-500/10 text-orange-700 dark:text-orange-400`,binary:`border-border/60 bg-muted/40 text-muted-foreground`};function yc({kind:e,className:t,well:n=!0}){let r=e===`folder`?yr:e===`image`?Ti:e===`pdf`?hn:e===`video`?Oe:e===`audio`?Fi:Je;return(0,Q.jsx)(`span`,{className:S(`inline-flex shrink-0 items-center justify-center`,n&&`size-7 rounded-md border`,n?vc[e]:k(vc[e]),t),"aria-hidden":!0,children:(0,Q.jsx)(b,{icon:r,className:`size-3.5`})})}function bc(e){let t=``,n=32768;for(let r=0;r<e.length;r+=n)t+=String.fromCharCode(...e.subarray(r,r+n));return btoa(t)}function xc(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}function Sc(e,t){return e===`utf8`?new TextEncoder().encode(t):xc(t)}function Cc(e,t,n){let r=new Blob([wc(t)],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=e,a.click(),URL.revokeObjectURL(i)}function wc(e){let t=new Uint8Array(e.byteLength);return t.set(e),t.buffer}var Tc=[`console.store.object`];function Ec(e){if(!e.error)return null;let t=Error(e.error.message??e.error.code);return t.code=e.error.code,t.data=e.error.data,t}function Dc(e,t){return A({queryKey:[...Tc,e],enabled:t&&e!==null,queryFn:async()=>{if(!e)throw Error(`Missing file get input`);let t=await xe(e),n=Ec(t);if(n)throw n;if(!t.data)throw Error(`Empty store object`);return t.data}})}function Oc(){let e=te();return Yr({mutationFn:async e=>{let t=await se({ref:e.ref,key:e.key,...e.tenant?{tenant:e.tenant}:{},patch:{body:e.body,encoding:e.encoding,...e.originalName?{originalName:e.originalName}:{}},commit:!0}),n=Ec(t);if(n)throw n;if(!t.data)throw Error(`Empty store file put`);return t.data},onSuccess:async()=>{await Promise.all([e.invalidateQueries({queryKey:_r}),e.invalidateQueries({queryKey:Tc}),e.invalidateQueries({queryKey:Dt})])}})}function kc({open:e,onOpenChange:t,storeRef:n,tenant:r,objectKey:i,sizeBytes:a,originalName:o,warnings:s=[],onDelete:c}){let l=Dc((0,Z.useMemo)(()=>i?{ref:n,key:i,...r?{tenant:r}:{}}:null,[n,i,r]),e&&i!==null),u=i?ac(i):null,d=i?rc(i):null,f=(0,Z.useMemo)(()=>l.data?Sc(l.data.encoding,l.data.body):null,[l.data]),p=u?lc(u):`none`,m=(0,Z.useMemo)(()=>{if(!l.data||!f||l.data.truncated||p!==`image`&&p!==`pdf`&&p!==`video`&&p!==`audio`)return null;let e=new Blob([wc(f)],{type:cc(p,l.data.contentType)});return URL.createObjectURL(e)},[l.data,f,p]);if((0,Z.useEffect)(()=>()=>{m&&URL.revokeObjectURL(m)},[m]),!i||!u||!d)return(0,Q.jsx)(Q.Fragment,{});let h=l.data&&sc(u)&&l.data.encoding===`utf8`?l.data.body:null;return(0,Q.jsx)(re,{open:e,onOpenChange:t,children:(0,Q.jsxs)(W,{side:`right`,showOverlay:!1,className:`gap-0 p-0 sm:max-w-lg`,"data-slot":`file-preview`,children:[(0,Q.jsx)(oe,{className:`gap-2 border-b border-border/50`,children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-2.5 pr-8`,children:[(0,Q.jsx)(yc,{kind:u}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(be,{className:`truncate text-sm`,children:l.data?.originalName??o??d}),(0,Q.jsxs)(ge,{className:`font-mono text-[11px]`,children:[oc(u),(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`mx-1 text-border`,children:`·`}),Mt(l.data?.sizeBytes??a??0)]})]})]})}),(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:l.isLoading?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 p-4`,children:[(0,Q.jsx)(si,{className:`h-28 w-full`}),(0,Q.jsx)(si,{className:`h-3 w-2/3`}),(0,Q.jsx)(si,{className:`h-3 w-1/2`})]}):l.isError?(0,Q.jsx)(`p`,{className:`px-4 py-4 text-[11px] text-destructive`,children:l.error.message}):(0,Q.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Q.jsx)(Ac,{kind:u,name:d,mode:p,text:h,objectUrl:m,truncated:l.data?.truncated??!1}),(0,Q.jsxs)(`dl`,{className:`flex flex-col gap-2 border-t border-border/50 px-4 py-3 text-[11px]`,children:[l.data?.originalName??o?(0,Q.jsx)(Mc,{label:`Original name`,value:l.data?.originalName??o??``}):null,(0,Q.jsx)(Mc,{label:`Key`,mono:!0,value:i}),(0,Q.jsx)(Mc,{label:`Type`,value:l.data?.contentType??`—`}),(0,Q.jsx)(Mc,{label:`Size`,value:Mt(l.data?.sizeBytes??a??0)})]}),s.length>0||(l.data?.warnings.length??0)>0?(0,Q.jsx)(`ul`,{className:`flex flex-col gap-1 border-t border-amber-500/20 bg-amber-500/5 px-4 py-2 text-[11px] text-amber-800 dark:text-amber-300`,children:(l.data?.warnings??s).map(e=>(0,Q.jsxs)(`li`,{className:`flex items-start gap-1.5`,children:[(0,Q.jsx)(b,{icon:nt,className:`mt-0.5 size-3 shrink-0`}),e.message]},e.code))}):null]})}),(0,Q.jsxs)(`div`,{className:`mt-auto flex items-center justify-between gap-2 border-t border-border/50 px-4 py-2.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsxs)(G,{type:`button`,variant:`outline`,size:`sm`,disabled:!f||l.data?.truncated,onClick:()=>{f&&l.data&&Cc(d,f,l.data.contentType)},children:[(0,Q.jsx)(b,{icon:hn,className:`size-3.5`,"aria-hidden":!0}),`Download`]}),(0,Q.jsx)(G,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`Copy key`,onClick:()=>void navigator.clipboard.writeText(i),children:(0,Q.jsx)(b,{icon:Pe})})]}),c?(0,Q.jsxs)(G,{type:`button`,variant:`destructive`,size:`sm`,onClick:c,"data-slot":`file-preview-delete`,children:[(0,Q.jsx)(b,{icon:pn,className:`size-3.5`,"aria-hidden":!0}),`Delete`]}):null]})]})})}function Ac({kind:e,name:t,mode:n,text:r,objectUrl:i,truncated:a}){if(a&&n!==`text`)return(0,Q.jsxs)(`p`,{className:`px-4 py-6 text-center text-[11px] text-muted-foreground`,children:[oc(e),` is larger than the preview window — download to open.`]});if(n===`image`&&i)return(0,Q.jsx)(`div`,{className:`flex items-center justify-center bg-[repeating-conic-gradient(var(--border)_0%_25%,transparent_0%_50%)] bg-size-[12px_12px] p-4`,children:(0,Q.jsx)(`img`,{src:i,alt:``,className:`max-h-72 max-w-full rounded-md border border-border/60 bg-background object-contain`})});if(n===`pdf`&&i)return(0,Q.jsx)(`iframe`,{title:t,src:i,className:`h-80 w-full border-0 bg-background`});if(n===`video`&&i)return(0,Q.jsx)(`div`,{className:`bg-black p-2`,children:(0,Q.jsx)(`video`,{src:i,controls:!0,className:`max-h-72 w-full`})});if(n===`audio`&&i)return(0,Q.jsx)(`div`,{className:`px-4 py-6`,children:(0,Q.jsx)(`audio`,{src:i,controls:!0,className:`w-full`})});if(n===`text`&&r!==null){let e=ic(t);return e===`csv`||e===`tsv`?(0,Q.jsx)(jc,{text:r,delimiter:e===`tsv`?` `:`,`}):(0,Q.jsxs)(`pre`,{className:`max-h-72 overflow-auto px-4 py-3 font-mono text-[11px] leading-4 text-foreground/80`,children:[uc(r,t),a?`
19
+ … truncated`:``]})}return(0,Q.jsxs)(`p`,{className:`px-4 py-6 text-center text-[11px] text-muted-foreground`,children:[oc(e),` — download to open`,a?` (preview truncated)`:``,`.`]})}function jc({text:e,delimiter:t}){let n=e.split(/\r?\n/).filter(e=>e.length>0).slice(0,40).map(e=>e.split(t));return(0,Q.jsx)(`div`,{className:`max-h-72 overflow-auto`,children:(0,Q.jsx)(`table`,{className:`w-full text-left font-mono text-[10px]`,children:(0,Q.jsx)(`tbody`,{children:n.map((e,t)=>(0,Q.jsx)(`tr`,{className:`border-b border-border/60`,children:e.map((e,t)=>(0,Q.jsx)(`td`,{className:`px-2 py-1 whitespace-nowrap text-foreground/80`,children:e},t))},t))})})})}function Mc({label:e,value:t,mono:n}){return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,Q.jsx)(`dt`,{className:`text-[10px] font-semibold tracking-[0.12em] text-muted-foreground uppercase`,children:e}),(0,Q.jsx)(`dd`,{className:S(`break-all text-foreground/80`,n&&`font-mono text-[10px]`),children:t})]})}function Nc(){let e=new Uint8Array(4);return crypto.getRandomValues(e),[...e].map(e=>e.toString(16).padStart(2,`0`)).join(``)}function Pc({open:e,onOpenChange:t,storeRef:n,tenant:r,prefix:i,existingKeys:a,pendingFiles:o=[]}){let{mutate:s,isPending:c,reset:l}=Oc(),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(``),[g,_]=(0,Z.useState)(null),[v,y]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{if(!e)return;let t=o[0]??null;_(t);let n=t?rc(t.name):``,r=Nc();p(r),d(n),h(n?Xs(n,i,r):``),y(null),l()},[e,i,o,l]);let b=async()=>{let e=u.trim();if(!g){y(`Choose a file to upload`);return}if(e.length===0){y(`Original name is required`);return}let o=m.trim().length>0?m.trim():Xs(e,i);if(a.includes(o)){y(`That key is already in this bucket`);return}let c=new Uint8Array(await g.arrayBuffer());y(null),s({ref:n,key:o,...r?{tenant:r}:{},body:bc(c),encoding:`base64`,originalName:e},{onSuccess:()=>t(!1),onError:e=>y(e instanceof Error?e.message:String(e))})};return(0,Q.jsx)(re,{open:e,onOpenChange:t,children:(0,Q.jsxs)(W,{side:`right`,showOverlay:!1,className:`gap-0 p-0 data-[side=right]:sm:max-w-md`,"data-slot":`file-upload-sheet`,children:[(0,Q.jsxs)(oe,{className:`gap-1 border-b border-border/50`,children:[(0,Q.jsx)(be,{className:`text-sm`,children:`Upload object`}),(0,Q.jsx)(ge,{className:`font-mono text-[11px]`,children:n})]}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:[(0,Q.jsx)(Y,{label:`Original name`,hint:`Shown in the browser. Unicode is fine.`,children:(0,Q.jsx)(x,{value:u,onChange:e=>{let t=e.target.value;d(t);let n=f.length>0?f:Nc();f.length===0&&p(n),h(t.trim().length>0?Xs(t.trim(),i,n):``)},"aria-label":`Original name`,flat:!0,className:X,autoFocus:!0})}),(0,Q.jsx)(Y,{label:`Object key`,hint:`URL-safe. Generated from the original name.`,children:(0,Q.jsx)(x,{value:m,readOnly:!0,"aria-label":`Object key`,flat:!0,className:S(X,`font-mono text-muted-foreground`)})}),(0,Q.jsx)(Y,{label:`File`,hint:g?`${rc(g.name)} · ${g.size} B`:void 0,children:(0,Q.jsx)(x,{type:`file`,"aria-label":`File`,flat:!0,className:S(X,`pt-1.5`),onChange:e=>{let t=e.target.files?.[0]??null;if(_(t),!t)return;let n=rc(t.name),r=f.length>0?f:Nc();f.length===0&&p(r),d(n),h(Xs(n,i,r))}})}),v?(0,Q.jsx)(bi,{slot:`file-upload-error`,children:v}):null]}),(0,Q.jsxs)(I,{children:[(0,Q.jsx)(gi,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(gi,{variant:`default`,disabled:c,onClick:()=>void b(),"data-slot":`file-upload-submit`,children:c?`Uploading…`:`Upload`})]})]})})}function Fc({store:e,child:t,tenant:n,data:r,fetching:i=!1,onRefresh:a}){let[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(``),[u,d]=(0,Z.useState)(`list`),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(new Set),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)([]),[C,w]=(0,Z.useState)(null),[T,E]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{s(``),l(``),p(null),h(new Set)},[t.effectRef]);let D=r.keys??[],O=c.trim().length>0,k=(0,Z.useMemo)(()=>O?{folders:[],files:gc(D,c)}:hc(D,o),[D,o,c,O]),A=(0,Z.useMemo)(()=>[...k.folders,...k.files],[k]),j=mc(o,t.name),M=k.files.find(e=>e.key===f)??null,N=Ia(),P=(e,t)=>{h(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},F=e=>{if(e.kind===`folder`){s(e.prefix),p(null),h(new Set);return}p(e.key)},I=()=>{if(m.size===0&&f)return[f];let e=[];for(let t of m)t.endsWith(`/`)?e.push(..._c(D,t)):e.push(t);return[...new Set(e)]};return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`file-explorer`,children:[(0,Q.jsxs)(`div`,{className:`flex h-9 shrink-0 items-center gap-1.5 border-b border-border/60 px-2`,children:[(0,Q.jsx)(J,{label:`Up one folder`,children:(0,Q.jsx)(G,{type:`button`,variant:`ghost`,size:`icon-xs`,disabled:o.length===0||O,"aria-label":`Parent folder`,onClick:()=>{s(fc(o)),p(null)},children:(0,Q.jsx)(b,{icon:at,className:`size-3.5`})})}),(0,Q.jsx)(zs,{className:`min-w-0 flex-1`,children:(0,Q.jsxs)(Bs,{className:`flex-nowrap gap-1 text-[11px]`,children:[(0,Q.jsx)(Vs,{children:o.length===0||O?(0,Q.jsx)(Us,{className:`font-mono text-[11px]`,children:t.name}):(0,Q.jsx)(Hs,{href:`#`,className:`font-mono text-[11px]`,onClick:e=>{e.preventDefault(),s(``),p(null)},children:t.name})}),j.map((e,t)=>(0,Q.jsxs)(`span`,{className:`contents`,children:[(0,Q.jsx)(Ws,{className:`mx-0`}),(0,Q.jsx)(Vs,{children:t===j.length-1?(0,Q.jsx)(Us,{className:`font-mono text-[11px]`,children:e.name}):(0,Q.jsx)(Hs,{href:`#`,className:`font-mono text-[11px]`,onClick:t=>{t.preventDefault(),s(e.prefix),p(null)},children:e.name})})]},e.prefix))]})}),(0,Q.jsxs)(`div`,{className:`relative w-44`,children:[(0,Q.jsx)(b,{icon:ei,className:`pointer-events-none absolute top-1/2 left-2 size-3 -translate-y-1/2 text-muted-foreground`}),(0,Q.jsx)(x,{value:c,onChange:e=>l(e.target.value),placeholder:`Find objects…`,"aria-label":`Find objects`,className:`h-6 border-0 bg-transparent pl-7 text-[11px] shadow-none focus-visible:border-transparent focus-visible:bg-muted/40 focus-visible:ring-0 md:text-[11px] dark:bg-transparent`})]}),(0,Q.jsx)(J,{label:u===`list`?`Grid view`:`List view`,children:(0,Q.jsx)(G,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":u===`list`?`Grid view`:`List view`,onClick:()=>d(e=>e===`list`?`grid`:`list`),children:(0,Q.jsx)(b,{icon:u===`list`?li:ct,className:`size-3.5`})})}),(0,Q.jsx)(J,{label:`Upload into this folder`,children:(0,Q.jsxs)(G,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px] text-muted-foreground`,"data-slot":`file-upload`,onClick:()=>{y([]),_(!0)},children:[(0,Q.jsx)(b,{icon:Di,className:`size-3.5`}),`Upload`]})}),(0,Q.jsx)(J,{label:I().length>0?`Delete ${I().length} object${I().length===1?``:`s`}`:`Select objects to delete`,children:(0,Q.jsxs)(G,{type:`button`,variant:`destructive`,size:I().length>0?`xs`:`icon-xs`,disabled:I().length===0,onClick:()=>w(I()),"aria-label":`Delete selected`,"data-slot":`file-delete`,children:[(0,Q.jsx)(b,{icon:pn,className:`size-3.5`}),I().length>0?I().length:null]})}),(0,Q.jsx)(J,{label:`Reload from the store`,children:(0,Q.jsx)(G,{type:`button`,variant:`ghost`,size:`icon-xs`,disabled:i,"aria-label":`Refresh`,"data-slot":`browse-refresh`,onClick:a,children:(0,Q.jsx)(b,{icon:mt,className:i?`size-3.5 animate-spin`:`size-3.5`})})})]}),(0,Q.jsxs)(`div`,{className:S(`flex min-h-0 flex-1 flex-col`,T&&`bg-sky-500/5`),onDragOver:e=>{e.preventDefault(),E(!0)},onDragLeave:()=>E(!1),onDrop:e=>{e.preventDefault(),E(!1);let t=[...e.dataTransfer.files];t.length!==0&&(y(t),_(!0))},"data-slot":`file-drop`,children:[A.length===0?(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center px-6`,children:(0,Q.jsx)(Be,{role:`status`,"data-slot":`files-empty`,children:(0,Q.jsxs)(Ie,{children:[(0,Q.jsx)(Le,{variant:`icon`,children:(0,Q.jsx)(b,{icon:yr})}),(0,Q.jsx)(We,{children:O?`No matching objects`:`This folder is empty`}),(0,Q.jsx)(qe,{children:O?`Try another name or clear the filter.`:`Drop files here or upload into this prefix.`})]})})}):u===`grid`?(0,Q.jsx)(Lc,{entries:A,selectedKey:f,checked:m,onOpen:F,onToggle:P}):(0,Q.jsx)(Ic,{entries:A,selectedKey:f,checked:m,searching:O,onOpen:F,onToggle:P}),(0,Q.jsxs)(`footer`,{className:`flex h-8 shrink-0 items-center justify-between border-t border-border/60 px-3 text-[11px] text-muted-foreground`,children:[(0,Q.jsxs)(`span`,{className:`font-mono tabular-nums`,children:[k.folders.length,` folder`,k.folders.length===1?``:`s`,(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`mx-1 text-border`,children:`·`}),k.files.length,` object`,k.files.length===1?``:`s`,i?` · refreshing`:``]}),(0,Q.jsx)(`span`,{children:`Drop to upload · click a folder to open · click a file to inspect`})]})]}),(0,Q.jsx)(kc,{open:f!==null,onOpenChange:e=>{e||p(null)},storeRef:e.ref,tenant:n,objectKey:f,sizeBytes:M?.sizeBytes,originalName:M?.name,warnings:M?.warnings,onDelete:f?()=>{w([f])}:void 0}),(0,Q.jsx)(Pc,{open:g,onOpenChange:_,storeRef:e.ref,tenant:n,prefix:o,existingKeys:D.map(e=>e.key),pendingFiles:v}),(0,Q.jsx)(Fs,{open:C!==null,onOpenChange:e=>{e||w(null)},phrase:`DELETE`,title:`Delete ${C?.length??0} ${C?.length===1?`object`:`objects`}`,description:`Permanently delete ${C?.length??0} object(s) from ${e.ref}. This is not a flow execution.`,pending:N.isPending,error:N.isError?N.error.message:null,onConfirm:t=>{C&&N.mutate({ref:e.ref,...n?{tenant:n}:{},keys:C,confirmation:t.confirmation,reason:t.reason},{onSuccess:()=>{w(null),h(new Set),p(null),a()}})}})]})}function Ic({entries:e,selectedKey:t,checked:n,searching:r,onOpen:i,onToggle:a}){return(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto`,role:`list`,"aria-label":`Objects`,children:[(0,Q.jsxs)(`div`,{className:`sticky top-0 z-10 flex h-7 items-center gap-2 border-b border-border/60 bg-background px-3 text-[10px] font-semibold tracking-[0.08em] text-muted-foreground uppercase`,children:[(0,Q.jsx)(`span`,{className:`w-5`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1`,children:`Name`}),(0,Q.jsx)(`span`,{className:`w-20 text-right`,children:`Kind`}),(0,Q.jsx)(`span`,{className:`w-16 text-right`,children:`Size`})]}),e.map(e=>{let o=e.kind===`folder`?e.prefix:e.key,s=e.kind===`file`&&e.key===t;return(0,Q.jsxs)(`div`,{role:`listitem`,"data-slot":e.kind===`folder`?`file-folder`:`file-object`,className:S(`flex h-8 cursor-default items-center gap-2 border-b border-border/60 px-3 text-xs`,s&&`bg-muted/70`,!s&&`hover:bg-muted/50`),onClick:()=>i(e),onDoubleClick:()=>i(e),children:[(0,Q.jsx)(`span`,{onClick:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),children:(0,Q.jsx)(Rs,{checked:n.has(o),onCheckedChange:e=>a(o,e),"aria-label":`Select ${e.name}`})}),(0,Q.jsx)(yc,{kind:e.kind===`folder`?`folder`:ac(e.name),well:!1}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[(0,Q.jsx)(`span`,{className:`text-foreground`,children:e.name}),r&&e.kind===`file`?(0,Q.jsx)(`span`,{className:`ml-2 font-mono text-[10px] text-muted-foreground`,children:e.key}):null,e.warnings.length>0?(0,Q.jsx)(b,{icon:nt,className:`ml-1 inline size-3 text-amber-600 dark:text-amber-400`}):null]}),(0,Q.jsx)(`span`,{className:`w-20 text-right text-[11px] text-muted-foreground`,children:e.kind===`folder`?`Folder`:oc(ac(e.name))}),(0,Q.jsx)(`span`,{className:`w-16 text-right font-mono text-[11px] tabular-nums text-muted-foreground`,children:Mt(e.sizeBytes)})]},o)})]})}function Lc({entries:e,selectedKey:t,checked:n,onOpen:r,onToggle:i}){return(0,Q.jsx)(`div`,{className:`grid min-h-0 flex-1 auto-rows-min grid-cols-[repeat(auto-fill,minmax(7.5rem,1fr))] content-start gap-2 overflow-auto p-3`,role:`list`,"aria-label":`Objects`,children:e.map(e=>{let a=e.kind===`folder`?e.prefix:e.key,o=e.kind===`file`&&e.key===t;return(0,Q.jsxs)(`button`,{type:`button`,role:`listitem`,"data-slot":e.kind===`folder`?`file-folder`:`file-object`,className:S(`relative flex flex-col items-center gap-2 rounded-lg border px-2 py-3 text-center`,o?`border-sky-500/40 bg-sky-500/10`:`border-border/50 hover:border-border hover:bg-muted/40`),onClick:()=>r(e),onDoubleClick:()=>r(e),children:[(0,Q.jsx)(`span`,{className:`absolute top-1.5 left-1.5`,onClick:e=>e.stopPropagation(),children:(0,Q.jsx)(Rs,{checked:n.has(a),onCheckedChange:e=>i(a,e),"aria-label":`Select ${e.name}`})}),(0,Q.jsx)(yc,{kind:e.kind===`folder`?`folder`:ac(e.name),className:`size-10 rounded-lg [&_svg]:size-5`}),(0,Q.jsx)(`span`,{className:`line-clamp-2 w-full text-[11px] leading-4 text-foreground`,children:e.name}),(0,Q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.kind===`folder`?`${e.objectCount} objects`:Mt(e.sizeBytes)})]},a)})})}function Rc(e,t,n){let r=Array(e);return new Proxy(r,{get(r,i,a){if(typeof i==`string`){let a=i.charCodeAt(0);if(a>=48&&a<=57){let a=+i;if(Number.isInteger(a)&&a>=0&&a<e){let e=r[a];if(!e){let i=t[a*2];e=r[a]={index:a,key:n(a),start:i,size:t[a*2+1],end:i+t[a*2+1],lane:0}}return e}}if(i===`length`)return e}return Reflect.get(r,i,a)}})}function zc(e,t,n){let r=n.initialDeps??[],i,a=!0;function o(){let o=e();return o.length!==r.length||o.some((e,t)=>r[t]!==e)?(r=o,i=t(...o),n?.onChange&&!(a&&n.skipInitialOnChange)&&n.onChange(i),a=!1,i):i}return o.updateDeps=e=>{r=e},o}function Bc(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}var Vc=(e,t)=>Math.abs(e-t)<1.01,Hc=(e,t,n)=>{let r;return Object.assign(function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)},{cancel:()=>{e.clearTimeout(r)}})},Uc,Wc=()=>{if(Uc!==void 0)return Uc;if(typeof navigator>`u`)return Uc=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return Uc=!0;let e=navigator.maxTouchPoints;return Uc=navigator.platform===`MacIntel`&&e!==void 0&&e>0},Gc=e=>{let{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},Kc=e=>e,qc=e=>{let t=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1)-t+1,r=Array(n);for(let e=0;e<n;e++)r[e]=t+e;return r},Jc=(e,t)=>{let n=e.scrollElement;if(!n)return;let r=e.targetWindow;if(!r)return;let i=e=>{let{width:n,height:r}=e;t({width:Math.round(n),height:Math.round(r)})};if(i(Gc(n)),!r.ResizeObserver)return()=>{};let a=new r.ResizeObserver(t=>{let r=()=>{let e=t[0];if(e?.borderBoxSize){let t=e.borderBoxSize[0];if(t){i({width:t.inlineSize,height:t.blockSize});return}}i(Gc(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(r):r()});return a.observe(n,{box:`border-box`}),()=>{a.unobserve(n)}},Yc={passive:!0},Xc=typeof window>`u`||`onscrollend`in window,Zc=(e,t,n)=>{let r=e.scrollElement;if(!r)return;let i=e.targetWindow;if(!i)return;let a=e.options.useScrollendEvent&&Xc,o=0,s=a?null:Hc(i,()=>t(o,!1),e.options.isScrollingResetDelay),c=e=>()=>{o=n(r),s?.(),t(o,e)},l=c(!0),u=c(!1);return r.addEventListener(`scroll`,l,Yc),a&&r.addEventListener(`scrollend`,u,Yc),()=>{r.removeEventListener(`scroll`,l),a&&r.removeEventListener(`scrollend`,u),s?.cancel()}},Qc=(e,t)=>Zc(e,t,t=>{let{horizontal:n,isRtl:r}=e.options;return n?t.scrollLeft*(r&&-1||1):t.scrollTop}),$c=(e,t,n)=>{if(n.options.useCachedMeasurements){let t=n.indexFromElement(e),r=n.options.getItemKey(t);return n.itemSizeCache.get(r)??n.options.estimateSize(t)}if(t?.borderBoxSize){let e=t.borderBoxSize[0];if(e)return Math.round(e[n.options.horizontal?`inlineSize`:`blockSize`])}if(!t){let t=n.indexFromElement(e),r=n.options.getItemKey(t),i=n.itemSizeCache.get(r);if(i!==void 0)return i}return e[n.options.horizontal?`offsetWidth`:`offsetHeight`]},el=(e,{adjustments:t=0,behavior:n},r)=>{var i,a;(a=(i=r.scrollElement)?.scrollTo)==null||a.call(i,{[r.options.horizontal?`left`:`top`]:e+t,behavior:n})},tl=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._flatMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this._clampedAdjustment=null,this.elementsCache=new Map,this.now=()=>{var e;return((e=this.targetWindow?.performance)?.now)?.call(e)??Date.now()},this.observer=(()=>{let e=null,t=()=>e||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:e=new this.targetWindow.ResizeObserver(e=>{e.forEach(e=>{let t=()=>{let t=e.target,n=this.indexFromElement(t);if(!t.isConnected){this.observer.unobserve(t);for(let[e,n]of this.elementsCache)if(n===t){this.elementsCache.delete(e);break}return}this.isIndexInRange(n)&&this.shouldMeasureDuringScroll(n)&&this.resizeItem(n,this.options.measureElement(t,e,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(t):t()})}));return{disconnect:()=>{var n;(n=t())==null||n.disconnect(),e=null},observe:e=>t()?.observe(e,{box:`border-box`}),unobserve:e=>t()?.unobserve(e)}})(),this.range=null,this.setOptions=e=>{let t={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Kc,rangeExtractor:qc,onChange:()=>{},measureElement:$c,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:`data-index`,initialMeasurementsCache:[],lanes:1,anchorTo:`start`,followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:`estimate`,useCachedMeasurements:!1};for(let n in e){let r=e[n];r!==void 0&&(t[n]=r)}let n=this.options,r=null,i=null,a=!1;if(n!==void 0&&n.enabled&&t.enabled&&t.anchorTo===`end`&&this.scrollElement!==null){let e=n.count,o=t.count,s=this.getMeasurements(),c=e>0?s[0]?.key??n.getItemKey(0):null,l=e>0?s[e-1]?.key??n.getItemKey(e-1):null;if(o!==e||e>0&&o>0&&(t.getItemKey(0)!==c||t.getItemKey(o-1)!==l)){a=!0;let c=e>0?this.getVirtualItemForOffset(this.getScrollOffset())??s[0]:null;c&&(r=[c.key,this.getScrollOffset()-c.start]);let u=t.followOnAppend===!0?`auto`:t.followOnAppend||null;u&&o>e&&this.isAtEnd(n.scrollEndThreshold)&&(e===0||t.getItemKey(o-1)!==l)&&(i=u)}}this.options=t,a&&(this.pendingMin=0,this.itemSizeCacheVersion++);let o=!1,s=0;if(r&&this.scrollOffset!==null){let[e,t]=r,n=this.getMeasurements(),{count:i,getItemKey:a}=this.options,c=0;for(;c<i&&a(c)!==e;)c++;if(c<i){let e=n[c];if(e){let n=Math.max(0,e.start+t);n!==this.scrollOffset&&(s=n-this.scrollOffset,this.scrollOffset=n,o=!0)}}}(o||i)&&(this.pendingScrollAnchor=[o?r[0]:null,o?r[1]:0,i,s])},this.notify=e=>{var t,n;(n=(t=this.options).onChange)==null||n.call(t,this,e)},this.maybeNotify=zc(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),e=>{this.notify(e)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(e=>e()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.isScrolling=!1,this.scrollDirection=null,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._clampedAdjustment=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{let e=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==e){if(this.cleanup(),!e){this.maybeNotify();return}if(this.scrollElement=e,this.targetWindow=this.scrollElement&&`ownerDocument`in this.scrollElement?this.scrollElement.ownerDocument.defaultView:this.scrollElement?.window??null,this.elementsCache.forEach(e=>{this.observer.observe(e)}),this.unsubs.push(this.options.observeElementRect(this,e=>{this.scrollRect=e,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(e,t)=>{if(t&&this._intendedScrollOffset===null&&e===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(e-this._intendedScrollOffset)<1.5&&(e=this._intendedScrollOffset),this._intendedScrollOffset=null,this._clampedAdjustment!==null&&Math.abs(e-this._clampedAdjustment.maxAtWrite)>=1.5&&(this._clampedAdjustment=null),this.scrollAdjustments=0;let n=this.getScrollOffset();this.scrollDirection=t?n===e?this.scrollDirection:n<e?`forward`:`backward`:null,this.scrollOffset=e,this.isScrolling=t,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),`addEventListener`in this.scrollElement){let e=this.scrollElement,t=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},n=()=>{this._iosTouching=!1,Wc()&&this.targetWindow!=null&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};e.addEventListener(`touchstart`,t,Yc),e.addEventListener(`touchend`,n,Yc),this.unsubs.push(()=>{e.removeEventListener(`touchstart`,t),e.removeEventListener(`touchend`,n),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}let t=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,t&&this.scrollElement&&this.options.enabled){let[e,n,r,i]=t;e!==null&&!r&&(Wc()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?i!==0&&(this._iosDeferredAdjustment+=i):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),r&&this.scrollToEnd({behavior:r})}this._retryClampedAdjustment()},this._retryClampedAdjustment=()=>{if(this._clampedAdjustment===null||!this.scrollElement||!this.options.enabled)return;let{target:e,maxAtWrite:t}=this._clampedAdjustment,n=this.getMaxScrollOffset();n>t+.5&&(this._clampedAdjustment=e>n+.5?{target:e,maxAtWrite:n}:null,this._scrollToOffset(e,{adjustments:void 0,behavior:void 0}))},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;let e=this.getScrollOffset(),t=this.getMaxScrollOffset();if(e<0||e>t)return;if(this._iosDeferredAdjustment<0&&e>=t-1){this._iosDeferredAdjustment=0;return}let n=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(e,{adjustments:this.scrollAdjustments+=n,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?`width`:`height`]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset==`function`?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=zc(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(e,t,n,r,i,a,o,s)=>(this.prevLanes!==void 0&&this.prevLanes!==a&&(this.lanesChangedFlag=!0),this.prevLanes=a,this.pendingMin=null,{count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o,gap:s}),{key:!1}),this.isIndexInRange=e=>e>=0&&e<this.options.count,this.getMeasurements=zc(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o,gap:s},c)=>{let l=this.itemSizeCache;if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>e)for(let t of this.laneAssignments.keys())t>=e&&this.laneAssignments.delete(t);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(e=>{this.itemSizeCache.set(e.key,e.size)}));let u=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===e&&(this.lanesSettling=!1),a===1){let i=e*2,a=this._flatMeasurements;if(!a||a.length<i){let e=new Float64Array(i);a&&u>0&&e.set(a.subarray(0,u*2)),a=e,this._flatMeasurements=a}let o;if(u===0)o=t+n;else{let e=u-1;o=a[e*2]+a[e*2+1]+s}for(let t=u;t<e;t++){let e=r(t),n=l.get(e),i=typeof n==`number`?n:this.options.estimateSize(t);a[t*2]=o,a[t*2+1]=i,o+=i+s}let c=Rc(e,a,r);return this.measurementsCache=c,c}let d=this.measurementsCache.slice(0,u),f=Array(a).fill(void 0),p=new Float64Array(a),m=0;for(let e=0;e<u;e++){let t=d[e];t&&(f[t.lane]===void 0&&m++,f[t.lane]=e,p[t.lane]=t.end)}for(let i=u;i<e;i++){let e=r(i),c=this.laneAssignments.get(i),u,h,g=o===`estimate`||l.has(e);if(c!==void 0&&this.options.lanes>1){u=c;let e=f[u],r=e===void 0?void 0:d[e];h=r?r.end+s:t+n}else if(m===a){let e=0,t=p[0],n=f[0];for(let r=1;r<a;r++){let i=p[r];(i<t||i===t&&f[r]<n)&&(e=r,t=i,n=f[r])}u=e,h=t+s,g&&this.laneAssignments.set(i,u)}else u=i%this.options.lanes,h=t+n,g&&this.laneAssignments.set(i,u);let _=l.get(e),v=typeof _==`number`?_:this.options.estimateSize(i),y=h+v;d[i]={index:i,start:h,size:v,end:y,key:e,lane:u},f[u]===void 0&&m++,f[u]=i,p[u]=y}return this.measurementsCache=d,d},{key:!1,debug:()=>this.options.debug}),this.calculateRange=zc(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,r)=>e.length===0||t===0?(this.range=null,null):(this.range=il(e,t,n,r,r===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=zc(()=>{let e=null,t=null,n=this.calculateRange();return n&&(e=n.startIndex,t=n.endIndex),this.maybeNotify.updateDeps([this.isScrolling,e,t]),[this.options.rangeExtractor,this.options.overscan,this.options.count,e,t]},(e,t,n,r,i)=>r===null||i===null?[]:e({startIndex:r,endIndex:i,overscan:t,count:n}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=e=>{let t=this.options.indexAttribute,n=e.getAttribute(t);return n?parseInt(n,10):(console.warn(`Missing attribute name '${t}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=e=>{if(!this.scrollState||this.scrollState.behavior!==`smooth`)return!0;let t=this.scrollState.index??this.getVirtualItemForOffset(this.scrollState.lastTargetOffset)?.index;if(t!==void 0&&this.range){let n=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),r=Math.max(0,t-n),i=Math.min(this.options.count-1,t+n);return e>=r&&e<=i}return!0},this.measureElement=e=>{if(!e){this.elementsCache.forEach((e,t)=>{e.isConnected||(this.observer.unobserve(e),this.elementsCache.delete(t))});return}let t=this.indexFromElement(e);if(!this.isIndexInRange(t))return;let n=this.options.getItemKey(t),r=this.elementsCache.get(n);r!==e&&(r&&this.observer.unobserve(r),this.observer.observe(e),this.elementsCache.set(n,e)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(t)&&this.resizeItem(t,this.options.measureElement(e,void 0,this))},this.resizeItem=(e,t)=>{if(!this.isIndexInRange(e))return;let n,r,i,a=this._flatMeasurements;if(this.options.lanes===1&&a!==null)i=this.options.getItemKey(e),r=a[e*2],n=a[e*2+1];else{let t=this.measurementsCache[e];if(!t)return;i=t.key,r=t.start,n=t.size}let o=this.itemSizeCache.get(i)??n,s=t-o;if(s!==0){let a=this.options.anchorTo===`end`&&this.scrollState?.behavior!==`smooth`&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,c=a?this.getTotalSize():0,l=this.getScrollOffset()+this.scrollAdjustments,u=this.itemSizeCache.has(i)?r+o<=l&&this.scrollDirection!==`backward`:r<l,d=this.scrollState?.behavior!==`smooth`&&(this.shouldAdjustScrollPositionOnItemSizeChange===void 0?u:this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[e]??{index:e,key:i,start:r,size:n,end:r+n,lane:0},s,this));(this.pendingMin===null||e<this.pendingMin)&&(this.pendingMin=e),this.itemSizeCache.set(i,t),this.itemSizeCacheVersion++;let f=!1;a?f=this.applyScrollAdjustment(this.getTotalSize()-c):d&&(f=this.applyScrollAdjustment(s)),this.notify(f),this._retryClampedAdjustment()}},this.getVirtualItems=zc(()=>[this.getVirtualIndexes(),this.getMeasurements()],(e,t)=>{let n=[];for(let r=0,i=e.length;r<i;r++){let i=t[e[r]];n.push(i)}return n},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=e=>{let t=this.getMeasurements();if(t.length===0)return;let n=this._flatMeasurements,r=this.options.lanes===1&&n!=null;return Bc(t[nl(0,t.length-1,r?e=>n[e*2]:e=>Bc(t[e]).start,e)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if(`scrollHeight`in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{let e=this.scrollElement.document.documentElement;return this.options.horizontal?e.scrollWidth-this.scrollElement.innerWidth:e.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(e=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=e,this.getOffsetForAlignment=(e,t,n=0)=>{if(!this.scrollElement)return 0;let r=this.getSize(),i=this.getScrollOffset();t===`auto`&&(t=e>=i+r?`end`:`start`),t===`center`?e+=(n-r)/2:t===`end`&&(e-=r);let a=this.getMaxScrollOffset();return Math.max(Math.min(a,e),0)},this.getOffsetForIndex=(e,t=`auto`)=>{e=Math.max(0,Math.min(e,this.options.count-1));let n=this.getSize(),r=this.getScrollOffset(),i=this.measurementsCache[e];if(!i)return;if(t===`auto`){if(i.end>=r+n-this.options.scrollPaddingEnd)t=`end`;else if(i.start<=r+this.options.scrollPaddingStart)t=`start`;else return[r,t]}if(t===`end`&&e===this.options.count-1)return[this.getMaxScrollOffset(),t];let a=t===`end`?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,t,i.size),t]},this.scrollToOffset=(e,{align:t=`start`,behavior:n=`auto`}={})=>{this._iosDeferredAdjustment=0;let r=this.getOffsetForAlignment(e,t),i=this.now();this.scrollState={index:null,align:t,behavior:n,startedAt:i,lastTargetOffset:r,stableFrames:0},this._scrollToOffset(r,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollToIndex=(e,{align:t=`auto`,behavior:n=`auto`}={})=>{this._iosDeferredAdjustment=0,e=Math.max(0,Math.min(e,this.options.count-1));let r=this.getOffsetForIndex(e,t);if(!r)return;let[i,a]=r,o=this.now();this.scrollState={index:e,align:a,behavior:n,startedAt:o,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollBy=(e,{behavior:t=`auto`}={})=>{let n=this.getScrollOffset()+e,r=this.now();this.scrollState={index:null,align:`start`,behavior:t,startedAt:r,lastTargetOffset:n,stableFrames:0},this._scrollToOffset(n,{adjustments:void 0,behavior:t}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:e=`auto`}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:`end`,behavior:e});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:e})},this.getTotalSize=()=>{let e=this.getMeasurements(),t;if(e.length===0)t=this.options.paddingStart;else if(this.options.lanes===1){let n=e.length-1,r=this._flatMeasurements;t=r==null?e[n]?.end??0:r[n*2]+r[n*2+1]}else{let n=Array(this.options.lanes).fill(null),r=e.length-1;for(;r>=0&&n.some(e=>e===null);){let t=e[r];n[t.lane]===null&&(n[t.lane]=t.end),r--}t=Math.max(...n.filter(e=>e!==null))}return Math.max(t-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{let e=[];if(this.itemSizeCache.size===0)return e;let t=this.getMeasurements();for(let n of t)n&&this.itemSizeCache.has(n.key)&&e.push({index:n.index,key:n.key,start:n.start,size:n.size,end:n.end,lane:n.lane});return e},this._scrollToOffset=(e,{adjustments:t,behavior:n})=>{this._intendedScrollOffset=e+(t??0),this.options.scrollToFn(e,{behavior:n,adjustments:t},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(e)}applyScrollAdjustment(e,t){if(e===0)return!1;if(Wc()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded))return this._iosDeferredAdjustment+=e,!1;{let n=this.getScrollOffset()+this.scrollAdjustments+e,r=this.scrollElement,i=r!==null&&(`scrollHeight`in r||`document`in r)?this.getMaxScrollOffset():null;return this._clampedAdjustment=i!==null&&n>i+.5?{target:n,maxAtWrite:i}:null,this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=e,behavior:t}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollOffset<0&&(this.scrollOffset=0),this.scrollAdjustments=0),!0}}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId??=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()})}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}let e=this.scrollState.index==null?void 0:this.getOffsetForIndex(this.scrollState.index,this.scrollState.align),t=e?e[0]:this.scrollState.lastTargetOffset,n=t!==this.scrollState.lastTargetOffset;if(!n&&Vc(t,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=1){this.getScrollOffset()!==t&&this._scrollToOffset(t,{adjustments:void 0,behavior:`auto`}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,n){let e=this.getSize()||600,n=Math.abs(t-this.getScrollOffset()),r=this.scrollState.behavior===`smooth`&&n>e;this.scrollState.lastTargetOffset=t,r||(this.scrollState.behavior=`auto`),this._scrollToOffset(t,{adjustments:void 0,behavior:r?`smooth`:`auto`})}this.scheduleScrollReconcile()}},nl=(e,t,n,r)=>{for(;e<=t;){let i=(e+t)/2|0,a=n(i);if(a<r)e=i+1;else if(a>r)t=i-1;else return i}return e>0?e-1:0};function rl(e,t,n){let r=0;for(;r<=t;){let i=(r+t)/2|0,a=e[i*2];if(a<n)r=i+1;else if(a>n)t=i-1;else return i}return r>0?r-1:0}function il(e,t,n,r,i){let a=e.length-1;if(e.length<=r)return{startIndex:0,endIndex:a};if(r===1&&i!==null){let e=rl(i,a,n),r=e,o=n+t;for(;r<a&&i[r*2]+i[r*2+1]<o;)r++;return{startIndex:e,endIndex:r}}let o=nl(0,a,t=>e[t].start,n),s=o;if(r===1)for(;s<a&&e[s].end<n+t;)s++;else if(r>1){let i=Array(r).fill(0);for(;s<a&&i.some(e=>e<n+t);){let t=e[s];i[t.lane]=t.end,s++}let c=Array(r).fill(n+t);for(;o>=0&&c.some(e=>e>=n);){let t=e[o];c[t.lane]=t.start,o--}o=Math.max(0,o-o%r),s=Math.min(a,s+(r-1-s%r))}return{startIndex:o,endIndex:s}}var al=typeof document<`u`?Z.useLayoutEffect:Z.useEffect;function ol({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:n=`transform`,...r}){let i=Z.useReducer(e=>e+1,0)[1],a=Z.useRef({enabled:t,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});a.current.enabled=t,a.current.mode=n;let o=e=>{let t=a.current;if(!t.enabled||!t.container)return;let n=e.getTotalSize();if(n!==t.lastSize){t.lastSize=n;let r=e.options.horizontal?`width`:`height`;t.container.style[r]=`${n}px`}},s=e=>{let t=a.current;if(!t.enabled||!t.container)return;o(e);let n=!!e.options.horizontal,r=t.mode===`transform`,i=n?`left`:`top`,s=e.options.scrollMargin,c=e.getVirtualItems();for(let a of c){let o=a.start-s,c=e.elementsCache.get(a.key);c&&t.lastPositions.get(c)!==o&&(t.lastPositions.set(c,o),r?c.style.transform=n?`translate3d(${o}px, 0, 0)`:`translate3d(0, ${o}px, 0)`:c.style[i]=`${o}px`)}},c={...r,onChange:(t,n)=>{var o;let c=a.current,l=!0;if(c.enabled){s(t);let e=t.range,n=c.prevRange;l=!n||n.isScrolling!==t.isScrolling||n.startIndex!==e?.startIndex||n.endIndex!==e?.endIndex,l&&(c.prevRange=e?{startIndex:e.startIndex,endIndex:e.endIndex,isScrolling:t.isScrolling}:null)}l&&(e&&n?(0,Qi.flushSync)(i):i()),(o=r.onChange)==null||o.call(r,t,n)}},[l]=Z.useState(()=>{let e=new tl(c);return Object.assign(e,{containerRef:t=>{let n=a.current;if(n.container=t,n.lastSize=null,t&&n.enabled){let r=e.getTotalSize();n.lastSize=r;let i=e.options.horizontal?`width`:`height`;t.style[i]=`${r}px`}}})});return l.setOptions(c),al(()=>l._didMount(),[]),al(()=>(o(l),l._willUpdate())),al(()=>{s(l)}),l}function sl(e){return ol({observeElementRect:Jc,observeElementOffset:Qc,scrollToFn:el,...e})}var cl=188;function ll({items:e,ariaLabel:t,trigger:n,triggerClassName:r}){let i=ti(),a=(0,Z.useRef)(null),[o,s]=(0,Z.useState)(null),c=o!==null;(0,Z.useEffect)(()=>{if(!c)return;let e=()=>s(null),t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,e),window.removeEventListener(`keydown`,t)}},[c]);let l=()=>{if(c){s(null);return}let e=a.current;if(!e)return;let t=e.getBoundingClientRect();s({top:t.bottom+4,left:Math.max(8,t.right-cl)})};return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{ref:a,type:`button`,"aria-label":t,"aria-haspopup":`menu`,"aria-expanded":c,onClick:e=>{e.stopPropagation(),l()},className:r,children:n}),c&&o&&typeof document<`u`?(0,Qi.createPortal)((0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`fixed inset-0 z-40`,onPointerDown:()=>s(null)}),(0,Q.jsx)(Xr.div,{role:`menu`,className:`fixed z-50 overflow-hidden rounded-xl border border-border bg-background p-1 shadow-xl`,style:{top:o.top,left:o.left,width:cl},initial:i?{opacity:0}:{opacity:0,scale:.96,y:-4},animate:i?{opacity:1}:{opacity:1,scale:1,y:0},transition:i?{duration:0}:Hr,children:e.map(e=>(0,Q.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{s(null),e.onSelect()},className:S(`flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-left text-sm transition-colors [&_svg]:size-4`,e.destructive?`text-rose-500 hover:bg-rose-500/10`:`text-foreground hover:bg-muted`),children:[e.icon,e.label]},e.label))})]}),document.body):null]})}function ul({rowEl:e,id:t,index:n,onInsertRow:r,onDeleteRow:i,onEnter:a,onLeave:o}){if((0,Z.useEffect)(()=>(window.addEventListener(`scroll`,o,!0),()=>window.removeEventListener(`scroll`,o,!0)),[o]),!e||typeof document>`u`)return null;let s=e.getBoundingClientRect();return(0,Qi.createPortal)((0,Q.jsx)(`div`,{style:{position:`fixed`,top:s.top+s.height/2,left:s.left,transform:`translate(-50%, -50%)`,zIndex:40},onPointerEnter:a,onPointerLeave:o,children:(0,Q.jsx)(ll,{ariaLabel:`Row ${n+1} options`,triggerClassName:`flex h-6 w-2 items-center justify-center rounded-full bg-primary text-primary-foreground shadow-sm transition-colors hover:bg-primary/90`,trigger:(0,Q.jsx)(b,{icon:Pi,className:`size-3`}),items:[...r?[{label:`Insert before`,icon:(0,Q.jsx)(b,{icon:zt}),onSelect:()=>r(n,`before`)},{label:`Insert after`,icon:(0,Q.jsx)(b,{icon:et}),onSelect:()=>r(n,`after`)}]:[],...i?[{label:`Delete row`,icon:(0,Q.jsx)(b,{icon:pn}),destructive:!0,onSelect:()=>i(t,n)}]:[]]})}),document.body)}var dl=`48px`,fl=S(`[&_button]:size-3.5 [&_button]:rounded-[3px] [&_button]:border! [&_button]:border-border! [&_button]:bg-transparent!`,`[&_button]:ring-offset-0 [&_button]:hover:border-foreground/50!`,`[&_button[data-state=checked]]:border-sky-500! [&_button[data-state=checked]]:bg-sky-500! [&_button[data-state=checked]]:text-white!`,`[&_button[data-state=indeterminate]]:border-sky-500! [&_button[data-state=indeterminate]]:bg-sky-500! [&_button[data-state=indeterminate]]:text-white!`),pl=`inset 0 1px 0 var(--color-sky-500)`;function ml(e){return S(`relative after:pointer-events-none after:absolute after:inset-x-0 after:bottom-0 after:z-[1] after:h-px`,e?`after:bg-sky-500/25`:`after:bg-border/60`)}function hl(e){return e===`right`?`justify-end`:e===`center`?`justify-center`:`justify-start`}function gl(e){return e===`right`?`text-right`:e===`center`?`text-center`:`text-left`}function _l(e,t){return t.cell?t.cell(e):e[t.key]}function vl(e,t){if(t.sortValue)return t.sortValue(e);let n=e[t.key];if(typeof n==`number`)return n;if(n==null)return``;if(typeof n==`string`)return n;if(typeof n==`boolean`)return+!!n;try{return JSON.stringify(n)}catch{return``}}function yl(e,t){let n=e[t];if(n==null)return``;if(typeof n==`string`)return n;if(typeof n==`number`||typeof n==`boolean`)return String(n);try{return JSON.stringify(n)}catch{return``}}function bl(e,t,n){return e?{inRange:on(e,t,n),isHead:e.head.row===t&&e.head.col===n}:{inRange:!1,isHead:!1}}function xl({count:e,columns:t,selectable:n,rowHeight:r,slack:i=!0}){return(0,Q.jsx)(Q.Fragment,{children:Array.from({length:e},(e,a)=>(0,Q.jsxs)(`tr`,{style:{height:r},children:[n?(0,Q.jsx)(`td`,{className:`px-4`}):null,t.map(e=>(0,Q.jsx)(`td`,{className:S(`px-4`,gl(e.align)),children:(0,Q.jsx)(`div`,{className:S(`h-3 animate-pulse rounded-full bg-muted`,e.align===`right`?`ml-auto w-10`:`w-2/3`)})},e.key)),i?(0,Q.jsx)(`td`,{"aria-hidden":!0}):null]},a))})}function Sl(e,t,n,r){return[...n?[{label:`Insert before`,icon:(0,Q.jsx)(b,{icon:at}),onSelect:()=>n(t,`before`)},{label:`Insert after`,icon:(0,Q.jsx)(b,{icon:ut}),onSelect:()=>n(t,`after`)}]:[],...r?[{label:`Delete column`,icon:(0,Q.jsx)(b,{icon:pn}),destructive:!0,onSelect:()=>r(e.key,t)}]:[]]}function Cl({column:e,index:t,thRefs:n,onInsertColumn:r,onDeleteColumn:i,onEnter:a,onLeave:o}){(0,Z.useEffect)(()=>(window.addEventListener(`scroll`,o,!0),()=>window.removeEventListener(`scroll`,o,!0)),[o]);let s=n.current[e.key];if(!s||typeof document>`u`)return null;let c=s.getBoundingClientRect();return(0,Qi.createPortal)((0,Q.jsx)(`div`,{style:{position:`fixed`,top:c.top,left:c.left+c.width/2,transform:`translate(-50%, -50%)`,zIndex:40},onPointerEnter:a,onPointerLeave:o,children:(0,Q.jsx)(ll,{ariaLabel:`${e.key} column options`,triggerClassName:`flex h-2 w-6 items-center justify-center rounded-full bg-primary text-primary-foreground shadow-sm transition-colors hover:bg-primary/90`,trigger:(0,Q.jsx)(b,{icon:Tr,className:`size-3`}),items:Sl(e,t,r,i)})}),document.body)}function wl({columns:e,rowHeight:t,reduce:n,thRefs:r,selectable:i,allSelected:a,someSelected:o,onToggleAll:s,sort:c,onToggleSort:l,resizable:u,onResizeStart:d,onResizeMove:f,onResizeEnd:p,reorderable:m,dragKey:h,dropIndex:g,onReorderStart:_,onReorderMove:v,onReorderEnd:y,onInsertColumn:x,onDeleteColumn:C,onColumnRename:w,activeColumn:T,onColumnActivate:E,onColumnDeactivate:D,slack:O=!0}){let k=!!(x||C),A=e.findIndex(e=>e.key===T),j=A>=0?e[A]:void 0;return(0,Q.jsxs)(Q.Fragment,{children:[k&&T&&j?(0,Q.jsx)(Cl,{column:j,index:A,thRefs:r,onInsertColumn:x,onDeleteColumn:C,onEnter:()=>E?.(T),onLeave:()=>D?.()}):null,(0,Q.jsx)(`thead`,{children:(0,Q.jsxs)(`tr`,{children:[i?(0,Q.jsx)(`th`,{className:`sticky top-0 z-10 border-b border-border/60 bg-background p-0 font-medium`,children:(0,Q.jsx)(`div`,{className:`flex items-center justify-center`,style:{height:t},children:(0,Q.jsx)(Rs,{checked:a,indeterminate:o&&!a,onCheckedChange:()=>s(),"aria-label":`Select all rows`,className:fl})})}):null,e.map((i,a)=>{let o=c?.key===i.key,s=h===i.key,x=T===i.key;return(0,Q.jsxs)(`th`,{ref:e=>{r.current[i.key]=e},onPointerEnter:()=>E?.(i.key),onPointerLeave:()=>D?.(),style:x?{boxShadow:pl}:void 0,"aria-sort":o?c?.direction===`asc`?`ascending`:`descending`:void 0,"data-drop":h?g===a:void 0,"data-dropend":h?g===e.length&&a===e.length-1:void 0,className:S(`group relative sticky top-0 z-10 border-b border-border/60 bg-background p-0 font-medium text-muted-foreground`,`data-[drop=true]:before:absolute data-[drop=true]:before:inset-y-0 data-[drop=true]:before:left-0 data-[drop=true]:before:w-0.5 data-[drop=true]:before:bg-primary`,`data-[dropend=true]:after:absolute data-[dropend=true]:after:inset-y-0 data-[dropend=true]:after:right-0 data-[dropend=true]:after:w-0.5 data-[dropend=true]:after:bg-primary`),children:[(0,Q.jsxs)(Xr.div,{className:S(`flex h-full w-full min-w-0 items-center`,hl(i.align)),style:{height:t},animate:n?{opacity:s?.5:1}:{scale:s?1.04:1,opacity:s?.5:1},transition:zr,children:[m?(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Reorder ${i.key}`,onPointerDown:e=>_(i.key,e),onPointerMove:v,onPointerUp:y,className:`flex h-full w-6 cursor-grab touch-none items-center justify-center text-muted-foreground/60 transition-colors hover:text-foreground active:cursor-grabbing`,children:(0,Q.jsx)(b,{icon:Me,className:`size-3.5`})}):null,i.sortable?(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>l(i.key),className:S(`flex h-full min-w-0 flex-1 select-none items-center gap-1 px-4 transition-colors hover:text-foreground`,hl(i.align),o&&`text-foreground`),children:[i.header,(0,Q.jsx)(Xr.span,{"aria-hidden":!0,className:`inline-flex shrink-0`,animate:{rotate:o&&c?.direction===`desc`?180:0,opacity:o?1:.35},transition:n?{duration:0}:{duration:.18,ease:Wr},children:(0,Q.jsx)(b,{icon:zt,className:`size-3`})})]}):w?(0,Q.jsx)(`input`,{defaultValue:typeof i.header==`string`?i.header:i.key,"aria-label":`Rename ${i.key}`,onBlur:e=>w(i.key,e.target.value),onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()},className:S(`min-w-0 flex-1 truncate appearance-none rounded-md border-0 bg-transparent px-4 font-medium text-muted-foreground outline-none transition-colors focus:bg-muted focus:text-foreground`,gl(i.align))}):(0,Q.jsx)(`div`,{className:S(`min-w-0 flex-1 truncate px-4`,gl(i.align)),children:i.header})]}),u?(0,Q.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize ${i.key}`,onPointerDown:e=>d(i.key,e),onPointerMove:f,onPointerUp:p,className:`absolute top-0 right-0 h-full w-1.5 cursor-col-resize touch-none bg-transparent transition-colors hover:bg-primary/40`}):null]},i.key)}),O?(0,Q.jsx)(`th`,{className:`sticky top-0 z-10 border-b border-border/60 bg-background p-0`,"aria-hidden":!0}):null]})})]})}function Tl({columns:e,thRefs:t,onColumnOrderChange:n}){let[r,i]=(0,Z.useState)(()=>e.map(e=>e.key)),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(null),l=(0,Z.useMemo)(()=>{let t=new Map(e.map(e=>[e.key,e])),n=r.filter(e=>t.has(e)),i=new Set(n);return e.forEach((t,r)=>{if(i.has(t.key))return;let a=n.length;if(r===0)a=0;else{let t=e[r-1],i=t?n.indexOf(t.key):-1;a=i===-1?r:i+1}n.splice(a,0,t.key),i.add(t.key)}),n.map(e=>t.get(e)).filter(e=>e!==void 0)},[r,e]),u=(0,Z.useCallback)(e=>{for(let n=0;n<l.length;n++){let r=l[n];if(!r)continue;let i=t.current[r.key]?.getBoundingClientRect();if(i&&e<i.left+i.width/2)return n}return l.length},[l,t]);return{orderedColumns:l,dragKey:a,dropIndex:s,startReorder:(0,Z.useCallback)((e,t)=>{t.preventDefault(),t.stopPropagation(),o(e),t.currentTarget.setPointerCapture(t.pointerId)},[]),moveReorder:(0,Z.useCallback)(e=>{a&&c(u(e.clientX))},[a,u]),endReorder:(0,Z.useCallback)(e=>{if(e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId),a&&s!==null){let e=l.map(e=>e.key),t=e.indexOf(a);if(t!==-1){let r=e.filter((e,n)=>n!==t),o=s;t<o&&o--,r.splice(o,0,a),i(r),n?.(r)}}o(null),c(null)},[a,s,l,n])}}function El({orderedColumns:e,thRefs:t,minColumnWidth:n,onColumnResize:r}){let i=(0,Z.useRef)(null),[a,o]=(0,Z.useState)({});return{widths:a,startResize:(0,Z.useCallback)((r,s)=>{s.preventDefault(),s.stopPropagation();let c={...a};for(let r of e)if(c[r.key]==null){let e=t.current[r.key]?.getBoundingClientRect().width;c[r.key]=e?Math.round(e):n}i.current={key:r,startX:s.clientX,startWidth:c[r]??n},o(c),s.currentTarget.setPointerCapture(s.pointerId)},[n,e,t,a]),moveResize:(0,Z.useCallback)(e=>{let t=i.current;if(!t)return;let r=Math.max(n,t.startWidth+(e.clientX-t.startX));o(e=>({...e,[t.key]:r}))},[n]),endResize:(0,Z.useCallback)(e=>{let t=i.current;i.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId),t&&r?.(t.key,a[t.key]??t.startWidth)},[r,a])}}function Dl({rows:e,columns:t,sort:n,defaultSort:r=null,onSortChange:i}){let[a,o]=(0,Z.useState)(r),s=n===void 0?a:n,c=(0,Z.useCallback)(e=>{n===void 0&&o(e),i?.(e)},[n,i]),l=(0,Z.useCallback)(e=>{!s||s.key!==e?c({key:e,direction:`asc`}):s.direction===`asc`?c({key:e,direction:`desc`}):c(null)},[s,c]);return{sort:s,sortedRows:(0,Z.useMemo)(()=>{if(!s)return e;let n=t.find(e=>e.key===s.key);if(!n)return e;let r=[...e];return r.sort((e,t)=>{let r=vl(e.row,n),i=vl(t.row,n),a=typeof r==`number`&&typeof i==`number`?r-i:String(r).localeCompare(String(i));return s.direction===`asc`?a:-a}),r},[e,s,t]),toggleSort:l}}function Ol({sortedRows:e,selectedRowIds:t,defaultSelectedRowIds:n,onSelectionChange:r}){let[i,a]=(0,Z.useState)(()=>new Set(n)),o=(0,Z.useMemo)(()=>t===void 0?i:new Set(t),[t,i]),s=(0,Z.useCallback)(e=>{t===void 0&&a(e),r?.([...e])},[t,r]),c=e.length>0&&e.every(e=>o.has(e.id));return{selected:o,allSelected:c,someSelected:e.some(e=>o.has(e.id)),toggleAll:(0,Z.useCallback)(()=>{let t=new Set(o);if(c)for(let n of e)t.delete(n.id);else for(let n of e)t.add(n.id);s(t)},[c,e,o,s]),toggleRow:(0,Z.useCallback)(e=>{let t=new Set(o);t.has(e)?t.delete(e):t.add(e),s(t)},[o,s])}}var kl=`input, textarea, button, [role='checkbox']`,Al=4;function jl(e){if(!(e instanceof Element))return null;let t=e.closest(`[data-slot='table-cell']`);if(!t)return null;let n=Number(t.getAttribute(`data-row`)),r=Number(t.getAttribute(`data-col`));return!Number.isInteger(n)||!Number.isInteger(r)||n<0||r<0?null:{row:n,col:r}}function Ml(e,t,n){return e?e.anchor.row===t&&e.anchor.col===n&&e.head.row===t&&e.head.col===n:!1}function Nl(e){let t=(0,Z.useRef)(!1),n=(0,Z.useRef)(!1),r=(0,Z.useRef)(!1),i=(0,Z.useRef)(null),a=(0,Z.useRef)(e.range);a.current=e.range;let o=(0,Z.useRef)(e.onChange);o.current=e.onChange;let s=(0,Z.useRef)(e.onActivate);s.current=e.onActivate;let c=(0,Z.useRef)(e.enabled);return c.current=e.enabled,{onCellPointerDown:(0,Z.useCallback)((e,s,l)=>{if(!c.current||l.button!==0)return;let u=l.target;if(u instanceof Element&&u.closest(kl))return;t.current=!0,n.current=!1,i.current={x:l.clientX,y:l.clientY,row:e,col:s},r.current=!l.shiftKey&&Ml(a.current,e,s);let d=l.currentTarget.closest(`[data-slot='table-scroller']`);d instanceof HTMLElement&&d.setPointerCapture?.(l.pointerId);let f=a.current;l.shiftKey&&f?o.current?.({anchor:f.anchor,head:{row:e,col:s}}):o.current?.({anchor:{row:e,col:s},head:{row:e,col:s}})},[]),onScrollerPointerDown:(0,Z.useCallback)(e=>{c.current&&e.button===0&&(jl(e.target)||e.target instanceof Element&&e.target.closest(`thead, button, input, textarea, [role='checkbox']`)||o.current?.(null))},[]),onScrollerPointerMove:(0,Z.useCallback)(e=>{if(!t.current)return;let s=i.current;s&&Math.hypot(e.clientX-s.x,e.clientY-s.y)>Al&&(n.current=!0,r.current=!1);let c=jl(document.elementFromPoint(e.clientX,e.clientY));if(!c)return;let l=a.current?.anchor??s??c;o.current?.({anchor:{row:l.row,col:l.col},head:c})},[]),onPointerUp:(0,Z.useCallback)(()=>{let e=i.current,a=r.current&&!n.current;t.current=!1,n.current=!1,r.current=!1,i.current=null,a&&e&&s.current?.(e.row,e.col)},[])}}function Pl({data:e,columns:t,getRowId:n,selectable:r=!1,selectedRowIds:i,defaultSelectedRowIds:a,onSelectionChange:o,sort:s,defaultSort:c=null,onSortChange:l,resizable:u=!1,minColumnWidth:d=64,onColumnResize:f,reorderable:p=!1,onColumnOrderChange:m,onCellEdit:h,onColumnRename:g,onInsertRow:_,onDeleteRow:v,onInsertColumn:y,onDeleteColumn:b,onRowDoubleClick:x,onRowContextMenu:C,onViewportContextMenu:w,cellRange:T=null,onCellRangeChange:E,onCellActivate:D,rowHeight:O=48,height:k=440,overscan:A=10,onEndReached:j,loading:M=!1,skeletonRows:N=3,emptyState:P=`No data`,className:F}){let I=!!ti(),L=(0,Z.useRef)(null),R=(0,Z.useRef)({}),z=(0,Z.useMemo)(()=>e.map((e,t)=>({row:e,id:n?n(e,t):String(t)})),[e,n]),{orderedColumns:B,dragKey:V,dropIndex:H,startReorder:ee,moveReorder:te,endReorder:ne}=Tl({columns:t,thRefs:R,onColumnOrderChange:m}),{sort:re,sortedRows:U,toggleSort:ie}=Dl({rows:z,columns:t,sort:s,defaultSort:c,onSortChange:l}),{widths:ae,startResize:oe,moveResize:se,endResize:ce}=El({orderedColumns:B,thRefs:R,minColumnWidth:d,onColumnResize:f}),{selected:le,allSelected:ue,someSelected:de,toggleAll:W,toggleRow:fe}=Ol({sortedRows:U,selectedRowIds:i,defaultSelectedRowIds:a,onSelectionChange:o}),pe=Nl({enabled:E!==void 0,range:T,onChange:E,onActivate:D}),me=sl({count:U.length,getScrollElement:()=>L.current,estimateSize:()=>O,overscan:A}),he=me.getVirtualItems(),ge=me.getTotalSize(),_e=he[0],ve=he[he.length-1],ye=_e?_e.start:0,be=ve?ge-ve.end:0,xe=!!(_||v),Se=B.length>0&&B.every(e=>ae[e.key]!=null),Ce=(0,Z.useRef)(!1);(0,Z.useEffect)(()=>{M||(Ce.current=!1)},[M]);let we=(0,Z.useCallback)(()=>{let e=L.current;e&&j&&!M&&!Ce.current&&e.scrollHeight-e.scrollTop-e.clientHeight<O*4&&(Ce.current=!0,j())},[j,M,O]),[Te,G]=(0,Z.useState)(null),Ee=(0,Z.useRef)(null),De=(0,Z.useCallback)(e=>{Ee.current&&clearTimeout(Ee.current),Ee.current=null,G(e)},[]),Oe=(0,Z.useCallback)(()=>{Ee.current&&clearTimeout(Ee.current),Ee.current=setTimeout(()=>G(null),100)},[]),ke=(0,Z.useRef)({}),[K,Ae]=(0,Z.useState)(null),je=(0,Z.useRef)(null),q=(0,Z.useCallback)((e,t)=>{je.current&&clearTimeout(je.current),je.current=null,Ae({id:e,index:t})},[]),Me=(0,Z.useCallback)(()=>{je.current&&clearTimeout(je.current),je.current=setTimeout(()=>Ae(null),100)},[]),Ne=K?ke.current[K.id]??null:null,Pe=t.length+ +!!r,Fe=!B.some(e=>e.fill&&ae[e.key]==null),Ie=Pe+ +!!Fe;return(0,Q.jsxs)(`div`,{className:S(`w-full overflow-hidden border border-border/60 bg-background text-sm`,F),children:[(0,Q.jsx)(`div`,{ref:L,"data-slot":`table-scroller`,onScroll:we,onPointerDown:pe.onScrollerPointerDown,onPointerMove:pe.onScrollerPointerMove,onPointerUp:pe.onPointerUp,onPointerCancel:pe.onPointerUp,onContextMenu:e=>{if(!w)return;let t=e.target;t instanceof Element&&t.closest(`[data-slot='table-row']`)||(e.preventDefault(),w())},className:S(`overflow-auto`,E?`select-none`:void 0),style:{height:k},children:(0,Q.jsxs)(`table`,{className:S(`border-collapse`,Se?`w-max min-w-full`:`min-w-full`),style:{tableLayout:`fixed`},children:[(0,Q.jsxs)(`colgroup`,{children:[r?(0,Q.jsx)(`col`,{style:{width:dl}}):null,B.map(e=>{let t=ae[e.key],n=t==null?e.width:`${t}px`;return(0,Q.jsx)(`col`,{style:n?{width:n}:void 0},e.key)}),Fe?(0,Q.jsx)(`col`,{}):null]}),(0,Q.jsx)(wl,{columns:B,rowHeight:O,reduce:I,thRefs:R,selectable:r,allSelected:ue,someSelected:de,onToggleAll:W,sort:re,onToggleSort:ie,resizable:u,onResizeStart:oe,onResizeMove:se,onResizeEnd:ce,reorderable:p,dragKey:V,dropIndex:H,onReorderStart:ee,onReorderMove:te,onReorderEnd:ne,onInsertColumn:y,onDeleteColumn:b,onColumnRename:g,activeColumn:Te,onColumnActivate:De,onColumnDeactivate:Oe,slack:Fe}),(0,Q.jsx)(`tbody`,{children:U.length===0?M?(0,Q.jsx)(xl,{count:N,columns:B,selectable:r,rowHeight:O,slack:Fe}):(0,Q.jsx)(`tr`,{children:(0,Q.jsx)(`td`,{colSpan:Ie,className:`px-4 py-8 text-center text-muted-foreground`,children:P})}):(0,Q.jsxs)(Q.Fragment,{children:[ye>0?(0,Q.jsx)(`tr`,{children:(0,Q.jsx)(`td`,{colSpan:Ie,style:{height:ye,padding:0,border:`none`}})}):null,he.map(e=>{let t=U[e.index];if(!t)return null;let n=le.has(t.id);return(0,Q.jsxs)(`tr`,{ref:e=>{ke.current[t.id]=e},"data-slot":`table-row`,"data-selected":n,style:{height:O},onPointerEnter:xe?()=>q(t.id,e.index):void 0,onPointerLeave:xe?Me:void 0,onContextMenu:e=>{C&&(e.preventDefault(),e.stopPropagation(),C(t.row,t.id))},onDoubleClick:e=>{if(!x)return;let n=e.target;n instanceof Element&&n.closest(`input, textarea, button, [role='checkbox'], [data-slot='cell-display']`)||x(t.row,t.id)},className:S(`transition-colors hover:bg-muted/50`,`data-[selected=true]:bg-sky-500/10 data-[selected=true]:hover:bg-sky-500/15`),children:[r?(0,Q.jsx)(`td`,{className:S(`px-4 align-middle`,ml(n),n&&`bg-sky-500/10`),children:(0,Q.jsx)(`div`,{className:`flex items-center justify-center`,style:{height:O},children:(0,Q.jsx)(Rs,{checked:n,onCheckedChange:()=>fe(t.id),"aria-label":`Select row ${e.index+1}`,className:fl})})}):null,B.map((r,i)=>{let a=bl(T,e.index,i);return(0,Q.jsx)(`td`,{"data-slot":`table-cell`,"data-row":String(e.index),"data-col":String(i),"data-range":a.inRange?`in`:void 0,"data-range-head":a.isHead?`true`:void 0,className:S(`relative h-full cursor-cell overflow-hidden p-0`,gl(r.align),ml(n),!a.inRange&&`has-[[data-pending=true]]:bg-amber-500/10`,a.inRange&&`bg-sky-500/15`,a.isHead&&`z-[1] shadow-[inset_0_0_0_2px_color-mix(in_oklab,var(--color-sky-500)_45%,transparent)] has-[input]:shadow-none`),onPointerDown:t=>pe.onCellPointerDown(e.index,i,t),children:!r.cell&&r.editable?(0,Q.jsx)(`span`,{className:`absolute inset-0 flex items-center px-4`,children:(0,Q.jsx)(At,{value:yl(t.row,r.key),label:typeof r.header==`string`?r.header:r.key,onChange:e=>h?.(t.id,r.key,e)})}):_l(t.row,r)},r.key)}),Fe?(0,Q.jsx)(`td`,{"aria-hidden":!0,className:S(ml(n),n&&`bg-sky-500/10`)}):null]},t.id)}),be>0?(0,Q.jsx)(`tr`,{children:(0,Q.jsx)(`td`,{colSpan:Ie,style:{height:be,padding:0,border:`none`}})}):null,M?(0,Q.jsx)(xl,{count:N,columns:B,selectable:r,rowHeight:O,slack:Fe}):null]})})]})}),xe&&K?(0,Q.jsx)(ul,{rowEl:Ne,id:K.id,index:K.index,onInsertRow:_,onDeleteRow:v,onEnter:()=>q(K.id,K.index),onLeave:Me}):null]})}function Fl(){return Yr({mutationFn:async e=>{let t=await le(e);if(t.error){let e=Error(t.error.code);throw e.code=t.error.code,e.data=t.error.data,e}if(!t.data)throw Error(`Empty store reveal`);return t.data}})}function Il({refName:e,child:t,tenant:n,rowId:r,column:i,maskedValue:a}){let o=Fl(),[s,c]=(0,Z.useState)(null);return s===null?(0,Q.jsxs)(`span`,{className:`inline-flex max-w-full items-center gap-1`,"data-slot":`reveal-cell`,children:[(0,Q.jsx)(`span`,{className:`rounded-md bg-muted/70 px-1.5 py-px font-mono text-[10px] tracking-[0.22em] text-muted-foreground`,"aria-label":`Masked`,children:`••••••`}),(0,Q.jsxs)(w,{children:[(0,Q.jsx)(O,{render:a=>(0,Q.jsx)(G,{...a,type:`button`,variant:`ghost`,size:`icon-xs`,className:`size-5 text-muted-foreground`,disabled:o.isPending||r.length===0,"aria-label":`Reveal ${i}`,"data-slot":`reveal-button`,onClick:s=>{s.stopPropagation(),a.onClick?.(s),o.mutate({ref:e,child:t,...n===void 0?{}:{tenant:n},id:r,column:i},{onSuccess:e=>{c({value:e.value})}})},children:(0,Q.jsx)(b,{icon:li,className:`size-3`,"aria-hidden":!0})})}),(0,Q.jsx)(T,{side:`top`,className:`text-[11px]`,children:`Audited PII reveal — logged server-side`})]}),o.isError?(0,Q.jsx)(`span`,{className:`text-[10px] text-destructive`,role:`status`,children:o.error.message}):null,(0,Q.jsx)(`span`,{className:`sr-only`,children:Ll(i,a)})]}):(0,Q.jsxs)(`span`,{className:`inline-flex max-w-full items-center gap-1`,"data-slot":`reveal-cell`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[11px]`,children:Ll(i,s.value)}),(0,Q.jsxs)(w,{children:[(0,Q.jsx)(O,{render:e=>(0,Q.jsx)(G,{...e,type:`button`,variant:`ghost`,size:`icon-xs`,className:`size-5 text-muted-foreground`,"aria-label":`Hide ${i}`,"data-slot":`hide-button`,onClick:t=>{t.stopPropagation(),e.onClick?.(t),c(null)},children:(0,Q.jsx)(b,{icon:ri,className:`size-3`,"aria-hidden":!0})})}),(0,Q.jsx)(T,{side:`top`,className:`text-[11px]`,children:`Hide cleartext`})]})]})}function Ll(e,t){return wt(e,t)??It(t)}function Rl({open:e,onOpenChange:t,model:n,row:r,facet:i,storeRef:a,childName:o,tenant:s,masked:c=!1,asGate:l=null,asUserId:u=null,onDeleteRow:d}){let f=Fa(),[p,m]=(0,Z.useState)(`fields`),[h,g]=(0,Z.useState)(!1),[_,v]=(0,Z.useState)({}),[y,C]=(0,Z.useState)(null),w=(0,Z.useMemo)(()=>n.columns.filter(e=>e.editable),[n.columns]),T=n.editable&&(i===`sql`||i===`kv`)&&w.length>0;(0,Z.useEffect)(()=>{e&&(m(`fields`),g(!1),C(null))},[e,r]);let E=(0,Z.useMemo)(()=>{if(!r)return``;try{return JSON.stringify(r.cells,null,2)}catch{return`[unserializable row]`}},[r]);if(!r)return(0,Q.jsx)(Q.Fragment,{});let O=()=>{let e={};for(let t of w)e[t.key]=zl(t.type,r.cells[t.key]);v(e),C(null),g(!0),m(`fields`)},k=async()=>{C(null);let e={};for(let t of w){let n=_[t.key]??``;t.pii&&n.trim()===``||n!==zl(t.type,r.cells[t.key])&&(e[t.key]=Bt(t.type,n))}if(Object.keys(e).length===0){g(!1);return}try{await f.mutateAsync({ref:a,...i===`sql`?{child:o,id:r.id}:{key:r.id},...s?{tenant:s}:{},...l?{asGate:l}:{},...u?{asUserId:u}:{},patch:sn(e),commit:!0}),g(!1)}catch(e){C(e instanceof Error?e.message:String(e))}};return(0,Q.jsx)(re,{open:e,onOpenChange:t,children:(0,Q.jsxs)(W,{side:`right`,showOverlay:!1,className:`gap-0 p-0 sm:max-w-md`,"data-slot":`store-row-detail-sheet`,"data-editing":h?`true`:`false`,children:[(0,Q.jsxs)(oe,{className:`gap-2 border-b border-border/50`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-0.5 pr-8`,children:[(0,Q.jsxs)(be,{className:`text-sm`,children:[h?`Edit`:`Row`,` `,(0,Q.jsx)(`span`,{className:`font-mono`,children:r.id})]}),(0,Q.jsxs)(ge,{className:`font-mono text-[11px]`,children:[a,i===`sql`?`/${o}`:``]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-4`,role:`tablist`,"aria-label":`Row detail tabs`,children:[(0,Q.jsx)(Bl,{active:p===`fields`,onClick:()=>m(`fields`),id:`fields`,children:`Fields`}),(0,Q.jsx)(Bl,{active:p===`json`,onClick:()=>m(`json`),id:`json`,children:`JSON`})]})]}),(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto px-4 pb-2`,children:p===`fields`?(0,Q.jsx)(`ul`,{className:`flex flex-col divide-y divide-border/50`,"data-slot":`row-fields`,children:n.columns.map(e=>{let t=r.cells[e.key],n=e.pii&&c&&Kt(t),i=h&&e.editable;return(0,Q.jsxs)(`li`,{className:`flex items-baseline gap-3 py-1.5`,children:[(0,Q.jsxs)(`span`,{className:`flex w-32 shrink-0 items-center gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`truncate font-mono text-[11px] font-medium text-muted-foreground`,children:e.key}),(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[9px] text-muted-foreground/60`,children:e.type===`integer`||e.type===`number`?`123`:e.type===`json`?`{ }`:`abc`}),e.primaryKey?(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[9px] text-amber-600 dark:text-amber-400`,children:`PK`}):null,e.pii?(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[9px] text-sky-600 dark:text-sky-400`,children:`PII`}):null]}),i?e.type===`json`?(0,Q.jsx)(`textarea`,{value:_[e.key]??``,onChange:t=>v(n=>({...n,[e.key]:t.target.value})),"aria-label":e.key,rows:3,className:`min-h-16 min-w-0 flex-1 rounded-none border-0 bg-transparent font-mono text-[11px] outline-none`}):(0,Q.jsx)(x,{value:_[e.key]??``,onChange:t=>v(n=>({...n,[e.key]:t.target.value})),type:e.type===`integer`||e.type===`number`?`number`:`text`,"aria-label":e.key,flat:!0,className:S(X,`min-w-0 flex-1 px-0 font-mono`)}):n?(0,Q.jsx)(Il,{refName:a,child:o,...s?{tenant:s}:{},rowId:r.id,column:e.key,maskedValue:t}):(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 font-mono text-[11px] break-words`,dir:Ht(t)?`rtl`:`ltr`,children:Tt(e,t)})]},e.key)})}):(0,Q.jsx)(`div`,{className:`rounded-md border border-border/60`,"data-slot":`row-json`,children:(0,Q.jsx)(yt,{json:E,dataSlot:`store-row-json`,className:`flex max-h-none overflow-auto`})})}),y?(0,Q.jsx)(bi,{slot:`row-detail-error`,children:y}):null,(0,Q.jsxs)(`div`,{className:`mt-auto flex items-center justify-between gap-2 border-t border-border/50 px-4 py-2.5`,children:[h?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(G,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{g(!1),C(null)},disabled:f.isPending,"data-slot":`row-detail-cancel`,children:[(0,Q.jsx)(b,{icon:ae,className:`size-3.5`,"aria-hidden":!0}),`Cancel`]}),(0,Q.jsxs)(G,{type:`button`,size:`sm`,onClick:()=>void k(),disabled:f.isPending,"data-slot":`row-detail-save`,children:[(0,Q.jsx)(b,{icon:D,className:`size-3.5`,"aria-hidden":!0}),f.isPending?`Saving…`:`Save`]})]}):T?(0,Q.jsxs)(G,{type:`button`,variant:`outline`,size:`sm`,onClick:O,"data-slot":`row-detail-edit`,children:[(0,Q.jsx)(b,{icon:fn,className:`size-3.5`,"aria-hidden":!0}),`Edit`]}):(0,Q.jsx)(`span`,{}),!h&&d?(0,Q.jsxs)(G,{type:`button`,variant:`destructive`,size:`sm`,onClick:()=>d(r),"data-slot":`row-detail-delete`,children:[(0,Q.jsx)(b,{icon:pn,className:`size-3.5`,"aria-hidden":!0}),`Delete 1 row`]}):null]})]})})}function zl(e,t){if(t==null||Kt(t))return``;if(e===`json`)try{return JSON.stringify(t,null,2)}catch{return``}if(typeof t==`string`)return t;if(typeof t==`number`||typeof t==`boolean`)return String(t);try{return JSON.stringify(t)}catch{return``}}function Bl({active:e,onClick:t,id:n,children:r}){return(0,Q.jsx)(`button`,{type:`button`,role:`tab`,id:`tab-${n}`,"aria-selected":e,onClick:t,className:S(`px-2 py-1.5 text-[10px] font-semibold tracking-[0.08em] uppercase transition-colors hover:bg-muted/50`,e?`text-foreground`:`text-muted-foreground hover:text-foreground`),"data-slot":`row-tab-${n}`,children:r})}function Vl({open:e,onOpenChange:t,storeRef:n,childName:r,tenant:i,existingKeys:a}){let{mutate:o,isPending:s,reset:c}=Fa(),[l,u]=(0,Z.useState)(`${r}:`),[d,f]=(0,Z.useState)(`{
20
+
21
+ }`),[p,m]=(0,Z.useState)(``),[h,g]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{e&&(u(`${r}:`),f(`{
22
+
23
+ }`),m(``),g(null),c())},[e,r,c]),(0,Q.jsx)(re,{open:e,onOpenChange:t,children:(0,Q.jsxs)(W,{side:`right`,showOverlay:!1,className:`gap-0 p-0 data-[side=right]:sm:max-w-md`,"data-slot":`kv-add-sheet`,children:[(0,Q.jsxs)(oe,{className:`gap-1 border-b border-border/50`,children:[(0,Q.jsx)(be,{className:`text-sm`,children:`Add key`}),(0,Q.jsx)(ge,{className:`font-mono text-[11px]`,children:n})]}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:[(0,Q.jsx)(Y,{label:`Key`,children:(0,Q.jsx)(x,{value:l,onChange:e=>u(e.target.value),"aria-label":`Key`,flat:!0,className:S(X,`font-mono`),autoFocus:!0})}),(0,Q.jsx)(Y,{label:`Value`,children:(0,Q.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),"aria-label":`JSON value`,spellCheck:!1,className:`min-h-40 w-full flex-1 resize-y rounded-none border-0 bg-transparent px-4 py-1.5 font-mono text-[11px] leading-5 outline-none`})}),(0,Q.jsx)(Y,{label:`TTL`,children:(0,Q.jsx)(x,{value:p,onChange:e=>m(e.target.value),"aria-label":`TTL`,placeholder:`30m`,flat:!0,className:S(X,`font-mono`)})}),h?(0,Q.jsx)(bi,{slot:`kv-add-error`,children:h}):null]}),(0,Q.jsxs)(I,{children:[(0,Q.jsx)(gi,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(gi,{variant:`default`,disabled:s,onClick:()=>{let e=l.trim();if(e.length===0||e.endsWith(`:`)){g(`Key needs a name after the prefix`);return}if(a.includes(e)){g(`That key is already on this page`);return}let r=Ct(d);if(!r.ok){g(r.error);return}let s=Yt(p);if(s===void 0){g(`TTL must be a duration like 30m, 1h, or empty`);return}g(null),o({ref:n,key:e,...i?{tenant:i}:{},patch:{value:r.value,...s===null?{}:{ttl:s}},commit:!0},{onSuccess:()=>t(!1),onError:e=>g(e instanceof Error?e.message:String(e))})},"data-slot":`kv-add-submit`,children:s?`Adding…`:`Add key`})]})]})})}function Hl({open:e,onOpenChange:t,storeRef:n,childName:r,tenant:i,columns:a,asGate:o=null,asUserId:s=null}){let{mutate:c,isPending:l,reset:u}=Fa(),d=(0,Z.useMemo)(()=>qt(a),[a]),[f,p]=(0,Z.useState)({}),[m,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{e&&(p(Qt(d)),_(null),u())},[e,d,u]);let v=(e,t)=>{p(n=>({...n,[e]:t}))},y=()=>{let e=tn(d,f);if(!e.ok){_(e.error);return}_(null),c({ref:n,child:r,...i?{tenant:i}:{},...o?{asGate:o}:{},...s?{asUserId:s}:{},patch:e.patch,commit:!0},{onSuccess:()=>{if(m){p(Qt(d));return}t(!1)},onError:e=>_(e instanceof Error?e.message:String(e))})};return(0,Q.jsx)(re,{open:e,onOpenChange:t,children:(0,Q.jsxs)(W,{side:`right`,showOverlay:!1,className:`gap-0 p-0 data-[side=right]:sm:max-w-md`,"data-slot":`sql-insert-sheet`,onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),l||y())},children:[(0,Q.jsxs)(oe,{className:`gap-1 border-b border-border/50`,children:[(0,Q.jsxs)(be,{className:`text-sm`,children:[`Add new row to `,r]}),(0,Q.jsx)(ge,{className:`font-mono text-[11px]`,children:n})]}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:[d.map(e=>{let t=f[e.key]??``;return(0,Q.jsx)(Y,{label:e.key,hint:e.type===`integer`||e.type===`number`?`integer`:e.type,children:e.type===`json`?(0,Q.jsx)(`textarea`,{value:t,onChange:t=>v(e.key,t.target.value),"aria-label":e.key,placeholder:`Default: NULL`,spellCheck:!1,className:`min-h-20 w-full resize-y rounded-none border-0 bg-transparent px-4 py-1.5 font-mono text-[11px] leading-5 outline-none`}):(0,Q.jsx)(x,{value:t,onChange:t=>v(e.key,t.target.value),"aria-label":e.key,placeholder:e.key===`id`?void 0:`Default: NULL`,type:e.type===`integer`||e.type===`number`?`number`:`text`,flat:!0,className:S(X,`font-mono`),autoFocus:e.key===`id`})},e.key)}),g?(0,Q.jsx)(bi,{slot:`sql-insert-error`,children:g}):null]}),(0,Q.jsx)(mi,{label:`Create more`,children:(0,Q.jsx)(Ra,{size:`sm`,checked:m,onCheckedChange:h,ariaLabel:`Create more`})}),(0,Q.jsxs)(I,{children:[(0,Q.jsx)(gi,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(gi,{variant:`default`,disabled:l,onClick:y,"data-slot":`sql-insert-submit`,children:l?`Saving…`:`Save`})]})]})})}function Ul({value:e,type:t}){return e?(0,Q.jsxs)(`span`,{className:S(`font-mono text-xs tabular-nums`,t===`added`?`text-emerald-600 dark:text-emerald-400`:`text-rose-600 dark:text-rose-400`),children:[t===`added`?`+`:`−`,e]}):null}function Wl({file:e,lines:t,status:n=`streaming`,open:r,defaultOpen:i=!0,onOpenChange:a,collapseOnComplete:o=!0,maxHeight:s=220,language:c=`typescript`,copyText:l,onCopy:u,className:d}){let f=ti()??!1,p=(0,Z.useId)(),m=`${p}-trigger`,h=`${p}-content`,g=(0,Z.useRef)(null),_=(0,Z.useRef)(n),v=(0,Z.useRef)(void 0),[y,x]=(0,Z.useState)(!1),[C,w]=(0,Z.useState)(i),T=r??C,E=n===`streaming`,O=t.filter(e=>e.type===`added`).length,k=t.filter(e=>e.type===`removed`).length,A=!!(l||u),j=Mo(t.map(e=>e.content).join(`
24
+ `),c),M=(0,Z.useCallback)(e=>{r===void 0&&w(e),a?.(e)},[a,r]);(0,Z.useEffect)(()=>{_.current!==`streaming`&&n===`streaming`&&M(!0),_.current===`streaming`&&n===`complete`&&o&&M(!1),_.current=n},[o,M,n]),(0,Z.useEffect)(()=>()=>{v.current&&window.clearTimeout(v.current)},[]),(0,Z.useLayoutEffect)(()=>{let e=g.current;if(!e||!T||!E)return;let t=requestAnimationFrame(()=>{e.scrollHeight<=e.clientHeight||(typeof e.scrollTo==`function`?e.scrollTo({top:e.scrollHeight,behavior:f?`auto`:`smooth`}):e.scrollTop=e.scrollHeight)});return()=>cancelAnimationFrame(t)});let N=(0,Z.useCallback)(async()=>{u?await u():l&&await navigator.clipboard?.writeText(l),x(!0),v.current&&window.clearTimeout(v.current),v.current=window.setTimeout(()=>x(!1),1600)},[l,u]);return(0,Q.jsxs)(`div`,{"data-state":n,"aria-busy":E,className:S(`w-full text-sm`,d),children:[(0,Q.jsxs)(`button`,{id:m,type:`button`,"aria-expanded":T,"aria-controls":h,onClick:()=>M(!T),className:`group flex min-h-9 w-full items-center gap-2 rounded-md py-1 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background`,children:[(0,Q.jsx)(b,{icon:Ze,"aria-hidden":`true`,className:`size-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs`,children:e}),(0,Q.jsx)(Ul,{value:O,type:`added`}),(0,Q.jsx)(Ul,{value:k,type:`removed`}),E?(0,Q.jsx)(b,{icon:Jr,"aria-label":`Applying changes`,className:S(`size-3.5 text-muted-foreground`,!f&&`animate-spin`)}):null,(0,Q.jsx)(Xr.span,{"aria-hidden":`true`,animate:{rotate:T?180:0},transition:f?{duration:0}:Qr,className:`shrink-0 text-muted-foreground/45 transition-colors group-hover:text-muted-foreground`,children:(0,Q.jsx)(b,{icon:et,className:`size-3.5`})})]}),(0,Q.jsx)(wi,{id:h,role:`region`,"aria-labelledby":m,open:T,children:(0,Q.jsxs)(`div`,{className:`relative overflow-hidden rounded-lg border border-border/70 bg-muted/20`,children:[(0,Q.jsxs)(`div`,{ref:g,"data-slot":`file-diff-viewport`,"aria-live":`polite`,className:`overflow-auto`,style:{maxHeight:s},children:[(0,Q.jsx)(`div`,{className:`sr-only`,children:`File changes`}),t.map((e,t)=>{let n=e.type??`context`;return(0,Q.jsxs)(`div`,{className:S(`grid grid-cols-[1.5rem_0.75rem_minmax(0,1fr)] items-start font-mono text-xs leading-5`,n===`added`&&`bg-emerald-500/[0.07]`,n===`removed`&&`bg-rose-500/[0.07]`),children:[(0,Q.jsx)(`span`,{className:`select-none pl-1 pr-0.5 text-right text-muted-foreground/45 tabular-nums`,children:e.newLine??e.oldLine??``}),(0,Q.jsx)(`span`,{className:S(`select-none text-center text-muted-foreground/45`,n===`added`&&`text-emerald-600 dark:text-emerald-400`,n===`removed`&&`text-rose-600 dark:text-rose-400`),children:n===`added`?`+`:n===`removed`?`−`:``}),(0,Q.jsx)(No,{code:e.content,tokens:j?.[t],className:`block min-w-0 whitespace-pre-wrap break-all pr-1.5 pl-1`})]},e.id)})]}),A?(0,Q.jsx)(Xr.button,{type:`button`,"aria-label":y?`Copied`:`Copy diff`,title:y?`Copied`:`Copy diff`,onClick:()=>void N(),whileTap:f?void 0:{scale:.9},transition:zr,className:`absolute top-2 right-2 grid size-7 place-items-center rounded-md text-muted-foreground outline-none transition-colors hover:bg-background/70 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring`,children:(0,Q.jsx)(b,{icon:y?D:Pe,className:`size-3.5`})}):null]})})]})}function Gl(e,t){return`${e}\0${t}`}function Kl(e,t,n){let r=new Map(e),i=Gl(n.rowId,n.key),a=t.filter(e=>e!==i);return Object.is(n.prev,n.next)?(r.delete(i),{pending:r,log:a}):(r.set(i,n),{pending:r,log:[...a,i]})}function ql(e,t){let n=t[t.length-1];if(n===void 0)return{pending:new Map(e),log:[...t],popped:null};let r=e.get(n)??null,i=new Map(e);return i.delete(n),{pending:i,log:t.slice(0,-1),popped:r}}function Jl(e){return[...e.values()].map(e=>({rowId:e.rowId,key:e.key,prev:e.prev,next:e.next}))}function Yl(e){let{matrix:t,rowIds:n,columnKeys:r,writable:i}=e;if(t.length===0||n.length===0||r.length===0)return[];let a=Math.max(0,Math.min(e.startCol,r.length-1)),o=[];for(let e=0;e<n.length;e++){let s=n[e],c=t[e%t.length];if(s&&c)for(let e=0;e<c.length;e++){let t=r[a+e];t&&i(s,t)&&o.push({rowId:s,key:t,text:c[e]??``})}}return o}function Xl(e){let{range:t,rowIds:n,columnKeys:r,text:i,writable:a}=e,o=[];for(let e of Wt(t)){let t=n[e.row],s=r[e.col];t&&s&&a(t,s)&&o.push({rowId:t,key:s,text:i})}return o}function Zl(e){return e==null?`NULL`:typeof e==`number`&&Number.isFinite(e)?String(e):typeof e==`boolean`?e?`TRUE`:`FALSE`:`'${(typeof e==`string`?e:nu(e)??`[unserializable]`).replaceAll(`'`,`''`)}'`}function Ql(e){return`${e.table} > row ${e.rowId} > ${e.key}`}function $l(e){let t=e.pk??`id`,n=new Map;for(let t of e.updates){let e=n.get(t.rowId)??[];e.push(t),n.set(t.rowId,e)}let r=[];for(let[i,a]of n){let n=a[0],o=a.length===1&&n?`-- Update ${n.key} in row ${i} of ${e.table}`:`-- Update row ${i} of ${e.table}`,s=a.map(e=>`"${e.key}" = ${Zl(e.next)}`).join(`, `);r.push(`${o}\nUPDATE "${e.table}" SET ${s} WHERE "${t}" = ${Zl(i)};`)}return r.join(`
25
+
26
+ `)}function eu(e){let t=new Map;for(let n of e.updates){let e=t.get(n.rowId)??[];e.push(n),t.set(n.rowId,e)}let n=[];for(let[e,r]of t){let t=r.find(e=>e.key===`value`),i=r.find(e=>e.key===`ttl`),a=t?tu(t.next):`value`,o=i===void 0||i.next===null||i.next===``?void 0:typeof i.next==`string`?JSON.stringify(i.next):void 0,s=[JSON.stringify(e),a];o!==void 0&&s.push(o);let c=t&&i?`// Update value and TTL on ${e}`:i&&o===void 0?`// Clear TTL on ${e}`:i?`// Update TTL on ${e}`:`// Update ${e}`;n.push(`${c}\nset(${s.join(`, `)})`)}return n.join(`
27
+
28
+ `)}function tu(e){try{return JSON.stringify(e,null,2)??`undefined`}catch{return`undefined`}}function nu(e){try{return JSON.stringify(e)}catch{return null}}function ru({open:e,onOpenChange:t,pending:n,table:r,facet:i=`sql`,saving:a,error:o,onUndoCell:s,onClearAll:c,onCommitAll:l}){let[u,d]=(0,Z.useState)(`visual`),f=(0,Z.useMemo)(()=>Jl(n),[n]),p=i===`kv`,m=(0,Z.useMemo)(()=>p?eu({updates:f}):$l({table:r,updates:f}),[p,r,f]),h=(0,Z.useMemo)(()=>m.split(`
29
+ `).map((e,t)=>({id:`script-${t}`,type:e.startsWith(`--`)||e.startsWith(`//`)?`context`:`added`,newLine:t+1,content:e})),[m]),g=n.size,_=ni(`S`);return(0,Q.jsx)(re,{open:e,onOpenChange:t,children:(0,Q.jsxs)(W,{side:`right`,showOverlay:!1,className:`w-[24rem] gap-0 p-0 sm:max-w-md`,"data-slot":`pending-changes-sheet`,children:[(0,Q.jsxs)(oe,{className:`gap-2 border-b border-border/50`,children:[(0,Q.jsx)(be,{children:`Pending Changes`}),(0,Q.jsx)(ge,{className:`sr-only`,children:`Review staged cell edits, then commit or discard them.`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-4`,role:`tablist`,"aria-label":`Pending changes view`,children:[(0,Q.jsx)(iu,{active:u===`visual`,onClick:()=>d(`visual`),id:`visual`,children:`Visual`}),(0,Q.jsx)(iu,{active:u===`script`,onClick:()=>d(`script`),id:`script`,children:p?`KV`:`SQL`})]})]}),(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto px-3 py-3`,children:g===0?(0,Q.jsx)(`p`,{className:`px-1 py-8 text-center text-sm text-muted-foreground`,children:`No pending changes.`}):u===`visual`?(0,Q.jsx)(`ul`,{className:`flex flex-col gap-3`,"data-slot":`pending-visual`,children:f.map(e=>{let t=Ql({table:r,rowId:e.rowId,key:e.key});return(0,Q.jsxs)(`li`,{className:`overflow-hidden rounded-lg border border-border/70`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,Q.jsx)(`span`,{className:`grid size-5 shrink-0 place-items-center rounded-md bg-amber-700/50 font-mono text-[10px] font-bold text-amber-100`,title:`Update`,children:`U`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground`,children:t}),(0,Q.jsx)(G,{type:`button`,variant:`ghost`,size:`icon-xs`,disabled:a,"aria-label":`Undo ${t}`,onClick:()=>s(e.rowId,e.key),children:(0,Q.jsx)(b,{icon:Vi,className:`size-3.5`})})]}),(0,Q.jsxs)(`div`,{className:`font-mono text-xs leading-5`,children:[(0,Q.jsxs)(`div`,{className:`flex gap-1.5 bg-rose-500/[0.12] px-2.5 py-0.5 text-rose-700 dark:text-rose-300`,children:[(0,Q.jsx)(`span`,{className:`w-3 shrink-0 select-none`,children:`−`}),(0,Q.jsx)(`span`,{className:`min-w-0 break-all`,children:It(e.prev)})]}),(0,Q.jsxs)(`div`,{className:`flex gap-1.5 bg-emerald-500/[0.12] px-2.5 py-0.5 text-emerald-800 dark:text-emerald-300`,children:[(0,Q.jsx)(`span`,{className:`w-3 shrink-0 select-none`,children:`+`}),(0,Q.jsx)(`span`,{className:`min-w-0 break-all`,children:It(e.next)})]})]})]},`${e.rowId}\0${e.key}`)})}):(0,Q.jsx)(Wl,{file:p?`${r}.ts`:`${r}.sql`,lines:h,status:`complete`,collapseOnComplete:!1,defaultOpen:!0,language:p?`typescript`:`sql`,maxHeight:480,copyText:m,className:`min-w-0`})}),o?(0,Q.jsx)(bi,{children:o}):null,(0,Q.jsxs)(I,{children:[(0,Q.jsx)(gi,{split:!0,disabled:a||g===0,onClick:c,children:`Clear All`}),(0,Q.jsxs)(gi,{variant:`default`,disabled:a||g===0,onClick:l,"data-slot":`commit-all`,children:[a?`Committing…`:`Commit All (${g})`,(0,Q.jsx)(ve,{keys:_,className:`ml-1.5`})]})]})]})})}function iu({active:e,onClick:t,id:n,children:r}){return(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":e,id:`pending-tab-${n}`,onClick:t,className:S(`px-2 py-1.5 text-[10px] font-semibold tracking-[0.08em] uppercase transition-colors hover:bg-muted/50`,e?`text-foreground`:`text-muted-foreground hover:text-foreground`),children:r})}var au={past:[],future:[]};function ou(e,t,n=100){let r=[...e.past,t];return{past:r.length>n?r.slice(r.length-n):r,future:[]}}function su(e){let t=e.past[e.past.length-1];return t?{history:{past:e.past.slice(0,-1),future:[t,...e.future]},batch:t}:{history:e,batch:null}}function cu(e){let t=e.future[0];return t?{history:{past:[...e.past,t],future:e.future.slice(1)},batch:t}:{history:e,batch:null}}function lu(e){return{at:e.at,updates:e.updates.map(e=>({...e,prev:e.next,next:e.prev}))}}var uu={short:26,medium:34,tall:44,"extra-tall":56};function du(e){return e===`comment`||e===`value`}function fu(e,t){if(t===`id`||t===`key`||t===`name`)return 192;if(t===`title`)return 300;if(t===`version`)return 72;if(t===`ttl`)return 88;if(t===`size`)return 80;if(t===`enabled`)return 88;if(t===`source`)return 112;switch(e){case`boolean`:return 88;case`integer`:case`number`:return 112;case`json`:return 288;default:return 224}}function pu(e){switch(e){case`integer`:case`number`:return`123`;case`json`:return`{ }`;case`boolean`:return`01`;default:return`abc`}}function mu(e){return e===`integer`||e===`number`}function hu(e,t){if(e.format===`ttl`){let e=Yt(t);return e===void 0?{ok:!1}:{ok:!0,next:e}}return{ok:!0,next:t.trim()===``?null:Bt(e.type,t)}}function gu(e,t){if(e.format===`ttl`||t==null)return``;if(e.type===`json`)try{return JSON.stringify(t)}catch{return``}if(typeof t==`string`||typeof t==`number`||typeof t==`boolean`)return String(t);try{return JSON.stringify(t)}catch{return``}}function _u({model:e,facet:t,storeRef:n,childName:r,tenant:i,masked:a=!1,routedRole:o,limit:s,toolbarExtras:c,indexSearch:l,insertOpen:u=!1,onInsertOpenChange:d,onDeleteRows:f,asGate:p=null,asUserId:m=null,onViewportContextMenu:h}){let[g,_]=(0,Z.useState)(``),[v,y]=(0,Z.useState)([]),[S,C]=(0,Z.useState)(new Set),[w,T]=(0,Z.useState)(`medium`),[E,O]=(0,Z.useState)(null),[k,A]=(0,Z.useState)(null),[j,M]=(0,Z.useState)(null),[N,P]=(0,Z.useState)(au),[F,I]=(0,Z.useState)(new Map),[L,R]=(0,Z.useState)(null),[z,B]=(0,Z.useState)(null),[V,H]=(0,Z.useState)(null),[ee,te]=(0,Z.useState)(null),[ne,re]=(0,Z.useState)(!1),[U,ie]=(0,Z.useState)(null),[oe,se]=(0,Z.useState)(null),[ce,le]=(0,Z.useState)(!1),[ue,de]=(0,Z.useState)(!1),[W,fe]=(0,Z.useState)(!1),[pe,me]=(0,Z.useState)(440),he=(0,Z.useRef)(null),ge=(0,Z.useRef)(null),_e=(0,Z.useRef)(null),ve=(0,Z.useRef)(F),ye=(0,Z.useRef)([]);ve.current=F;let be=Fa(),xe=f!==void 0,Se=e.editable&&(t===`sql`||t===`kv`),Ce=uu[w],we=(0,Z.useMemo)(()=>e.columns.filter(e=>!S.has(e.key)),[e.columns,S]),Te=(e,n)=>{if(t===`kv`&&n===`size`){let t=F.get(Gl(e.id,`value`))?.next??e.cells.value;return xt(t)}return F.get(Gl(e.id,n))?.next??e.cells[n]},Ee=l!==void 0,De=Ee?l.value:g,Oe=(0,Z.useMemo)(()=>{if(Ee||!g.trim())return e.rows;let t=g.trim().toLowerCase();return e.rows.filter(n=>e.columns.some(e=>{if(Tt(e,Te(n,e.key)).toLowerCase().includes(t))return!0;if(e.format!==`name-key`)return!1;let r=n.cells.name,i=n.cells.version;return typeof r==`string`&&r.toLowerCase().includes(t)||i!=null&&String(i).toLowerCase().includes(t)}))},[e.rows,e.columns,g,F,Ee]),ke=(0,Z.useMemo)(()=>{if(!E)return Oe;let t=we.find(e=>e.key===E.key)??e.columns.find(e=>e.key===E.key);if(!t)return Oe;let n=[...Oe];return n.sort((e,n)=>{let r=Te(e,t.key),i=Te(n,t.key),a=typeof r==`number`&&typeof i==`number`?r-i:It(r).localeCompare(It(i));return E.direction===`asc`?a:-a}),n},[Oe,E,F,we,e.columns]);(0,Z.useEffect)(()=>{y([]),C(new Set),A(null),P(au),I(new Map),ye.current=[],R(null),B(null),H(null),te(null),re(!1),ie(null),de(!1),O(null),_(``)},[t,n,r,i]),(0,Z.useEffect)(()=>{if(!j)return;let e=setTimeout(()=>M(null),2e3);return()=>clearTimeout(e)},[j]),(0,Z.useEffect)(()=>{let e=he.current;if(!e)return;let t=new ResizeObserver(e=>{let t=e[0]?.contentRect.height;t&&me(Math.max(120,Math.round(t)))});return t.observe(e),()=>t.disconnect()},[]);let K=(0,Z.useMemo)(()=>e.rows.filter(e=>v.includes(e.id)),[e.rows,v]),Ae=(e,t)=>Se&&e.editable&&!(e.pii&&a&&Kt(t)),je=(e,t)=>{ve.current=e,ye.current=t,I(e)},q=(t,n)=>{let r=e.rows.find(e=>e.id===t),i=e.columns.find(e=>e.key===n);return!r||!i?!1:Ae(i,r.cells[n])},Me=t=>{if(t.length===0)return 0;let n=ve.current,r=ye.current;for(let i of t){let t=e.rows.find(e=>e.id===i.rowId),a=e.columns.find(e=>e.key===i.key);if(!t||!a)continue;let o=t.cells[a.key],s=hu(a,i.text);if(!s.ok)continue;let c=s.next,l=Kl(n,r,{rowId:t.id,key:a.key,prev:o,next:c});n=l.pending,r=l.log}return je(n,r),t.length},Ne=e=>{let t=v.length>0?ke.filter(e=>v.includes(e.id)):ke,n=we.map(e=>e.key);if(t.length===0||n.length===0)return;let i=v.length>0?`selection`:`page`,a=r.replace(/[^\w.-]+/g,`_`);if(e===`csv`){let e=t.map(e=>n.map(t=>nn(Te(e,t))));Eu(`${a}-${i}.csv`,`\uFEFF${en(n,e)}`,`text/csv;charset=utf-8`)}else{let e=t.map(e=>{let t={};for(let r of n)t[r]=Te(e,r)??null;return t});Eu(`${a}-${i}.json`,`${JSON.stringify(e,null,2)}\n`,`application/json`)}M(`Exported ${t.length} row(s)`)},Pe=t=>{let n=t.target.files?.[0];t.target.value=``,n&&Se&&n.text().then(t=>{try{let n=Vt(t);if(n.length===0){M(`No rows in import file`);return}let{hits:r,unmatched:i}=Jt({records:n,rowIds:new Set(e.rows.map(e=>e.id)),writable:q});if(r.length===0){A(i===n.length?`No matching rows — import needs an id or key that exists on this page`:`Nothing writable to import`);return}let a=Me(r);A(null),M(i>0?`Imported ${a} cell(s) · ${i} row(s) unmatched`:`Imported ${a} cell(s)`)}catch(e){A(e instanceof Error?e.message:`Could not parse import file`)}})},Fe=(e,t,n)=>{let r=e.cells[t.key];if(!Ae(t,r))return;let i=hu(t,n);if(!i.ok){A(`TTL must be a duration like 30m, 1h, or empty to clear`);return}A(null);let a=i.next,o=Kl(ve.current,ye.current,{rowId:e.id,key:t.key,prev:r,next:a});je(o.pending,o.log)},Ie=(t,n,r)=>{let i=e.rows.find(e=>e.id===t),a=e.columns.find(e=>e.key===n);if(!i||!a)return;let o=i.cells[a.key];if(!Ae(a,o))return;let s=Kl(ve.current,ye.current,{rowId:i.id,key:a.key,prev:o,next:Ft(o,r)?o:r});je(s.pending,s.log)},Le=(e,t)=>{let n=Gl(e,t),r=new Map(ve.current);r.delete(n),je(r,ye.current.filter(e=>e!==n))},Re=async(e,a)=>{if(e.length===0)return!0;let o=new Map;for(let t of e){let e=o.get(t.rowId)??{};e[t.key]=t.next,o.set(t.rowId,e)}fe(!0),A(null);let s=!0;try{await Promise.all([...o.entries()].map(([e,a])=>be.mutateAsync({ref:n,...t===`sql`?{child:r,id:e}:{key:e},...i?{tenant:i}:{},...p?{asGate:p}:{},...m?{asUserId:m}:{},patch:sn(a),commit:!0}))),a?.track!==!1&&P(t=>ou(t,{updates:e,at:Date.now()})),a?.notice&&M(a.notice)}catch(e){s=!1,A(e instanceof Error?e.message:String(e))}finally{fe(!1)}return s},ze=()=>{if(W)return;if(ve.current.size>0){let e=ql(ve.current,ye.current);je(e.pending,e.log);return}let{history:e,batch:t}=su(N);t&&(P(e),Re(lu(t).updates,{track:!1,notice:`Undid ${t.updates.length} cell(s)`}))},Be=()=>{if(W||F.size>0)return;let{history:e,batch:t}=cu(N);t&&(P(e),Re(t.updates,{track:!1,notice:`Redid ${t.updates.length} cell(s)`}))},Ve=(t,n,r)=>{if(W)return;let i=e.rows.find(e=>e.id===t),a=e.columns.find(e=>e.key===n);i&&a&&Ae(a,i.cells[n])&&(R({rowId:t,key:n}),te(r===void 0?null:r),H({rowId:t,key:n}))},He=(t,n,r)=>{if(W)return;let i=e.rows.find(e=>e.id===t),a=e.columns.find(e=>e.key===n);if(i&&a){if(a.type===`boolean`){let e=hu(a,r);if(!e.ok)return;Re([{rowId:t,key:n,prev:i.cells[n],next:e.next}],{notice:e.next===!0?`Enabled ${t}`:`Disabled ${t}`});return}if(z&&Ut(z)>1){Me(Xl({range:z,rowIds:ke.map(e=>e.id),columnKeys:we.map(e=>e.key),text:r,writable:q}));return}Fe(i,a,r)}},Ue=()=>{ve.current.size!==0&&re(!0)},We=()=>{if(W||ve.current.size===0)return;let e=Jl(ve.current);Re(e,{notice:`Applied ${e.length} change(s)`}).then(e=>{e&&(je(new Map,[]),re(!1))})},Ge=()=>{W||(je(new Map,[]),re(!1))};(0,Z.useEffect)(()=>{if(!ne)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`s`&&(e.preventDefault(),We())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[ne]);let Ke=()=>{if(v.length>1)return ke.filter(e=>v.includes(e.id));let e=L?.rowId??v[0]??ke[0]?.id;if(!e)return[];let t=ke.findIndex(t=>t.id===e);return t<0?[]:ke.slice(t)},qe=e=>{if(!Se||W||e.length===0)return;let t=we.map(e=>e.key),n=[];if(z){let r=Zt(z),i=[];for(let e=r.minRow;e<=r.maxRow;e++){let t=ke[e];t&&i.push(t.id)}n=Yl({matrix:e,rowIds:i,columnKeys:t,startCol:r.minCol,writable:q})}else{let r=Ke();if(r.length===0)return;let i=L?.key,a=Math.max(0,i?we.findIndex(e=>e.key===i):0);n=Yl({matrix:e,rowIds:v.length>1?r.map(e=>e.id):r.slice(0,e.length).map(e=>e.id),columnKeys:t,startCol:a,writable:q})}let r=Me(n);r>0&&M(`Pasted ${r} cell(s)`)},Je=async()=>{let t=[];if(z){let e=Zt(z);for(let n=e.minRow;n<=e.maxRow;n++){let r=ke[n];if(!r)continue;let i=[];for(let t=e.minCol;t<=e.maxCol;t++){let e=we[t];i.push(e?It(Te(r,e.key)):``)}t.push(i)}}else{let n=v.length>0?ke.filter(e=>v.includes(e.id)):[];if(n.length>0)for(let e of n)t.push(we.map(t=>It(Te(e,t.key))));else if(L){let n=e.rows.find(e=>e.id===L.rowId);n&&t.push([It(Te(n,L.key))])}}if(t.length!==0)try{await navigator.clipboard.writeText(rn(t)),M(`Copied ${t.length} row(s)`)}catch{A(`Clipboard write blocked — allow clipboard access in the browser prompt.`)}},Ye=e=>e instanceof Node&&(ge.current===e||ge.current?.contains(e)===!0),Xe=e=>e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement,Ze=e=>e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement?e.selectionStart!==e.selectionEnd:!1,Qe=(0,Z.useMemo)(()=>we.map(e=>({key:e.key,header:(0,Q.jsx)(vu,{col:e}),sortable:!0,align:mu(e.type)?`right`:`left`,width:du(e.key)?void 0:`${fu(e.type,e.key)}px`,fill:du(e.key),sortValue:t=>{let n=Te(t,e.key);return typeof n==`number`?n:It(n)},cell:t=>{let o=F.get(Gl(t.id,e.key)),s=o?o.next:t.cells[e.key];return(0,Q.jsx)(xu,{row:t,col:e,storeRef:n,childName:r,tenant:i,masked:a,editable:Se&&e.editable&&!(e.pii&&a&&Kt(t.cells[e.key])),saving:W,dirty:o!==void 0,editing:V?.rowId===t.id&&V.key===e.key,draftSeed:V?.rowId===t.id&&V.key===e.key?ee:null,displayValue:s,onFocus:()=>R({rowId:t.id,key:e.key}),onStartEdit:()=>Ve(t.id,e.key),onEditEnd:()=>{H(null),te(null)},onCommit:n=>He(t.id,e.key,n),onInspect:()=>ie({rowId:t.id,column:e.key}),onUpgrade:t.cells.upgrade===!0?()=>{Re([{rowId:t.id,key:`upgrade`,prev:t.cells.upgrade,next:!0}],{notice:`Upgraded ${t.id}`,track:!1})}:void 0})}})),[we,n,r,i,a,W,Se,F,V,ee,Re]),$e=e=>{let t=e.ctrlKey||e.metaKey;if(t&&e.key.toLowerCase()===`f`){e.preventDefault(),ge.current?.focus();return}if(!(Ye(e.target)||Xe(e.target))){if(t&&e.key.toLowerCase()===`enter`){ve.current.size>0&&(e.preventDefault(),ne?We():Ue());return}if(t&&e.key.toLowerCase()===`s`){ve.current.size>0&&(e.preventDefault(),ne?We():Ue());return}if(t&&e.key.toLowerCase()===`z`){e.preventDefault(),e.shiftKey?Be():ze();return}if(t&&e.key.toLowerCase()===`y`){e.preventDefault(),Be();return}if(e.key===`Escape`){if(Ye(e.target)||!V&&!z)return;e.preventDefault(),H(null),te(null),B(null),e.currentTarget.focus({preventScroll:!0});return}if(!V){if(e.key===`Enter`&&z){e.preventDefault();let t=ke[z.head.row],n=we[z.head.col];t&&n&&Ve(t.id,n.key);return}if(z&&Se&&e.key.length===1&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let t=ke[z.head.row],n=we[z.head.col];t&&n&&(e.preventDefault(),Ve(t.id,n.key,e.key));return}if((e.key===`Delete`||e.key===`Backspace`)&&z&&Se){e.preventDefault();let t=Me(Xl({range:z,rowIds:ke.map(e=>e.id),columnKeys:we.map(e=>e.key),text:``,writable:q}));t>0&&M(`Cleared ${t} cell(s)`)}}}},et=e=>{Ye(e.target)||Ze(e.target)||(v.length!==0||L||z)&&(e.preventDefault(),Je())},tt=e=>{if(!Se||Ye(e.target))return;let t=e.clipboardData.getData(`text/plain`),n=Gt(t);!(v.length>1||n.length>1||(n[0]?.length??0)>1)&&e.target instanceof HTMLInputElement||n.length!==0&&(e.preventDefault(),qe(n))},nt=U?e.rows.find(e=>e.id===U.rowId):void 0,rt=U?e.columns.find(e=>e.key===U.column):void 0,it=nt&&rt?Te(nt,rt.key):void 0,at=nt!==void 0&&rt!==void 0&&!W&&Ae(rt,nt.cells[rt.key]);return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden outline-none`,"data-slot":`store-data-grid`,tabIndex:0,onKeyDown:$e,onCopy:et,onPaste:tt,children:[(0,Q.jsxs)(`div`,{className:`relative z-20 flex h-9 shrink-0 flex-nowrap items-center gap-1.5 overflow-x-auto border-b border-border/60 px-2`,children:[c,c?(0,Q.jsx)($i,{orientation:`vertical`,className:`mx-0.5 my-2 h-4 self-center`}):null,(0,Q.jsxs)(J,{label:Ee?`Search this index`:`Find in this page`,keys:ni(`F`),className:`relative min-w-40 flex-1`,children:[(0,Q.jsx)(b,{icon:ei,className:`pointer-events-none absolute top-1/2 left-2 size-3.5 -translate-y-1/2 text-muted-foreground`,"aria-hidden":!0}),(0,Q.jsx)(x,{ref:ge,value:De,onChange:e=>Ee?l.onChange(e.target.value):_(e.target.value),placeholder:Ee?`Find by title or id — or paste 1, 0, 0`:`Find in results…`,"aria-label":Ee?`Search this index`:`Find in results`,"data-slot":Ee?`index-search`:`grid-find`,className:`h-6 border-0 bg-transparent pl-7 text-[11px] shadow-none focus-visible:border-transparent focus-visible:bg-muted/40 focus-visible:ring-0 md:text-[11px] dark:bg-transparent`})]}),Ee?(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 text-[11px]`,title:`Hits to return`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`topK`}),(0,Q.jsx)(x,{type:`number`,min:1,max:100,"aria-label":`topK`,"data-slot":`index-topk`,className:`h-6 w-10 border-0 bg-transparent px-1 text-center font-mono text-[11px] tabular-nums shadow-none focus-visible:border-transparent focus-visible:bg-muted/40 focus-visible:ring-0 md:text-[11px] dark:bg-transparent`,value:l.topK,onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&t>=1&&t<=100&&l.onTopKChange(t)}})]}):null,E?(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-muted/50 px-1.5 py-0.5 font-mono text-[10px] whitespace-nowrap text-muted-foreground`,"data-slot":`sort-indicator`,children:[E.key,` `,E.direction===`desc`?`↓`:`↑`]}):null,(0,Q.jsx)($i,{orientation:`vertical`,className:`mx-0.5 my-2 ml-auto h-4 self-center`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[Se&&t===`kv`?(0,Q.jsx)(Du,{label:`Add key`,disabled:W,onClick:()=>de(!0),slot:`add-kv-key`,children:(0,Q.jsx)(b,{icon:Er,className:`size-3.5`,"aria-hidden":!0})}):null,Se?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`input`,{ref:_e,type:`file`,accept:`.csv,.tsv,.txt,.json,text/csv,application/json`,className:`sr-only`,tabIndex:-1,"aria-hidden":!0,onChange:Pe}),(0,Q.jsx)(Du,{label:`Import CSV or JSON`,disabled:W,onClick:()=>_e.current?.click(),slot:`import-rows`,children:(0,Q.jsx)(b,{icon:Di,className:`size-3.5`,"aria-hidden":!0})})]}):null,(0,Q.jsxs)(Ir,{children:[(0,Q.jsx)(J,{label:v.length>0?`Export ${v.length} selected row${v.length===1?``:`s`}`:`Export this page as CSV or JSON`,children:(0,Q.jsx)(kr,{disabled:ke.length===0,render:e=>(0,Q.jsx)(G,{...e,type:`button`,variant:`ghost`,size:`icon-xs`,disabled:ke.length===0,"aria-label":`Export rows`,"data-slot":`export-rows`,children:(0,Q.jsx)(b,{icon:hn,className:`size-3.5`,"aria-hidden":!0})})})}),(0,Q.jsx)(Pr,{align:`end`,className:`w-40`,children:(0,Q.jsxs)(Ar,{children:[(0,Q.jsx)(Nr,{children:v.length>0?`Export selection`:`Export page`}),(0,Q.jsx)(Dr,{onClick:()=>Ne(`csv`),children:`CSV`}),(0,Q.jsx)(Dr,{onClick:()=>Ne(`json`),children:`JSON`})]})})]}),Se?(0,Q.jsxs)(Q.Fragment,{children:[F.size>0?(0,Q.jsx)(Du,{label:`Discard uncommitted changes`,disabled:W,onClick:Ge,slot:`discard-changes`,children:(0,Q.jsx)(b,{icon:ae,className:`size-3.5`,"aria-hidden":!0})}):null,(0,Q.jsx)(J,{label:F.size>0?`Review ${F.size} uncommitted change${F.size===1?``:`s`}`:`No uncommitted changes`,children:(0,Q.jsxs)(G,{type:`button`,variant:F.size>0?`outline`:`ghost`,size:`xs`,disabled:F.size===0||W,onClick:Ue,"aria-label":F.size>0?`Review ${F.size} uncommitted changes`:`Review changes`,"data-slot":`apply-changes`,className:F.size>0?`relative h-6 gap-1 overflow-visible border-amber-500/25 bg-amber-500/10 text-amber-800 hover:bg-amber-500/15 dark:text-amber-300`:`h-6`,children:[F.size>0?(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`oke-changes-border-run pointer-events-none absolute inset-0`}):null,(0,Q.jsx)(b,{icon:D,className:`relative size-3.5`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`relative`,children:`Changes`}),F.size>0?(0,Q.jsx)(`span`,{className:`relative min-w-3.5 rounded-full border border-amber-500/25 bg-amber-500/10 px-1 font-mono text-[9px] leading-3`,children:F.size}):null]})})]}):null,(0,Q.jsx)(Du,{label:`Undo edit`,keys:ni(`Z`),disabled:F.size===0&&N.past.length===0||W,onClick:ze,slot:`undo-edit`,children:(0,Q.jsx)(b,{icon:Vi,className:`size-3.5`,"aria-hidden":!0})}),(0,Q.jsx)(Du,{label:`Redo edit`,keys:oi(`Z`),disabled:N.future.length===0||W||F.size>0,onClick:Be,slot:`redo-edit`,children:(0,Q.jsx)(b,{icon:Li,className:`size-3.5`,"aria-hidden":!0})}),(0,Q.jsxs)(Ir,{children:[(0,Q.jsx)(J,{label:`Row height and columns`,children:(0,Q.jsx)(kr,{render:e=>(0,Q.jsx)(G,{...e,type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`View options`,"data-slot":`view-menu`,children:(0,Q.jsx)(b,{icon:li,className:`size-3.5`,"aria-hidden":!0})})})}),(0,Q.jsxs)(Pr,{align:`end`,className:`w-48`,children:[(0,Q.jsxs)(Ar,{children:[(0,Q.jsx)(Nr,{children:`Row height`}),(0,Q.jsxs)(Fr,{value:w,onValueChange:e=>T(e),children:[(0,Q.jsx)(Or,{value:`short`,"data-slot":`row-height-menu`,children:`Short`}),(0,Q.jsx)(Or,{value:`medium`,children:`Medium`}),(0,Q.jsx)(Or,{value:`tall`,children:`Tall`}),(0,Q.jsx)(Or,{value:`extra-tall`,children:`Extra tall`})]})]}),(0,Q.jsx)(jr,{}),(0,Q.jsxs)(Ar,{children:[(0,Q.jsx)(Nr,{children:`Columns`}),e.columns.map(e=>{let t=!S.has(e.key),n=t&&we.length===1;return(0,Q.jsx)(Mr,{checked:t,disabled:n,onCheckedChange:t=>{C(n=>{let r=new Set(n);return t?r.delete(e.key):r.add(e.key),r})},children:(0,Q.jsx)(`span`,{className:`font-mono text-[11px]`,children:e.label??e.key})},e.key)})]})]})]}),e.editable&&f?(0,Q.jsx)(J,{label:K.length>0?`Delete ${K.length} selected row${K.length===1?``:`s`}`:`Select rows to delete`,children:(0,Q.jsxs)(G,{type:`button`,variant:`destructive`,size:K.length>0?`xs`:`icon-xs`,className:K.length>0?`ml-1 h-6`:`ml-1`,disabled:K.length===0,onClick:()=>f(K),"aria-label":K.length>0?`Delete ${K.length} selected rows`:`Delete selected rows`,"data-slot":`delete-selected`,children:[(0,Q.jsx)(b,{icon:pn,className:`size-3.5`,"aria-hidden":!0}),K.length>0?K.length:null]})}):null]})]}),(0,Q.jsx)(`div`,{ref:he,className:`min-h-0 flex-1`,"data-slot":`grid-viewport`,"aria-label":`${r} rows`,children:(0,Q.jsx)(Pl,{data:ke,columns:Qe,getRowId:e=>e.id,selectable:xe,selectedRowIds:v,onSelectionChange:y,sort:E,onSortChange:O,resizable:!0,reorderable:!0,onCellEdit:Se?He:void 0,onDeleteRow:e.editable&&f?t=>{let n=e.rows.find(e=>e.id===t);n&&f([n])}:void 0,onRowContextMenu:e=>{se(e),le(!0)},onViewportContextMenu:h,cellRange:z,onCellRangeChange:Se?e=>{if(B(e),!e)return;let t=ke[e.head.row],n=we[e.head.col];t&&n&&R({rowId:t.id,key:n.key});let r=he.current?.closest(`[data-slot='store-data-grid']`);r instanceof HTMLElement&&!(document.activeElement instanceof HTMLInputElement)&&r.focus({preventScroll:!0})}:void 0,onCellActivate:Se?(e,t)=>{let n=ke[e],r=we[t];n&&r&&Ve(n.id,r.key)}:void 0,rowHeight:Ce,height:pe,emptyState:Ee&&De.trim()?`No hits — try a different query or raise topK.`:g.trim()?`No matches on this page — increase Limit to search more rows.`:`No rows.`,className:`h-full rounded-none border-0`})}),Se?(0,Q.jsx)(ru,{open:ne,onOpenChange:re,pending:F,table:r,facet:t===`kv`?`kv`:`sql`,saving:W,error:k,onUndoCell:Le,onClearAll:Ge,onCommitAll:We}):null,Se&&t===`sql`&&d?(0,Q.jsx)(Hl,{open:u,onOpenChange:d,storeRef:n,childName:r,tenant:i,columns:e.columns,asGate:p,asUserId:m}):null,Se&&t===`kv`?(0,Q.jsx)(Vl,{open:ue,onOpenChange:de,storeRef:n,childName:r,tenant:i,existingKeys:e.rows.map(e=>e.id)}):null,(0,Q.jsx)(Rl,{open:ce,onOpenChange:le,model:e,row:oe?e.rows.find(e=>e.id===oe.id)??oe:null,facet:t,storeRef:n,childName:r,tenant:i,masked:a,asGate:p,asUserId:m,onDeleteRow:f?e=>{le(!1),f([e])}:void 0}),U&&nt&&rt?(0,Q.jsx)(un,{open:!0,onOpenChange:e=>{e||ie(null)},rowId:U.rowId,column:U.column,storeRef:n,value:it,originalValue:nt.cells[rt.key],editable:at,onChange:at?e=>Ie(U.rowId,U.column,e):void 0}):null,(0,Q.jsxs)(`div`,{className:`flex h-7 shrink-0 items-center gap-2 border-t border-border/60 px-2.5 font-mono text-[10px] tabular-nums text-muted-foreground`,"data-slot":`grid-status`,children:[(0,Q.jsxs)(`span`,{children:[Oe.length,Oe.length===e.rows.length?``:` of ${e.rows.length}`,` `,e.rows.length===1?`row`:`rows`]}),o?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`text-border`,children:`·`}),(0,Q.jsx)(`span`,{children:o})]}):null,t===`sql`&&a?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`text-border`,children:`·`}),(0,Q.jsx)(`span`,{className:`text-sky-700 dark:text-sky-400`,children:`PII masked`})]}):t===`sql`&&e.columns.some(e=>e.pii)?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`text-border`,children:`·`}),(0,Q.jsx)(`span`,{className:`text-amber-800 dark:text-amber-300`,children:`PII visible`})]}):null,F.size>0?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`text-border`,children:`·`}),(0,Q.jsxs)(`span`,{className:`text-amber-800 dark:text-amber-300`,role:`status`,"data-slot":`pending-count`,children:[F.size,` uncommitted`]})]}):null,W?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`text-border`,children:`·`}),(0,Q.jsx)(`span`,{role:`status`,"data-slot":`cell-edit-saving`,children:`Saving…`})]}):null,j?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`text-border`,children:`·`}),(0,Q.jsx)(`span`,{role:`status`,"data-slot":`grid-notice`,children:j})]}):null,k?(0,Q.jsx)(`span`,{className:`text-destructive`,role:`alert`,"data-slot":`cell-edit-error`,children:k}):null,Ee&&De.trim()?(0,Q.jsxs)(`span`,{className:`ml-auto truncate`,role:`status`,"data-slot":`find-scope`,children:[`Index query · topK `,l.topK]}):g.trim()?(0,Q.jsxs)(`span`,{className:`ml-auto truncate`,role:`status`,"data-slot":`find-scope`,children:[`This page only · limit `,s]}):K.length>0?(0,Q.jsxs)(`span`,{className:`ml-auto`,children:[K.length,` row`,K.length===1?``:`s`,` checked`]}):(0,Q.jsx)(`span`,{className:`ml-auto opacity-60`,children:`Click to select · two-finger click opens sheet · drag a range · type to edit`})]})]})}function vu({col:e}){return(0,Q.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1`,title:e.description??e.key,children:[e.type===`string`?null:(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[9px] text-muted-foreground/50`,children:pu(e.type)}),e.primaryKey?(0,Q.jsx)(b,{icon:Re,className:`size-3 shrink-0 text-amber-600 dark:text-amber-400`,"aria-label":`Primary key`}):null,e.pii?(0,Q.jsx)(b,{icon:Ve,className:`size-3 shrink-0 text-sky-600 dark:text-sky-400`,"aria-label":`PII column`}):null,(0,Q.jsx)(`span`,{className:`truncate font-mono text-[11px]`,children:e.label??e.key})]})}var yu=`text-[#9a5b12] dark:text-[#e8c48a]`,bu=`absolute inset-0 flex min-w-0 items-center overflow-hidden px-4 font-mono text-[11px]`;function xu({row:e,col:t,storeRef:n,childName:r,tenant:i,masked:a,editable:o,saving:s,dirty:c,editing:l,draftSeed:u,displayValue:d,onFocus:f,onStartEdit:p,onEditEnd:m,onCommit:h,onInspect:g,onUpgrade:_}){let v=d,y=mu(t.type),b=v==null;if(t.pii&&a&&Kt(e.cells[t.key])&&!c)return(0,Q.jsx)(`span`,{className:bu,children:(0,Q.jsx)(Il,{refName:n,child:r,...i?{tenant:i}:{},rowId:e.id,column:t.key,maskedValue:e.cells[t.key]})});if(t.type===`boolean`){let t=d===!0;return(0,Q.jsx)(`span`,{className:S(bu,`justify-center`,c&&yu),"data-slot":o?`cell-display`:void 0,"data-pending":c?`true`:void 0,onClick:e=>e.stopPropagation(),children:(0,Q.jsx)(Ra,{size:`sm`,checked:t,disabled:!o||s,ariaLabel:t?`Disable ${e.id}`:`Enable ${e.id}`,onCheckedChange:e=>{o&&!s&&h(e?`true`:`false`)}})})}if(o&&l)return(0,Q.jsx)(`span`,{className:S(bu,c&&yu,y&&`tabular-nums`),"data-slot":`cell-editor`,"data-pending":c?`true`:void 0,children:(0,Q.jsx)(At,{value:u??gu(t,v),label:`Edit ${t.key}`,dirty:c,autoFocus:!0,placeholder:t.format===`ttl`?`30m`:void 0,onFocus:f,onIdle:m,onChange:e=>{s||h(e)},className:S(`h-full min-w-0 font-mono text-[11px]`,y&&`text-right tabular-nums`,Ht(v)&&`text-right`)})});let x=ln(v)!==null,C=Tt(t,v);return(0,Q.jsxs)(`span`,{role:o?`button`:void 0,tabIndex:o?-1:void 0,"data-slot":o?`cell-display`:void 0,"data-pending":c?`true`:void 0,className:S(bu,`group/cell gap-1`,o&&`cursor-cell`,c&&yu,y&&`tabular-nums`,b&&!c&&`text-muted-foreground/40`,t.type===`json`&&!b&&!c&&`text-muted-foreground`),title:t.format===`name-key`&&typeof e.cells.url==`string`?e.cells.url:C,onDoubleClick:o?e=>{e.stopPropagation(),s||p()}:void 0,children:[t.format===`source`?(0,Q.jsx)(wu,{value:C}):t.format===`name-key`?(0,Q.jsx)(Su,{title:C,url:typeof e.cells.url==`string`?e.cells.url:null}):(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,dir:Ht(v)?`rtl`:`ltr`,children:C}),t.format===`name-key`?(0,Q.jsx)(Cu,{name:typeof e.cells.name==`string`?e.cells.name:``,version:e.cells.version==null?``:String(e.cells.version),available:e.cells.available==null?``:String(e.cells.available),upgradeable:e.cells.upgrade===!0,saving:s,onUpgrade:_}):null,x?(0,Q.jsx)(Tu,{onInspect:g}):null]})}function Su({title:e,url:t}){return t?(0,Q.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:`group/ext-link inline-flex min-w-0 flex-1 items-center gap-1 truncate text-foreground underline-offset-2 hover:underline`,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:[(0,Q.jsx)(`span`,{className:`truncate`,children:e}),(0,Q.jsx)(b,{icon:Mi,className:`size-3 shrink-0 text-muted-foreground/50 group-hover/ext-link:text-muted-foreground`,"aria-hidden":!0})]}):(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e})}function Cu({name:e,version:t,available:n,upgradeable:r,saving:i,onUpgrade:a}){return!e&&!t?null:(0,Q.jsxs)(`span`,{className:`inline-flex h-5 shrink-0 items-stretch overflow-hidden rounded-md border border-border/60 bg-muted/25 font-mono text-[9px] leading-none`,children:[e?(0,Q.jsx)(`span`,{className:`inline-flex items-center px-1.5 text-muted-foreground`,children:e}):null,e&&t?(0,Q.jsx)(`span`,{className:`w-px self-stretch bg-border/60`,"aria-hidden":!0}):null,t?(0,Q.jsxs)(`span`,{className:`inline-flex items-center bg-amber-500/10 px-1.5 font-semibold tabular-nums text-amber-800 dark:text-amber-300`,children:[`v`,t]}):null,r&&n&&a?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`w-px self-stretch bg-border/60`,"aria-hidden":!0}),(0,Q.jsx)(`button`,{type:`button`,disabled:i,title:`Upgrade to ${n}`,"aria-label":`Upgrade ${e} from ${t} to ${n}`,className:`inline-flex items-center bg-emerald-500/15 px-1.5 font-semibold tracking-wide text-emerald-800 uppercase hover:bg-emerald-500/25 disabled:opacity-50 dark:text-emerald-300`,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),i||a()},children:`Upgrade`})]}):null]})}function wu({value:e}){let t=e===`library`;return(0,Q.jsxs)(Qe,{variant:`outline`,className:S(`h-5 gap-1 rounded-md px-1.5 font-mono text-[9px] font-semibold tracking-wide uppercase`,t?`border-sky-500/35 bg-sky-500/10 text-sky-800 dark:text-sky-300`:`border-border/60 bg-muted/40 text-muted-foreground`),children:[(0,Q.jsx)(b,{icon:t?Ii:Xe,className:`size-3`,"aria-hidden":!0}),t?`Library`:`Builtin`]})}function Tu({onInspect:e}){return(0,Q.jsxs)(w,{children:[(0,Q.jsx)(O,{render:t=>(0,Q.jsx)(`button`,{...t,type:`button`,"aria-label":`Open as table`,"data-slot":`json-inspect`,className:S(`flex size-5 shrink-0 items-center justify-center rounded-sm text-muted-foreground/40`,`group-hover/cell:text-muted-foreground hover:bg-muted hover:text-foreground`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50`),onPointerDown:e=>{e.stopPropagation(),t.onPointerDown?.(e)},onDoubleClick:e=>e.stopPropagation(),onClick:n=>{n.stopPropagation(),t.onClick?.(n),e()},children:(0,Q.jsx)(b,{icon:ct,className:`size-3`,"aria-hidden":!0})})}),(0,Q.jsx)(T,{side:`left`,className:`text-[11px]`,children:`Open as table`})]})}function Eu(e,t,n){let r=new Blob([t],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=e,a.click(),URL.revokeObjectURL(i)}function Du({label:e,keys:t,disabled:n,onClick:r,slot:i,children:a}){return(0,Q.jsxs)(w,{children:[(0,Q.jsx)(O,{render:t=>(0,Q.jsx)(G,{...t,type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":e,disabled:n,onClick:e=>{t.onClick?.(e),r()},"data-slot":i,children:a})}),(0,Q.jsxs)(T,{side:`bottom`,className:`text-[11px]`,children:[e,t&&t.length>0?(0,Q.jsx)(ve,{keys:t}):null]})]})}var Ou=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/;function ku(e){let t=e.trim();if(!t)return null;let n=t.split(/[\s,]+/).filter(e=>e.length>0),r=[];for(let e of n){let t=Number(e);if(!Number.isFinite(t))return null;r.push(t)}return r.length>0?r:null}function Au(e){let t=e.trim().split(/[\s,]+/).filter(e=>e.length>0);return t.length>=2&&t.every(e=>Ou.test(e))}function ju(e){let t=e.trim();if(t.length===0)return{kind:`empty`};if(Au(t)){let e=ku(t);if(e&&e.length>=2)return{kind:`vector`,vector:e}}return{kind:`text`,q:t}}function Mu({manifest:e,value:t,onChange:n}){let{asGate:r,asUserId:i}=t,a=wn(!0),o=Zn(),s=(0,Z.useMemo)(()=>$n(br(e),a.data??null),[e,a.data]),c=(0,Z.useMemo)(()=>Jn(s),[s]),l=(0,Z.useMemo)(()=>vr(o.data??[],s),[o.data,s]),u=s.gates.find(e=>e.kind===`public`)?.description??`Intentionally unauthenticated.`,d=mr(r),f=r!==null,[p,m]=(0,Z.useState)(i?`user`:`policy`),h=c.find(e=>e.id===r)??null,g=l.find(e=>e.id===i&&e.gate===r)??null,_=c.length>0||l.length>0,v=e=>{if(e===`operator`){n({asGate:null,asUserId:null});return}if(e===`public`){n({asGate:`public`,asUserId:null});return}if(d===`as`)return;let t=h?.id??c[0]?.id??l[0]?.gate??null;if(t!==null){if(l[0]&&t===l[0].gate&&c.length===0){m(`user`),n({asGate:l[0].gate,asUserId:l[0].id});return}m(`policy`),n({asGate:t,asUserId:null})}};return(0,Q.jsxs)(Ir,{children:[(0,Q.jsx)(kr,{render:e=>(0,Q.jsxs)(G,{...e,type:`button`,variant:`ghost`,size:`sm`,className:S(`h-full max-w-44 min-w-0 rounded-none px-2 text-[11px]`,f&&`text-sky-800 dark:text-sky-300`),"aria-label":f?`View data as Gate ${r}`:`View data as Operator (default)`,"data-slot":`store-query-gate`,children:[(0,Q.jsx)(b,{icon:Ke.gate.icon,"data-icon":`inline-start`,className:`size-3.5`}),(0,Q.jsx)(`span`,{className:`truncate`,children:ir(r,i,g?.label)})]})}),(0,Q.jsxs)(Pr,{align:`start`,className:`w-80 overflow-hidden p-0`,children:[(0,Q.jsx)(lr,{children:`View as`}),(0,Q.jsxs)(Gn,{label:`View data as`,children:[(0,Q.jsx)(fr,{mode:`operator`,title:`Operator`,caption:`Bypass`,selected:d===`operator`,onSelect:()=>v(`operator`)}),(0,Q.jsx)(fr,{mode:`public`,title:`Public`,caption:`Anonymous`,selected:d===`public`,onSelect:()=>v(`public`)}),(0,Q.jsx)(fr,{mode:`as`,title:`As`,caption:g?g.label:h?.label??`User / policy`,selected:d===`as`,disabled:!_,onSelect:()=>v(`as`)})]}),d===`operator`?(0,Q.jsxs)(er,{title:`Operator`,badge:`Default`,children:[`Bypasses RLS. No `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`oke.gate()`}),` stamp.`]}):null,d===`public`?(0,Q.jsxs)(er,{title:`Public`,children:[u,` Sets `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`oke.gate()`}),` to`,` `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`public`}),`.`]}):null,d===`as`?(0,Q.jsx)(sr,{tab:p,onTabChange:m,policies:c,users:l,asGate:r,asUserId:g?.id??null,onSelectPolicy:e=>{m(`policy`),n({asGate:e.id,asUserId:null})},onSelectUser:e=>{m(`user`),n({asGate:e.gate,asUserId:e.id})}}):null]})]})}function Nu(e){return[...new Set(e)].sort((e,t)=>e.localeCompare(t))}function Pu({child:e}){let t=Nu(e.writers),n=Nu(e.readers);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,"data-slot":`touched-by-lists`,children:[(0,Q.jsx)(Fu,{title:`Writers`,ids:t,empty:`No Manifest flow declares writes for this resource.`}),(0,Q.jsx)(Fu,{title:`Readers`,ids:n,empty:`No Manifest flow declares reads for this resource.`})]})}function Fu({title:e,ids:t,empty:n}){return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,"data-slot":`touched-by-list`,"data-kind":e.toLowerCase(),children:[(0,Q.jsx)(`h3`,{className:`text-[10px] font-semibold tracking-[0.14em] text-muted-foreground uppercase`,children:e}),t.length===0?(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:n}):(0,Q.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:t.map(e=>(0,Q.jsxs)(`li`,{className:`flex flex-wrap items-center gap-2 font-mono text-xs text-foreground/90`,children:[(0,Q.jsx)(`span`,{children:e}),(0,Q.jsx)(ui,{to:`/flows`,search:{flow:e},className:`text-[10px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline`,children:`Flows`}),(0,Q.jsx)(ui,{to:`/overview`,search:{flow:e},className:`text-[10px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline`,children:`Graph`})]},e))})]})}var Iu=[10,25,50,100,250,500],Lu=280;function Ru(e,t){let[n,r]=(0,Z.useState)(e);return(0,Z.useEffect)(()=>{let n=window.setTimeout(()=>r(e),t);return()=>window.clearTimeout(n)},[e,t]),n}function zu({store:e,child:t,manifest:n,tenancyDeclared:r,tenants:i,tenant:a,onTenantChange:o,piiMasked:s=!0}){let[c,l]=(0,Z.useState)(500),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(5),[m,h]=(0,Z.useState)(null),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(!1),[x,S]=(0,Z.useState)(!1),[C,E]=(0,Z.useState)(!1),[D,k]=(0,Z.useState)(!1),[A,j]=(0,Z.useState)(!1),[M,N]=(0,Z.useState)({asGate:null,asUserId:null}),P=Ru(u,Lu),F=(0,Z.useMemo)(()=>ju(P),[P]),I=!r||a!==null&&a.length>0,L=(0,Z.useMemo)(()=>I?{ref:e.ref,child:t.name,...a?{tenant:a}:{},limit:c,...e.facet===`index`&&F.kind===`vector`?{vector:F.vector,topK:f}:{},...e.facet===`index`&&F.kind===`text`?{q:F.q,topK:f}:{},...e.facet===`sql`&&!s?{revealPii:!0}:{},...e.facet===`sql`&&!Kn(t)&&M.asGate?{asGate:M.asGate}:{},...e.facet===`sql`&&!Kn(t)&&M.asUserId?{asUserId:M.asUserId}:{}}:null,[e.ref,e.facet,t,a,I,c,F,f,s,M]),R=cr(L,I),z=Ia(),B=pr(t),V=B===`extension`,H=B===`policy`,ee=B===`function`,te=B===`index`,ne=B===`trigger`,re=Kn(t)&&!V,U=e.ref===`sql:oke_console`||re,{columnTypes:ie,primaryKeyColumns:ae}=(0,Z.useMemo)(()=>{let r=n?.stores?.[e.name]?.tables?.[t.name],i={},a=[];for(let[e,t]of Object.entries(r?.columns??{}))if(t&&typeof t==`object`){let n=t.type;(n===`text`||n===`integer`)&&(i[e]=n),t.primaryKey===!0&&a.push(e)}if(Object.keys(i).length===0)for(let e of Object.keys(t.columnDescriptions))i[e]=`text`;return a.length===0&&`id`in i&&a.push(`id`),{columnTypes:i,primaryKeyColumns:a}},[n,e.name,t]),oe=(0,Z.useMemo)(()=>{if(!R.data)return null;let n=cn({facet:e.facet,data:R.data,piiColumns:t.piiColumns,columnTypes:ie,columnDescriptions:t.columnDescriptions,primaryKeyColumns:ae});return H&&e.ref!==`sql:oke_console`?{...n,editable:!0,columns:n.columns.filter(e=>e.key!==`id`&&e.key!==`schema`).map(e=>({...e,editable:e.key===`roles`||e.key===`using`||e.key===`with_check`||e.key===`command`||e.key===`permissive`,...e.key===`origin`?{label:`Origin`}:{},...e.key===`code`?{label:`Code`}:{}}))}:H?{...n,editable:!1,columns:n.columns.filter(e=>e.key!==`id`&&e.key!==`schema`).map(e=>({...e,editable:!1}))}:V&&e.ref!==`sql:oke_console`?{...n,editable:!0,columns:n.columns.filter(e=>e.key!==`name`&&e.key!==`version`&&e.key!==`available`&&e.key!==`upgrade`&&e.key!==`url`).map(e=>({...e,type:e.key===`enabled`?`boolean`:e.type,editable:e.key===`enabled`,...e.key===`title`?{label:`Name`,format:`name-key`}:{},...e.key===`source`?{label:`Source`,format:`source`}:{}}))}:U?{...n,editable:!1,columns:n.columns.map(e=>({...e,editable:!1}))}:n},[R.data,e.facet,e.ref,t,ie,ae,U,V,H]),se=n=>{if(!m)return;let r=m.map(e=>e.id);z.mutate({ref:e.ref,...e.facet===`sql`?{child:t.name}:{},...a?{tenant:a}:{},...oe?.deleteKind===`keys`?{keys:r}:{ids:r},confirmation:n.confirmation,reason:n.reason},{onSuccess:()=>{h(null)}})},ce=new Set(t.writers).size,le=new Set(t.readers).size,ue=I&&oe!==null,de=(0,Q.jsxs)(Q.Fragment,{children:[e.facet===`sql`&&!Kn(t)?(0,Q.jsx)(Mu,{manifest:n,value:M,onChange:N}):null,(0,Q.jsxs)(w,{children:[(0,Q.jsx)(O,{render:e=>(0,Q.jsx)(G,{...e,type:`button`,variant:`ghost`,size:`icon-xs`,onClick:()=>void R.refetch(),disabled:R.isFetching,"aria-label":`Refresh`,"data-slot":`browse-refresh`,children:(0,Q.jsx)(b,{icon:mt,className:R.isFetching?`size-3.5 animate-spin`:`size-3.5`,"aria-hidden":!0})})}),(0,Q.jsx)(T,{side:`bottom`,className:`text-[11px]`,children:`Reload from the store`})]}),e.facet===`sql`&&!U&&!Kn(t)?(0,Q.jsx)(J,{label:`Insert a row`,children:(0,Q.jsxs)(G,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px] text-muted-foreground`,"data-slot":`add-sql-row`,onClick:()=>j(!0),children:[(0,Q.jsx)(b,{icon:Er,className:`size-3.5`,"aria-hidden":!0}),`Insert data`]})}):null,te&&e.ref!==`sql:oke_console`?(0,Q.jsx)(J,{label:`CREATE INDEX`,children:(0,Q.jsxs)(G,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px] text-muted-foreground`,"data-slot":`sql-create-index`,onClick:()=>E(!0),children:[(0,Q.jsx)(b,{icon:Re,className:`size-3.5`,"aria-hidden":!0}),`Create index`]})}):null,ee&&e.ref!==`sql:oke_console`?(0,Q.jsx)(J,{label:`CREATE FUNCTION`,children:(0,Q.jsxs)(G,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px] text-muted-foreground`,"data-slot":`sql-create-function`,onClick:()=>S(!0),children:[(0,Q.jsx)(b,{icon:Ai,className:`size-3.5`,"aria-hidden":!0}),`New function`]})}):null,ne&&e.ref!==`sql:oke_console`?(0,Q.jsx)(J,{label:`CREATE TRIGGER`,children:(0,Q.jsxs)(G,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px] text-muted-foreground`,"data-slot":`sql-create-trigger`,onClick:()=>k(!0),children:[(0,Q.jsx)(b,{icon:Hi,className:`size-3.5`,"aria-hidden":!0}),`New trigger`]})}):null,H&&e.ref!==`sql:oke_console`?(0,Q.jsx)(J,{label:`CREATE POLICY on a table`,children:(0,Q.jsxs)(G,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px] text-muted-foreground`,"data-slot":`rls-create-policy`,onClick:()=>y(!0),children:[(0,Q.jsx)(b,{icon:Ve,className:`size-3.5`,"aria-hidden":!0}),`Create policy`]})}):null,V&&e.ref!==`sql:oke_console`?(0,Q.jsx)(J,{label:`Add Timescale, PostGIS, pg_cron…`,children:(0,Q.jsxs)(G,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px] text-muted-foreground`,"data-slot":`extension-library`,onClick:()=>_(!0),children:[(0,Q.jsx)(b,{icon:Ii,className:`size-3.5`,"aria-hidden":!0}),`Library`]})}):null,(0,Q.jsxs)(Ir,{children:[(0,Q.jsx)(J,{label:`${ce} writer${ce===1?``:`s`} · ${le} reader${le===1?``:`s`}`,children:(0,Q.jsx)(kr,{render:e=>(0,Q.jsxs)(G,{...e,type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1.5 px-1.5 text-[11px] text-muted-foreground`,"data-slot":`browse-touched-by`,"aria-label":`${ce} writers, ${le} readers`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(b,{icon:fn,className:`size-3`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:ce})]}),(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`h-3 w-px bg-border/60`}),(0,Q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(b,{icon:li,className:`size-3`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:le})]})]})})}),(0,Q.jsx)(Pr,{align:`start`,className:`w-72 p-3`,children:(0,Q.jsx)(Pu,{child:t})})]}),r?(0,Q.jsx)(J,{label:`Tenant for this browse`,children:(0,Q.jsxs)(`div`,{className:`relative flex items-center`,children:[(0,Q.jsx)(b,{icon:mn,className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground`,"aria-hidden":!0}),(0,Q.jsxs)(`select`,{"aria-label":`Tenant`,"data-slot":`store-tenant`,className:`h-6 min-w-[9rem] appearance-none rounded-md border border-border/70 bg-transparent pr-6 pl-7 font-mono text-[11px] text-foreground outline-none transition-colors focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/40`,value:a??``,onChange:e=>o(e.target.value.length>0?e.target.value:null),children:[(0,Q.jsx)(`option`,{value:``,children:`Select tenant…`}),i.map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e))]}),(0,Q.jsx)(b,{icon:ar,className:`pointer-events-none absolute right-1.5 size-3.5 text-muted-foreground`,"aria-hidden":!0})]})}):null,(0,Q.jsx)(J,{label:`Rows to fetch`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Rows`}),(0,Q.jsxs)(ka,{value:String(c),onValueChange:e=>{let t=Number(e);Number.isFinite(t)&&l(t)},className:`z-30 w-14`,children:[(0,Q.jsx)(Aa,{"aria-label":`Browse limit`,className:`h-6 gap-0.5 border-0 bg-transparent px-1.5 py-0 text-[11px] tabular-nums shadow-none hover:border-transparent hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:ring-0`,children:(0,Q.jsx)(ja,{})}),(0,Q.jsx)(Ma,{className:`min-w-16`,children:Iu.map(e=>(0,Q.jsx)(Na,{value:String(e),className:`text-[11px] tabular-nums`,children:e},e))})]})]})})]});return(0,Q.jsxs)(`section`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,"data-slot":`browse-section`,"aria-label":`Browse`,children:[e.facet===`sql`&&R.data?.masked?(0,Q.jsx)(`p`,{className:`sr-only`,role:`status`,"data-slot":`browse-mask-note`,children:`PII columns masked. Toggle the PII chip to show all cleartext, or reveal a cell. Editing a masked cell requires reveal first.`}):null,e.facet===`sql`&&R.data&&!R.data.masked&&t.piiColumns.length>0?(0,Q.jsx)(`p`,{className:`sr-only`,role:`status`,"data-slot":`browse-unmask-note`,children:`PII columns visible. Toggle the PII chip to remask.`}):null,e.facet===`kv`||e.facet===`files`||e.facet===`index`?(0,Q.jsx)(`p`,{className:`sr-only`,role:`status`,"data-slot":`browse-non-sql-pii`,children:`Not PII-classified — values are shown as returned by the store.`}):null,I?R.isLoading&&!R.data?(0,Q.jsx)(Vu,{}):R.isError?(0,Q.jsx)(Bu,{children:(0,Q.jsx)(Be,{role:`alert`,"data-slot":`browse-error`,children:(0,Q.jsxs)(Ie,{children:[(0,Q.jsx)(Le,{variant:`icon`,className:`bg-destructive/10 text-destructive`,children:(0,Q.jsx)(b,{icon:nt,"aria-hidden":!0})}),(0,Q.jsx)(We,{children:`Couldn’t load rows`}),(0,Q.jsx)(qe,{children:R.error.message})]})})}):e.facet===`files`&&R.data?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,Q.jsx)(Fc,{store:e,child:t,tenant:a,data:R.data,fetching:R.isFetching,onRefresh:()=>void R.refetch()})}):oe?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,Q.jsx)(_u,{model:oe,facet:e.facet,storeRef:e.ref,childName:t.name,tenant:a,masked:R.data?.masked??!1,routedRole:R.data?.routedRole,limit:c,toolbarExtras:ue?de:void 0,indexSearch:e.facet===`index`?{value:u,onChange:d,topK:f,onTopKChange:p}:void 0,insertOpen:A,onInsertOpenChange:j,asGate:M.asGate,asUserId:M.asUserId,onDeleteRows:U||V?void 0:e=>h(e),onViewportContextMenu:e.ref===`sql:oke_console`?void 0:H?()=>y(!0):ee?()=>S(!0):te?()=>E(!0):ne?()=>k(!0):e.facet===`sql`&&!Kn(t)?()=>j(!0):void 0})}):null:(0,Q.jsx)(Bu,{children:(0,Q.jsx)(Be,{role:`status`,"data-slot":`browse-gate`,children:(0,Q.jsxs)(Ie,{children:[(0,Q.jsx)(Le,{variant:`icon`,children:(0,Q.jsx)(b,{icon:mn,"aria-hidden":!0})}),(0,Q.jsx)(We,{children:`Select a tenant`}),(0,Q.jsx)(qe,{children:`Tenancy is a compliance boundary, not a display filter — choose a tenant to browse its data.`})]})})}),V&&e.ref!==`sql:oke_console`?(0,Q.jsx)(go,{open:g,onOpenChange:_,storeRef:e.ref,presentNames:(oe?.rows??[]).map(e=>e.id)}):null,te&&e.ref!==`sql:oke_console`?(0,Q.jsx)(xs,{open:C,onOpenChange:E,storeRef:e.ref,tables:tr(e.children).tables.map(e=>e.name)}):null,ee&&e.ref!==`sql:oke_console`?(0,Q.jsx)(ps,{open:x,onOpenChange:S,storeRef:e.ref}):null,ne&&e.ref!==`sql:oke_console`?(0,Q.jsx)(Ps,{open:D,onOpenChange:k,storeRef:e.ref,tables:tr(e.children).tables.map(e=>e.name)}):null,H&&e.ref!==`sql:oke_console`?(0,Q.jsx)(Lo,{open:v,onOpenChange:y,storeRef:e.ref,tables:tr(e.children).tables.map(e=>e.name),manifest:n}):null,(0,Q.jsx)(Fs,{open:m!==null,onOpenChange:e=>{e||h(null)},phrase:`DELETE`,title:`Delete ${m?.length??0} ${m?.length===1?`row`:`rows`}`,description:`Permanently delete ${m?.length??0} item(s) from ${e.ref}${e.facet===`sql`?`/${t.name}`:``}. This is not a flow execution.`,pending:z.isPending,error:z.isError?z.error.message:null,onConfirm:se})]})}function Bu({children:e}){return(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center px-6`,children:e})}function Vu(){return(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,role:`status`,"data-slot":`browse-loading`,"aria-label":`Loading rows`,children:[(0,Q.jsxs)(`div`,{className:`flex h-9 shrink-0 items-center gap-2 border-b border-border/60 px-2`,children:[(0,Q.jsx)(si,{className:`h-5 w-8`}),(0,Q.jsx)(si,{className:`h-5 w-16`}),(0,Q.jsx)(si,{className:`h-5 w-14`}),(0,Q.jsx)(si,{className:`ml-auto h-5 w-48`}),(0,Q.jsx)(si,{className:`h-5 w-6`}),(0,Q.jsx)(si,{className:`h-5 w-6`})]}),(0,Q.jsxs)(`div`,{className:`flex h-8 shrink-0 items-center gap-6 border-b border-border/60 px-3`,children:[(0,Q.jsx)(si,{className:`size-3.5`}),(0,Q.jsx)(si,{className:`h-3 w-20`}),(0,Q.jsx)(si,{className:`h-3 w-24`}),(0,Q.jsx)(si,{className:`h-3 w-12`}),(0,Q.jsx)(si,{className:`h-3 w-28`}),(0,Q.jsx)(si,{className:`h-3 w-32`})]}),(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:Array.from({length:14},(e,t)=>(0,Q.jsxs)(`div`,{className:`flex h-8 items-center gap-6 border-b border-border/60 px-3`,style:{opacity:1-t*.05},children:[(0,Q.jsx)(si,{className:`size-3.5`}),(0,Q.jsx)(si,{className:`h-3 w-16`}),(0,Q.jsx)(si,{className:`h-3 w-20`}),(0,Q.jsx)(si,{className:`h-3 w-8`}),(0,Q.jsx)(si,{className:`h-3 w-24`}),(0,Q.jsx)(si,{className:`h-3 flex-1`})]},t))})]})}function Hu({store:e,child:t,manifest:n,tenancyDeclared:r,tenants:i,tenant:a,onTenantChange:o,runs:s=[],leading:c}){let l=e.migrationDrift,u=oa[e.facet],d=Kn(t)?0:De(t.piiColumns),[f,p]=(0,Z.useState)(!0);(0,Z.useEffect)(()=>{p(!0)},[t.effectRef]);let m=(0,Z.useMemo)(()=>new Set(e.children.map(e=>e.effectRef)),[e.children]),h=an(s,m)??e.replicaLagMs,g=h==null?null:st(h),_=e.facet===`files`,v=Yn(t),y=t.rls===!0,x=hr(t,n,e.name),S=!!(l||h!==null||e.contentAddressed||d>0||v);return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`resource-panel`,children:[(0,Q.jsx)(xi,{dataSlot:`resource-header`,leading:c,icon:(0,Q.jsx)(b,{icon:_?yr:u.icon,className:`size-4`}),wellClassName:u.wellClass,title:ur(t),badge:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] font-medium tracking-[0.08em] text-muted-foreground uppercase`,"data-slot":`facet-badge`,children:_?`Bucket`:u.label}),e.description?(0,Q.jsx)(`span`,{className:`min-w-0 truncate text-[11px] text-muted-foreground`,children:e.description}):null]}),subtitle:(0,Q.jsx)(Q.Fragment,{children:_?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[11px] leading-none text-muted-foreground`,children:ta(e.driverId)}),(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`text-border`,children:`·`}),(0,Q.jsx)(`span`,{className:`shrink-0 text-[11px] leading-none text-muted-foreground`,children:na(e.driverId)}),(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`text-border`,children:`·`}),(0,Q.jsx)(`code`,{className:`min-w-0 truncate font-mono text-[11px] leading-none text-foreground/70`,children:t.effectRef}),(0,Q.jsx)(Ci,{value:t.effectRef,label:`Copy effect ref`})]}):(0,Q.jsx)(Uu,{storeRef:e.ref,effectRef:t.effectRef})}),actions:S?(0,Q.jsxs)(`div`,{className:`flex h-full shrink-0 items-stretch`,"data-slot":`resource-status`,children:[h!==null&&g?(0,Q.jsxs)(Gu,{chipClassName:lt(g),icon:(0,Q.jsx)(b,{icon:bt,className:`size-3`,"aria-hidden":!0}),title:`Replica lag from the newest run that touched this store`,"data-slot":`replica-lag`,children:[(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:ht(h)}),(0,Q.jsx)(`span`,{className:`opacity-70`,children:`lag`})]}):null,e.contentAddressed?(0,Q.jsx)(Gu,{children:`content-addressed`}):null,v?(0,Q.jsx)(Gu,{tone:y?`emerald`:`neutral`,icon:(0,Q.jsx)(b,{icon:y?zi:Ri,className:`size-3`,"aria-hidden":!0}),title:y?x>0?`Row-level security enabled · ${x} ${x===1?`policy`:`policies`}`:`Row-level security enabled`:`Row-level security disabled`,role:`status`,"data-slot":`resource-rls`,"data-rls":y?`on`:`off`,children:y&&x>0?`${x} RLS`:`RLS`}):null,d>0?(0,Q.jsxs)(Gu,{tone:f?`sky`:`amber`,icon:(0,Q.jsx)(b,{icon:Ve,className:`size-3`,"aria-hidden":!0}),title:f?`PII masked on ${t.piiColumns.join(`, `)}. Click to show all cleartext (audited).`:`PII visible on ${t.piiColumns.join(`, `)}. Click to remask.`,pressed:f,ariaLabel:f?`PII masking on for ${d} columns. Show all.`:`PII visible for ${d} columns. Hide all.`,"data-slot":`pii-toggle`,onClick:()=>p(e=>!e),children:[d,` PII`]}):null,l?(0,Q.jsxs)(Gu,{tone:l.drifted?`amber`:`emerald`,icon:(0,Q.jsx)(b,{icon:l.drifted?nt:ci,className:`size-3`,"aria-hidden":!0}),title:`Migration — declared ${l.declared} / applied ${l.applied??`(none)`}`,role:`status`,"data-slot":`migration-drift`,"data-drifted":l.drifted?`true`:`false`,children:[l.drifted?`Drifted`:`In sync`,(0,Q.jsx)(`span`,{className:`font-mono opacity-70`,children:Ku(l.declared)})]}):null]}):void 0}),e.warnings.length>0?(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-start gap-2 border-b border-amber-500/25 bg-amber-500/5 px-3 py-1.5`,children:[(0,Q.jsx)(b,{icon:nt,className:`mt-px size-3.5 shrink-0 text-amber-600 dark:text-amber-400`,"aria-hidden":!0}),(0,Q.jsx)(`ul`,{className:`flex flex-col gap-0.5 text-[11px] leading-relaxed text-amber-800 dark:text-amber-300`,"aria-label":`Warnings`,children:e.warnings.map(e=>(0,Q.jsxs)(`li`,{children:[(0,Q.jsx)(`span`,{className:`font-mono`,children:e.key}),`: `,e.message]},`${e.key}:${e.code}`))})]}):null,(0,Q.jsx)(zu,{store:e,child:t,manifest:n,tenancyDeclared:r,tenants:i,tenant:a,onTenantChange:o,piiMasked:f})]})}function Uu({storeRef:e,effectRef:t}){let n=da(e,t);return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[11px] leading-none text-muted-foreground`,children:e}),n?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`text-border`,children:`·`}),(0,Q.jsx)(`code`,{className:`min-w-0 truncate font-mono text-[11px] leading-none text-foreground/70`,children:n})]}):null,(0,Q.jsx)(Ci,{value:t,label:`Copy effect ref`})]})}var Wu={neutral:`text-muted-foreground`,emerald:`text-emerald-700 dark:text-emerald-400`,amber:`text-amber-800 dark:text-amber-300`,sky:`text-sky-700 dark:text-sky-400`};function Gu({tone:e=`neutral`,icon:t,title:n,children:r,role:i,"data-slot":a,"data-drifted":o,"data-rls":s,pressed:c,onClick:l,ariaLabel:u,chipClassName:d}){let f=S(F,`whitespace-nowrap`,d??Wu[e],l&&`cursor-pointer outline-none focus-visible:ring-2 focus-visible:ring-ring/40`),p=l?(0,Q.jsxs)(`button`,{type:`button`,className:f,"aria-pressed":c,"aria-label":u,"data-slot":a,"data-drifted":o,"data-rls":s,onClick:l,children:[t,r]}):(0,Q.jsxs)(`span`,{className:f,role:i,"data-slot":a,"data-drifted":o,"data-rls":s,children:[t,r]});return n?(0,Q.jsxs)(w,{children:[(0,Q.jsx)(O,{render:e=>(0,Q.jsx)(`span`,{...e,className:`flex self-stretch`,children:p})}),(0,Q.jsx)(T,{side:`bottom`,className:`max-w-xs text-[11px]`,children:n})]}):p}function Ku(e){return e.length>12?`${e.slice(0,12)}…`:e}function qu({stores:e,selectedEffectRef:t,onSelect:n,queryFacet:r=null,onOpenQuery:i,schemaActive:a=!1,onOpenSchema:o,performanceActive:s=!1,performanceFacet:c=null,onOpenPerformance:l}){let[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)({}),[m,h]=(0,Z.useState)(ba),g=(0,Z.useMemo)(()=>sa(ca(e,u)),[e,u]),_=(0,Z.useMemo)(()=>Sa(g,m),[g,m]),v=(0,Z.useMemo)(()=>ha(_),[_]),b=u.trim().length>0,x=v.length>0&&v.every(e=>ma(e,f)),C=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{if(!t)return;let n=ga(e,t).find(e=>e.startsWith(`facet:`));n&&p(e=>e[n]===!1?{...e,[n]:!0}:e);let r=C.current!==null&&C.current!==t;if(C.current=t,!r)return;let i=la(e,t);i&&h(e=>{if(!e.has(i.store.facet))return e;let t=new Set(e);return t.delete(i.store.facet),xa(t),t})},[t,e]);let w=(e,t)=>{p(n=>n[e]===t?n:{...n,[e]:t})};return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`store-tree`,children:[(0,Q.jsx)(`div`,{className:`shrink-0 border-b border-border/60`,children:(0,Q.jsxs)(`div`,{className:S(y,`border-b-0`),children:[(0,Q.jsx)(Fe,{value:u,onChange:e=>d(e.target.value),placeholder:`Search stores…`,"aria-label":`Search stores`,"data-slot":`store-search`}),(0,Q.jsx)(Ju,{hiddenFacets:m,onHiddenChange:(e,t)=>{h(n=>{if(n.has(e)===t)return n;let r=new Set(n);return t?r.add(e):r.delete(e),xa(r),r})}}),(0,Q.jsx)(gr,{allOpen:x,disabled:v.length===0,onToggle:()=>{let e=!x;p(t=>{let n={...t};for(let t of v)n[t]=e;return n})},dataSlot:`store-tree-expand-toggle`,className:`mr-1.5`})]})}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-x-hidden overflow-y-auto`,children:_.length===0?(0,Q.jsx)(`p`,{className:Se,children:g.length===0?`No stores match.`:`All facets hidden.`}):(0,Q.jsx)(`div`,{className:`flex flex-col`,children:_.map(e=>{let u=fa(e.facet);return(0,Q.jsx)(Yu,{band:e,open:ma(u,f),onOpenChange:e=>w(u,e),storeOpen:e=>b?f[e]!==!1:f[e]===!0,onStoreOpenChange:w,selectedEffectRef:t,onSelect:n,queryActive:r===e.facet,onOpenQuery:i&&(e.facet===`sql`||e.facet===`kv`)?()=>i(e.facet===`kv`?`kv`:`sql`):void 0,schemaActive:e.facet===`sql`&&a,onOpenSchema:e.facet===`sql`?o:void 0,performanceActive:(e.facet===`sql`||e.facet===`kv`)&&s&&(c??`sql`)===(e.facet===`kv`?`kv`:`sql`),onOpenPerformance:l&&(e.facet===`sql`||e.facet===`kv`)?()=>l(e.facet===`kv`?`kv`:`sql`):void 0},e.facet)})})})]})}function Ju({hiddenFacets:e,onHiddenChange:t}){return(0,Q.jsx)(`div`,{className:`flex h-full shrink-0 items-stretch`,role:`group`,"aria-label":`Store facets`,"data-slot":`store-tree-facet-toggles`,children:ra.map(n=>{let r=oa[n],i=!e.has(n);return(0,Q.jsx)(J,{label:i?`Hide ${r.label}`:`Show ${r.label}`,className:`flex self-stretch`,children:(0,Q.jsx)(`button`,{type:`button`,"aria-label":i?`Hide ${r.label}`:`Show ${r.label}`,"aria-pressed":i,"data-slot":`store-tree-facet-toggle`,"data-facet":n,onClick:()=>t(n,i),className:S(R,i?k(r.wellClass):`text-muted-foreground/40 hover:text-muted-foreground`),children:(0,Q.jsx)(b,{icon:r.icon,className:ce,"aria-hidden":!0})})},n)})})}function Yu({band:e,open:t,onOpenChange:n,storeOpen:r,onStoreOpenChange:i,selectedEffectRef:a,onSelect:o,queryActive:s,onOpenQuery:c,schemaActive:l,onOpenSchema:u,performanceActive:d,onOpenPerformance:f}){let p=oa[e.facet],m=e.stores.reduce((e,t)=>t.store.facet===`sql`?e+tr(t.children).tables.length:e+t.children.length,0),h=e.stores.filter(e=>!ua(e.store)).map(e=>e.store.ref),g=h.length>0&&h.every(e=>r(e)),_=()=>{let e=!g;for(let t of h)i(t,e);e&&n(!0)},v=(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(b,{icon:p.icon,className:S(ce,k(p.wellClass)),"aria-hidden":!0}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:he,children:e.label}),(0,Q.jsx)(`span`,{className:P,children:m})]})]});return(0,Q.jsx)(`section`,{"data-slot":`store-facet-band`,"data-facet":e.facet,"aria-label":e.label,className:ye,children:(0,Q.jsxs)(rt,{open:t,onOpenChange:n,children:[(0,Q.jsx)(tt,{nativeButton:!1,className:de,"data-slot":`store-facet-band-toggle`,render:n=>(0,Q.jsxs)(`div`,{...n,children:[(0,Q.jsx)(nd,{open:t}),v,(0,Q.jsxs)(`span`,{className:S(V,(l||s||d)&&`opacity-100`),children:[u?(0,Q.jsx)(ed,{active:l,onOpen:u}):null,f?(0,Q.jsx)(td,{active:d,onOpen:f}):null,c?(0,Q.jsx)($u,{facet:e.facet===`kv`?`kv`:`sql`,active:s,onOpen:c}):null,(0,Q.jsx)(gr,{allOpen:g,disabled:h.length===0,onToggle:_,collapseLabel:`Collapse all in ${e.label}`,expandLabel:`Expand all in ${e.label}`,dataSlot:`store-facet-expand-toggle`,disclose:!0,bare:!0})]})]})}),(0,Q.jsx)($e,{children:(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:e.stores.map(e=>(0,Q.jsx)(Xu,{node:e,facetWellClass:p.wellClass,facetIcon:p.icon,open:r(e.store.ref),onOpenChange:t=>i(e.store.ref,t),tablesOpen:r(pa(e.store.ref)),onTablesOpenChange:t=>i(pa(e.store.ref),t),selectedEffectRef:a,onSelect:o},e.store.ref))})})]})})}function Xu({node:e,facetWellClass:t,facetIcon:n,open:r,onOpenChange:i,tablesOpen:a,onTablesOpenChange:o,selectedEffectRef:s,onSelect:c}){let l=e.children[0];return ea(e.store)&&l?(0,Q.jsx)(ad,{store:e.store,child:l,selected:s===l.effectRef,onSelect:c}):ua(e.store)&&l?(0,Q.jsx)(od,{child:l,wellClass:t,icon:n,selected:s===l.effectRef,onSelect:c,nest:`store`}):(0,Q.jsx)(`li`,{"data-slot":`store-group`,"data-ref":e.store.ref,children:(0,Q.jsxs)(rt,{open:r,onOpenChange:i,children:[(0,Q.jsx)(tt,{nativeButton:!1,className:S(fe,`group/store pl-4`),"data-slot":`store-group-toggle`,render:t=>(0,Q.jsxs)(`div`,{...t,children:[(0,Q.jsx)(nd,{open:r}),(0,Q.jsx)(b,{icon:yr,className:S(ce,`text-muted-foreground`),"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:e.store.name}),(0,Q.jsx)(`span`,{className:P,children:e.store.facet===`sql`?tr(e.children).tables.length:e.children.length}),e.store.facet===`files`?(0,Q.jsx)(id,{driverId:e.store.driverId}):null]})}),(0,Q.jsx)($e,{children:(0,Q.jsx)(Zu,{node:e,facetWellClass:t,facetIcon:n,tablesOpen:a,onTablesOpenChange:o,selectedEffectRef:s,onSelect:c})})]})})}function Zu({node:e,facetWellClass:t,facetIcon:n,tablesOpen:r,onTablesOpenChange:i,selectedEffectRef:a,onSelect:o}){let s=tr(e.children);return e.store.facet!==`sql`||s.catalog.length===0?(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:e.children.map(r=>(0,Q.jsx)(od,{child:r,wellClass:t,icon:e.store.facet===`sql`?Oi:e.store.facet===`files`?yr:n,hint:e.store.facet===`files`?`bucket`:void 0,selected:a===r.effectRef,onSelect:o},r.effectRef))}):(0,Q.jsxs)(`ul`,{className:`flex flex-col`,children:[(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(rt,{open:r,onOpenChange:i,children:[(0,Q.jsx)(tt,{nativeButton:!1,className:S(fe,`group/tables group/store pl-6`),"data-slot":`store-tables-toggle`,render:e=>(0,Q.jsxs)(`div`,{...e,children:[(0,Q.jsx)(nd,{open:r}),(0,Q.jsx)(b,{icon:Bi,className:S(ce,k(t)),"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:`Tables`}),(0,Q.jsx)(`span`,{className:P,children:s.tables.length})]})}),(0,Q.jsx)($e,{children:(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:s.tables.map(e=>(0,Q.jsx)(od,{child:e,wellClass:t,icon:Oi,nest:`deep`,selected:a===e.effectRef,onSelect:o},e.effectRef))})})]})}),s.catalog.map(e=>(0,Q.jsx)(od,{child:e,wellClass:t,icon:Qu(e),selected:a===e.effectRef,onSelect:o},e.effectRef))]})}function Qu(e){let t=pr(e);return t===`index`?Re:t===`function`?Ai:t===`trigger`?Hi:t===`extension`?Ii:t===`policy`?Ve:yr}function $u({facet:e,active:t,onOpen:n}){let r=e===`sql`?`SQL console`:`KV console`;return(0,Q.jsxs)(w,{children:[(0,Q.jsx)(O,{render:i=>(0,Q.jsx)(`button`,{...i,type:`button`,"aria-label":r,"aria-pressed":t,"data-slot":`store-facet-query`,"data-facet":e,onClick:e=>{e.stopPropagation(),i.onClick?.(e),n()},className:S(`inline-flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors`,`hover:bg-muted/80 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/40 focus-visible:outline-none`,t&&`bg-muted text-foreground`),children:(0,Q.jsx)(b,{icon:Ze,className:`size-3.5`,"aria-hidden":!0})})}),(0,Q.jsx)(T,{side:`bottom`,className:`text-[11px]`,children:r})]})}function ed({active:e,onOpen:t}){return(0,Q.jsxs)(w,{children:[(0,Q.jsx)(O,{render:n=>(0,Q.jsx)(`button`,{...n,type:`button`,"aria-label":`Schema visualizer`,"aria-pressed":e,"data-slot":`store-facet-schema`,onClick:e=>{e.stopPropagation(),n.onClick?.(e),t()},className:S(`inline-flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors`,`hover:bg-muted/80 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/40 focus-visible:outline-none`,e&&`bg-muted text-foreground`),children:(0,Q.jsx)(b,{icon:ji,className:`size-3.5`,"aria-hidden":!0})})}),(0,Q.jsx)(T,{side:`bottom`,className:`text-[11px]`,children:`Schema visualizer`})]})}function td({active:e,onOpen:t}){return(0,Q.jsxs)(w,{children:[(0,Q.jsx)(O,{render:n=>(0,Q.jsx)(`button`,{...n,type:`button`,"aria-label":`Query performance`,"aria-pressed":e,"data-slot":`store-facet-performance`,onClick:e=>{e.stopPropagation(),n.onClick?.(e),t()},className:S(`inline-flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors`,`hover:bg-muted/80 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/40 focus-visible:outline-none`,e&&`bg-muted text-foreground`),children:(0,Q.jsx)(b,{icon:K,className:`size-3.5`,"aria-hidden":!0})})}),(0,Q.jsx)(T,{side:`bottom`,className:`text-[11px]`,children:`Query performance`})]})}function nd({open:e}){return(0,Q.jsx)(b,{icon:et,className:S(U,!e&&`-rotate-90`),"aria-hidden":!0})}function rd({enabled:e}){let t=e?`RLS enabled`:`RLS disabled`;return(0,Q.jsxs)(w,{children:[(0,Q.jsx)(O,{render:n=>(0,Q.jsx)(`span`,{...n,"data-slot":`store-table-rls`,"data-rls":e?`on`:`off`,"aria-label":t,className:S(ce,e?`text-emerald-500`:`text-muted-foreground/35 group-hover/child:text-amber-600 dark:group-hover/child:text-amber-400`),children:(0,Q.jsx)(b,{icon:e?zi:Ri,className:`size-3.5`,"aria-hidden":!0})})}),(0,Q.jsx)(T,{side:`right`,children:t})]})}function id({driverId:e}){return(0,Q.jsxs)(w,{children:[(0,Q.jsx)(O,{render:t=>(0,Q.jsx)(`span`,{...t,className:`shrink-0 font-mono text-[10px] text-muted-foreground`,"data-slot":`files-driver`,children:ta(e)})}),(0,Q.jsx)(T,{side:`right`,className:`text-[11px]`,children:na(e)})]})}function ad({store:e,child:t,selected:n,onSelect:r}){return(0,Q.jsx)(`li`,{"data-slot":`store-files-bucket`,"data-ref":e.ref,children:(0,Q.jsxs)(`button`,{type:`button`,"data-slot":`store-child-item`,"data-effect-ref":t.effectRef,"aria-current":n?`true`:void 0,onClick:()=>r(t.effectRef),className:S(ue,`group/child pl-4`,n&&`bg-muted/70 text-foreground`),children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:S(me,n?H:`bg-transparent`)}),(0,Q.jsx)(b,{icon:yr,className:S(ce,k(oa.files.wellClass)),"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:e.name}),(0,Q.jsx)(id,{driverId:e.driverId})]})})}function od({child:e,wellClass:t,icon:n,selected:r,onSelect:i,hint:a,nest:o=`child`}){return(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,"data-slot":`store-child-item`,"data-effect-ref":e.effectRef,"aria-current":r?`true`:void 0,onClick:()=>i(e.effectRef),className:S(ue,`group/child`,o===`store`?`pl-4`:o===`deep`?`pl-12`:`pl-8`,r&&`bg-muted/70 text-foreground`),children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:S(me,r?H:`bg-transparent`)}),(0,Q.jsx)(b,{icon:n,className:S(ce,k(t)),"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:ur(e)}),a?(0,Q.jsx)(`span`,{className:`shrink-0 text-[10px] tracking-[0.08em] text-muted-foreground/70 uppercase`,children:a}):null,Yn(e)?(0,Q.jsx)(rd,{enabled:e.rls===!0}):null]})})}var sd=`sql:oke_console`;function cd(e){return e?`SELECT *\nFROM "${e}"\nLIMIT 50;`:`SELECT 1;`}var ld=/^SELECT \*\nFROM "([^"]+)"\nLIMIT 50;$/,ud=/^\/\/ list · get · set · delete · ttl\nlist(?: (.+))?$/;function dd(e,t,n=Math.random){let r=ld.exec(e);if(!r)return e;let i=r[1];return i&&t.includes(i)?e:cd(gd(t,n))}function fd(e,t,n=Math.random){let r=ud.exec(e);if(!r)return e;let i=r[1];if(!i)return e;let a=i.endsWith(`:`)?i.slice(0,-1):i;if(t.includes(a))return e;let o=gd(t,n);return md(o?`${o}:`:void 0)}function pd(e,t,n){return n===`sql`?dd(e,t):fd(e,t)}function md(e){return e?`// list · get · set · delete · ttl\nlist ${e}`:`// list · get · set · delete · ttl
30
+ list`}function hd(e,t,n){let r=e.filter(e=>e.facet===t);if(r.length===0)return null;if(n){let e=r.find(e=>e.ref===n||e.children.some(e=>e.effectRef===n));if(e)return e}return r.find(e=>e.ref!==`sql:oke_console`)??r[0]??null}function gd(e,t=Math.random){if(e.length!==0)return e[Math.min(e.length-1,Math.floor(t()*e.length))]}function _d(e,t=Math.random){return gd(e.children.map(e=>e.name),t)}function vd(e){return e===sd}function yd(e){if(!e.error)return null;let t=e.error.data,n=t&&typeof t==`object`&&`reason`in t&&typeof t.reason==`string`?t.reason:null,r=Error(n??e.error.message??e.error.code);return r.code=e.error.code,r.data=e.error.data,r}function bd(){return Yr({mutationFn:async e=>{let t=await ee(e),n=yd(t);if(n)throw n;if(!t.data)throw Error(`Empty advise result`);return t.data}})}var xd=[`console.store.sql.locks`],Sd=1e4;function Cd(e){if(!e.error)return null;let t=e.error.data,n=t&&typeof t==`object`&&`reason`in t&&typeof t.reason==`string`?t.reason:null,r=Error(n??e.error.message??e.error.code);return r.code=e.error.code,r.data=e.error.data,r}function wd(e){return A({queryKey:[...xd,e],enabled:e!==null,refetchInterval:Sd,queryFn:async()=>{if(!e)throw Error(`Missing store ref`);let t=await j(e),n=Cd(t);if(n)throw n;if(!t.data)throw Error(`Empty SQL locks`);return t.data}})}var Td=[`console.store.sql.stats`];function Ed(e){if(!e.error)return null;let t=e.error.data,n=t&&typeof t==`object`&&`reason`in t&&typeof t.reason==`string`?t.reason:null,r=Error(n??e.error.message??e.error.code);return r.code=e.error.code,r.data=e.error.data,r}function Dd(e){return A({queryKey:[...Td,e],enabled:e!==null,queryFn:async()=>{if(!e)throw Error(`Missing store ref`);let t=await Ce(e),n=Ed(t);if(n)throw n;if(!t.data)throw Error(`Empty SQL stats`);return t.data}})}function Od(e){return e?e.installed?`on`:e.available?`enable`:`cta`:null}var kd=[`console.store.kv.stats`];function Ad(e){if(!e.error)return null;let t=e.error.data,n=t&&typeof t==`object`&&`reason`in t&&typeof t.reason==`string`?t.reason:null,r=Error(n??e.error.message??e.error.code);return r.code=e.error.code,r.data=e.error.data,r}function jd(e){return A({queryKey:[...kd,e],enabled:e!==null,queryFn:async()=>{if(!e)throw Error(`Missing store ref`);let t=await z(e),n=Ad(t);if(n)throw n;if(!t.data)throw Error(`Empty KV stats`);return t.data}})}function Md({stores:e,selectedEffectRef:t,tenant:n,leading:r}){let i=hd(e,`kv`,t),[a,o]=(0,Z.useState)(!1),s=jd(i?{ref:i.ref,...n?{tenant:n}:{},...a?{revealPii:!0}:{}}:null),c=Ld(s.error),l=Rd(s.error),u=(0,Z.useMemo)(()=>(s.data?.commands??[]).map(Pd),[s.data?.commands]),d=(0,Z.useMemo)(()=>(s.data?.slowlog??[]).map(Fd),[s.data?.slowlog]);if(!i)return(0,Q.jsx)(di,{icon:K,title:`No KV store`,description:`KV performance reads INFO / COMMANDSTATS / SLOWLOG on a redis-backed namespace.`,leading:r});if(l===`KvStatsUnsupported`)return(0,Q.jsx)(di,{leading:r,icon:K,title:`Engine telemetry unavailable`,description:c??`KV stats are not available on this driver (in-process memory has no INFO / SLOWLOG).`});let f=s.data?.kpis;return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`store-kv-performance`,children:[(0,Q.jsx)(xi,{dataSlot:`store-kv-performance-header`,leading:r,icon:(0,Q.jsx)(b,{icon:K,className:`size-4`}),title:`KV performance`,badge:(0,Q.jsx)(`span`,{className:`font-mono text-[10px] font-medium tracking-[0.08em] text-muted-foreground`,children:i.ref}),subtitle:(0,Q.jsx)(`span`,{className:`font-mono text-[11px] leading-none text-muted-foreground`,children:s.data?.engine??`—`}),actions:(0,Q.jsx)(q,{piiMasked:!a,disabled:s.isPending,onToggle:()=>o(e=>!e)})}),(0,Q.jsxs)(`p`,{className:`shrink-0 border-b border-border/60 bg-amber-500/8 px-3 py-1.5 text-[11px] leading-relaxed text-amber-900 dark:text-amber-200`,"data-slot":`store-kv-stats-gap`,role:`note`,children:[`INFO / COMMANDSTATS / LATENCY are instance-wide, not scoped to`,` `,(0,Q.jsx)(`span`,{className:`font-mono`,children:s.data?.namespacePrefix??`oke:kv:{ns}:`}),`. Limitation: `,v,`. SLOWLOG args are keys and values — collapsed until reveal. Limitation: `,ie,`. No hot-key table (OSS Redis does not expose one without MONITOR).`]}),(0,Q.jsxs)(`div`,{className:we,children:[(0,Q.jsx)(Nd,{label:`Hit rate`,value:Id(f?.hitRate??null),title:`keyspace_hits / (hits + misses)`}),(0,Q.jsx)(Nd,{label:`Ops / sec`,value:f?.opsPerSec==null?`—`:String(f.opsPerSec),title:`instantaneous_ops_per_sec`}),(0,Q.jsx)(Nd,{label:`Evicted`,value:f?.evictedKeys==null?`—`:String(f.evictedKeys),title:`evicted_keys`}),(0,Q.jsx)(Nd,{label:`Expired`,value:f?.expiredKeys==null?`—`:String(f.expiredKeys),title:`expired_keys`})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,Q.jsx)($t,{rows:u,error:c,pending:s.isPending,meta:s.data?`${s.data.commands.length} commands`:null,storeRef:i.ref})}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 border-t border-border/60`,children:(0,Q.jsx)($t,{rows:d,error:null,pending:s.isPending&&!s.data,meta:s.data?`${s.data.slowlog.length} slowlog · ${s.data.masked?`args collapsed`:`args revealed`}`:`slowlog`,storeRef:i.ref})})]})}function Nd({label:e,value:t,title:n}){return(0,Q.jsxs)(`span`,{className:`inline-flex h-full items-center gap-1.5 border-r border-border/60 px-2 text-[11px]`,title:n,children:[(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:t}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e})]})}function Pd(e){return{command:e.command,calls:e.calls,usec:e.usec,usec_per_call:e.usecPerCall}}function Fd(e){return{command:e.command,duration_us:e.durationUs,args:e.args.join(` `),id:e.id}}function Id(e){return e==null?`—`:`${(e*100).toFixed(2)}%`}function Ld(e){return e?e instanceof Error?e.message:String(e):null}function Rd(e){return!e||typeof e!=`object`||!(`code`in e)?null:typeof e.code==`string`?e.code:null}function zd({stores:e,selectedEffectRef:t,tenant:n,facet:r=`sql`,leading:i}){if(r===`kv`)return(0,Q.jsx)(Md,{stores:e,selectedEffectRef:t,tenant:n,leading:i});let a=hd(e,`sql`,t),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(null),u=a?{ref:a.ref,...n?{tenant:n}:{}}:null,d=Dd(u),f=wd(a?{...u,...o?{revealPii:!0}:{}}:null),p=bd(),m=Qo(),h=qd(d.error),g=Jd(d.error),_=qd(f.error),v=(0,Z.useMemo)(()=>(d.data?.statements??[]).map(Ud),[d.data?.statements]),y=(0,Z.useMemo)(()=>(f.data?.rows??[]).map(Wd),[f.data?.rows]);if(!a)return(0,Q.jsx)(di,{icon:K,title:`No SQL store`,description:`Query performance reads pg_stat_statements on a postgres-backed SQL store.`,leading:i});if(g===`PgStatStatementsNotPreloaded`)return(0,Q.jsx)(di,{leading:i,icon:K,title:`pg_stat_statements is not preloaded`,description:(0,Q.jsxs)(Q.Fragment,{children:[`Enabling the extension is not enough — add it to`,` `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`shared_preload_libraries`}),` at container start, recreate`,` `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`store-sql`}),`, then create the extension. Limitation:`,` `,g,`.`]})});if(g===`PgStatStatementsUnsupported`)return(0,Q.jsx)(di,{leading:i,icon:K,title:`Engine telemetry unavailable`,description:h??`pg_stat_statements is not available on this driver (memory, pglite, or CockroachDB).`});let x=d.data?.advisor,S=Od(x),C=d.data?.kpis,w=Ha.some(e=>e.name===`index_advisor`);return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`store-performance`,children:[(0,Q.jsx)(xi,{dataSlot:`store-performance-header`,leading:i,icon:(0,Q.jsx)(b,{icon:K,className:`size-4`}),title:`Query performance`,badge:(0,Q.jsx)(`span`,{className:`font-mono text-[10px] font-medium tracking-[0.08em] text-muted-foreground`,children:a.ref}),subtitle:(0,Q.jsx)(`span`,{className:`text-[11px] leading-none text-muted-foreground`,"data-slot":`locks-polling`,children:`locks polling`}),actions:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(q,{piiMasked:!o,disabled:f.isPending,onToggle:()=>s(e=>!e)}),(0,Q.jsx)(Bd,{advisor:x,pending:m.isPending,onEnable:()=>{m.mutateAsync({ref:a.ref,sql:lo(`index_advisor`,{cascade:!0}),allowWrite:!0,...n?{tenant:n}:{}}).then(()=>d.refetch())}})]})}),(0,Q.jsxs)(`p`,{className:`shrink-0 border-b border-border/60 bg-amber-500/8 px-3 py-1.5 text-[11px] leading-relaxed text-amber-900 dark:text-amber-200`,"data-slot":`store-sql-stats-pii-gap`,role:`note`,children:[`Engine-native query text from pg_stat_statements (usually`,` `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`$n`}),` fingerprints) and live lock activity. Live`,` `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`pg_stat_activity.query`}),` can contain literals — collapsed until reveal. Limitation: `,E,`. Not the Store browse / projectRun guarantee.`,S===`cta`?(0,Q.jsxs)(Q.Fragment,{children:[` `,`Index Advisor is not in `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`pg_available_extensions`}),w?` — pin oke-postgres-advisor:18-alpine (or supabase/postgres).`:`.`]}):null]}),(0,Q.jsxs)(`div`,{className:we,children:[(0,Q.jsx)(Hd,{label:`Slow queries`,value:C?String(C.slowQueries):`—`,title:`Statements with mean exec ≥ 100ms`}),(0,Q.jsx)(Hd,{label:`Cache hit rate`,value:Gd(C?.cacheHitRate??null),title:`shared_blks_hit / (hit + read) across listed statements`}),(0,Q.jsx)(Hd,{label:`Avg rows / call`,value:C?.avgRowsPerCall==null?`—`:C.avgRowsPerCall.toFixed(1),title:`sum(rows) / sum(calls)`})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,Q.jsx)($t,{rows:v,error:g&&g!==`PgStatStatementsNotCreated`?h:null,pending:d.isPending,meta:d.data?`${d.data.rowCount} statements${d.data.truncated?` (capped)`:``}`:null,storeRef:a.ref})}),x?.installed&&(d.data?.statements.length??0)>0?(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1.5 border-t border-border/60 px-3 py-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:`Suggest indexes`}),(d.data?.statements??[]).slice(0,6).map((e,t)=>(0,Q.jsxs)(G,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 rounded-none text-[11px]`,disabled:!e.query||p.isPending,onClick:()=>{l(e),p.mutate({ref:a.ref,query:e.query??``,...n?{tenant:n}:{}})},"data-slot":`store-sql-advise`,children:[`#`,t+1]},e.queryid??t))]}):null,c?(0,Q.jsx)(Vd,{query:c.query,result:p.data??null,error:qd(p.error),pending:p.isPending}):null,(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 border-t border-border/60`,children:(0,Q.jsx)($t,{rows:y,error:_,pending:f.isPending&&!f.data,meta:f.data?`${f.data.rows.length} blocking pair${f.data.rows.length===1?``:`s`} · polling`:`locks`,storeRef:a.ref})})]})}function Bd({advisor:e,pending:t,onEnable:n}){let r=Od(e);return r===`on`?(0,Q.jsx)(`span`,{className:S(F,Ee),"data-slot":`index-advisor-on`,children:`Index Advisor on`}):r===`cta`||r!==`enable`?null:(0,Q.jsx)(G,{type:`button`,variant:`ghost`,size:`sm`,className:`h-full rounded-none px-2 text-[11px]`,disabled:t,onClick:n,"data-slot":`index-advisor-enable`,children:`Enable Index Advisor`})}function Vd({query:e,result:t,error:n,pending:r}){return(0,Q.jsxs)(`div`,{className:`shrink-0 border-t border-border/60 px-3 py-2 text-[11px]`,"data-slot":`index-advisor-result`,children:[(0,Q.jsx)(`p`,{className:`truncate font-mono text-muted-foreground`,children:e}),r?(0,Q.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:`Advising…`}):null,n?(0,Q.jsx)(`p`,{className:`mt-1 text-destructive`,children:n}):null,t?(0,Q.jsxs)(`div`,{className:`mt-1 flex flex-col gap-0.5`,children:[(0,Q.jsxs)(`p`,{children:[`Cost `,Kd(t.totalCostBefore),` → `,Kd(t.totalCostAfter)]}),t.indexStatements.length===0?(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:`No index suggestion.`}):t.indexStatements.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(`code`,{className:`min-w-0 flex-1 font-mono text-foreground`,children:e}),(0,Q.jsx)(G,{type:`button`,size:`sm`,variant:`ghost`,className:`h-6 rounded-none px-1.5 text-[11px]`,onClick:()=>void navigator.clipboard.writeText(e),children:`Copy`})]},e)),t.errors.map(e=>(0,Q.jsx)(`p`,{className:`text-destructive`,children:e},e))]}):null]})}function Hd({label:e,value:t,title:n}){return(0,Q.jsxs)(`span`,{className:`inline-flex h-full items-center gap-1.5 border-r border-border/60 px-2 text-[11px]`,title:n,children:[(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:t}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e})]})}function Ud(e){return{query:e.query,calls:e.calls,total_ms:Number(e.totalExecMs.toFixed(2)),mean_ms:Number(e.meanExecMs.toFixed(2)),max_ms:Number(e.maxExecMs.toFixed(2)),min_ms:Number(e.minExecMs.toFixed(2)),rows:e.rows,cache_hit:Gd(e.cacheHitRate)}}function Wd(e){return{blocked_pid:e.blockedPid,blocked_user:e.blockedUser,blocked_query:e.blockedQuery,blocking_pid:e.blockingPid,blocking_user:e.blockingUser,blocking_query:e.blockingQuery,blocking_state:e.blockingState}}function Gd(e){return e==null?`—`:`${(e*100).toFixed(2)}%`}function Kd(e){return e==null?`—`:String(e)}function qd(e){return e?e instanceof Error?e.message:String(e):null}function Jd(e){return!e||typeof e!=`object`||!(`code`in e)?null:typeof e.code==`string`?e.code:null}var Yd=/^\s*(\/\/|#|--)/,Xd=/^(list|get|set|delete|ttl)\b/i;function Zd(e){let t=ef(e);if(t.length===0)return{kind:`list`,prefix:``};let n=Xd.exec(t)?.[1]?.toLowerCase();if(n===`set`)return rf(t);if(n===`list`)return tf(t);if(n===`get`||n===`delete`||n===`ttl`)return nf(n,t);let r=$d(t)??t;return/\s/.test(r)?{kind:`error`,message:"Use `list`, `get`, `set`, `delete`, or `ttl`."}:{kind:`list`,prefix:r}}function Qd(e){let t={};return e.keepValue||(t.value=e.value),e.ttl!==void 0&&(t.ttl=e.ttl),t}function $d(e){let t=e.split(`
31
+ `);for(let e=t.length-1;e>=0;--e){let n=t[e]?.trim()??``;if(!(n.length===0||Yd.test(n)))return n}return null}function ef(e){let t=e.split(`
32
+ `),n=-1;for(let e=0;e<t.length;e+=1){let r=t[e]?.trim()??``;r.length===0||Yd.test(r)||Xd.test(r)&&(n=e)}return n>=0?t.slice(n).join(`
33
+ `).trim():$d(e)??``}function tf(e){if(e.includes(`(`)){let t=af(e,`list`);if(t.kind===`error`)return t;if(t.args.length===0)return{kind:`list`,prefix:``};if(t.args.length>1)return{kind:`error`,message:`list takes an optional prefix.`};let n=of(t.args[0]??``,`list prefix`);return n.kind===`error`?n:{kind:`list`,prefix:n.value}}let t=/^list(?:\s+(\S.*))?$/i.exec($d(e)??e);return t?{kind:`list`,prefix:t[1]?.trim()??``}:{kind:`error`,message:'Use `list [prefix]` or `list("prefix")`.'}}function nf(e,t){if(t.includes(`(`)){let n=af(t,e);if(n.kind===`error`)return n;if(n.args.length!==1)return{kind:`error`,message:`${e} requires a key.`};let r=of(n.args[0]??``,`${e} key`);return r.kind===`error`?r:r.value.length===0?{kind:`error`,message:`${e} requires a key.`}:{kind:e,key:r.value}}let n=RegExp(`^${e}(?:\\s+(\\S.*))?$`,`i`).exec($d(t)??t)?.[1]?.trim()??``;return n.length===0?{kind:`error`,message:`${e} requires a key.`}:{kind:e,key:n}}function rf(e){let t=e.indexOf(`(`);if(t<0||!/^set\s*\(/i.test(e.slice(0,t+1)))return{kind:`error`,message:"set requires `set(key, value, ttl?)`."};let n=af(e,`set`);if(n.kind===`error`)return n;let r=n.args;if(r.length<2)return{kind:`error`,message:`set requires a key and a value.`};if(r.length>3)return{kind:`error`,message:`set takes key, value, and optional TTL.`};let i=sf(r[0]??``);if(!i.ok||typeof i.value!=`string`||i.value.length===0)return{kind:`error`,message:`set key must be a string.`};let a=r[1]??``,o=a===`value`,s;if(!o){let e=sf(a);if(!e.ok)return{kind:`error`,message:`set value: ${e.error}`};s=e.value}let c;if(r[2]!==void 0){let e=sf(r[2]);if(!e.ok||typeof e.value!=`string`)return{kind:`error`,message:`TTL must be a duration string like "30m".`};let t=Yt(e.value);if(t===void 0)return{kind:`error`,message:`TTL must be a duration like 30m, 1h, or empty.`};c=t}else o&&(c=null);return o?{kind:`set`,key:i.value,keepValue:!0,ttl:c}:{kind:`set`,key:i.value,keepValue:!1,value:s,ttl:c}}function af(e,t){let n=e.indexOf(`(`);if(n<0)return{kind:`error`,message:`${t} requires parentheses.`};let r=lf(e,n);if(r<0)return{kind:`error`,message:`Unclosed ${t}(…).`};let i=e.slice(r+1).trim();return i.length>0&&!Yd.test(i)?{kind:`error`,message:`Unexpected input after ${t}(…).`}:{kind:`ok`,args:cf(e.slice(n+1,r))}}function of(e,t){let n=sf(e);return!n.ok||typeof n.value!=`string`?{kind:`error`,message:`${t} must be a string.`}:{kind:`ok`,value:n.value}}function sf(e){try{return{ok:!0,value:JSON.parse(e)}}catch(e){return{ok:!1,error:e instanceof Error?e.message:`invalid JSON`}}}function cf(e){let t=[],n=0,r=0,i=null,a=!1;for(let o=0;o<e.length;o+=1){let s=e[o]??``;if(i){if(a){a=!1;continue}if(s===`\\`){a=!0;continue}s===i&&(i=null);continue}if(s===`"`||s===`'`){i=s;continue}if(s===`{`||s===`[`||s===`(`){r+=1;continue}if(s===`}`||s===`]`||s===`)`){--r;continue}if(s===`,`&&r===0){let r=e.slice(n,o).trim();r.length>0&&t.push(r),n=o+1}}let o=e.slice(n).trim();return o.length>0&&t.push(o),t}function lf(e,t){let n=0,r=null,i=!1;for(let a=t;a<e.length;a+=1){let t=e[a]??``;if(r){if(i){i=!1;continue}if(t===`\\`){i=!0;continue}t===r&&(r=null);continue}if(t===`"`||t===`'`){r=t;continue}if(t===`(`||t===`{`||t===`[`)n+=1;else if((t===`)`||t===`}`||t===`]`)&&(--n,n===0&&t===`)`))return a}return-1}var uf=8,df=24,ff=24;function pf(e){return/^Query \d+$/.test(e)}function mf(e){let t=new Set(e.map(e=>e.title)),n=1;for(;t.has(`Query ${n}`);)n+=1;return`Query ${n}`}function hf(e,t){return e.length>=uf?e:[...e,{id:jf(),title:mf(e),text:t}]}function gf(e,t,n){let r=e.filter(e=>e.id!==t);return r.length>0?r:[{id:jf(),title:`Query 1`,text:n}]}function _f(e,t,n){return e.map(e=>e.id===t?{...e,text:n}:e)}function vf(e,t,n){let r=n.trim().replace(/\s+/g,` `),i=r.length>0?r.slice(0,48):mf(e.filter(e=>e.id!==t));return e.map(e=>e.id===t?{...e,title:i}:e)}function yf(e,t){let n={id:t.id,title:t.title,text:t.text,at:t.at??Date.now()};return[n,...e.filter(e=>e.id!==n.id)].slice(0,ff)}function bf(e,t){return[{...t,id:jf()},...e].slice(0,df)}function xf(e){for(let t of e.split(`
34
+ `)){let e=t.trim();if(!(e.length===0||e.startsWith(`//`)||e.startsWith(`--`)))return e.length>72?`${e.slice(0,71)}…`:e}return e.trim().slice(0,72)||`(empty)`}function Sf(e){let t=Of(e),n=Lf(Ff(),t,Mf);if(n)return n;let r=Lf(If(),t,Mf);return r&&Rf(Ff(),t,r),r}function Cf(e,t){Rf(Ff(),Of(e),t)}function wf(e){return Lf(If(),kf(e),Nf)??[]}function Tf(e,t){Rf(If(),kf(e),t)}function Ef(e){return Lf(Ff(),Af(e),Pf)??[]}function Df(e,t){Rf(Ff(),Af(e),t)}function Of(e){return`oke_store_query_tabs_${e}`}function kf(e){return`oke_store_query_history_${e}`}function Af(e){return`oke_store_query_saved_${e}`}function jf(){return`q_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function Mf(e){return!Array.isArray(e)||e.length===0?!1:e.every(e=>typeof e==`object`&&!!e&&typeof e.id==`string`&&typeof e.title==`string`&&typeof e.text==`string`)}function Nf(e){return Array.isArray(e)?e.every(e=>typeof e==`object`&&!!e&&typeof e.id==`string`&&typeof e.at==`number`&&typeof e.text==`string`):!1}function Pf(e){return Array.isArray(e)?e.every(e=>typeof e==`object`&&!!e&&typeof e.id==`string`&&typeof e.title==`string`&&typeof e.text==`string`&&typeof e.at==`number`):!1}function Ff(){try{return typeof localStorage>`u`?null:localStorage}catch{return null}}function If(){try{return typeof sessionStorage>`u`?null:sessionStorage}catch{return null}}function Lf(e,t,n){if(!e)return null;try{let r=e.getItem(t);if(!r)return null;let i=JSON.parse(r);return n(i)?i:null}catch{return null}}function Rf(e,t,n){if(e)try{e.setItem(t,JSON.stringify(n))}catch{}}var zf=/^\s*(\/\/|#|--)/,Bf=/^(list|get|set|delete|ttl)\b/i;function Vf(e){if(e.trim().length===0)return``;let t=e.split(`
35
+ `),n=[],r=0;for(;r<t.length;){let e=t[r]?.trim()??``;if(e.length===0||zf.test(e)){n.push(e),r+=1;continue}let i=r+1;if(Bf.test(e))for(;i<t.length;){let e=t[i]?.trim()??``;if(Bf.test(e))break;i+=1}let a=t.slice(r,i),o=[];for(;a.length>1;){let e=a[a.length-1]?.trim()??``;if(e.length===0||zf.test(e)){o.unshift(a.pop()?.trim()??``);continue}break}n.push(Hf(a.join(`
36
+ `))),n.push(...o),r=i}return n.join(`
37
+ `).replace(/\n{3,}/g,`
38
+
39
+ `).trim()}function Hf(e){let t=Zd(e);return t.kind===`error`?e.trim():Uf(t)}function Uf(e){switch(e.kind){case`list`:return e.prefix.length===0?`list()`:`list(${JSON.stringify(e.prefix)})`;case`get`:case`delete`:case`ttl`:return`${e.kind}(${JSON.stringify(e.key)})`;case`set`:{let t=[JSON.stringify(e.key),e.keepValue?`value`:Wf(e.value)];return e.ttl!==void 0&&e.ttl!==null&&t.push(JSON.stringify(e.ttl)),`set(${t.join(`, `)})`}}}function Wf(e){if(typeof e==`object`&&e)try{return JSON.stringify(e,null,2)??`null`}catch{return`null`}try{return JSON.stringify(e)??`null`}catch{return`null`}}function Gf(e,t,n,r){let i=e?.stores?.[t]?.tables?.[n];return i?.columns?Kf(i.columns,r):[]}function Kf(e,t){return Object.entries(e).map(([e,n])=>qf(e,n,t?.[e]))}function qf(e,t,n){let r=Xf(t)?t:null,i=Yf(r),a=r?.nullable===!1||r?.primaryKey===!0,o=n??(typeof r?.description==`string`?r.description:void 0);return{path:`/${e}`,name:e,type:i,required:a,...r?.enumValues!==void 0&&r.enumValues.length>0?{enumValues:[...r.enumValues]}:{},...o===void 0?{}:{description:o},...t.pii===!0?{pii:!0}:{},...t.sensitive===!0?{sensitive:!0}:{},...r?.searchable?{searchable:!0,searchWeight:r.searchable.weight}:{},...r?.embed?{embed:!0,embedDims:r.embed.dims}:{},...r?.primaryKey===!0?{primaryKey:!0}:{},...r?.unique===!0&&r.primaryKey!==!0?{unique:!0}:{},...r?.references?.table?{foreignKey:!0,references:{table:r.references.table,...r.references.column===void 0?{}:{column:r.references.column}}}:{}}}var Jf=new Set([`smallint`,`integer`,`bigint`,`serial`,`smallserial`,`bigserial`,`real`,`doublePrecision`]);function Yf(e){let t=e?.type;return t===void 0?`unknown`:t===`boolean`?`boolean`:Jf.has(t)?t===`real`||t===`doublePrecision`?`number`:`integer`:t===`json`||t===`jsonb`?`object`:`string`}function Xf(e){return`type`in e||`nullable`in e||`primaryKey`in e||`unique`in e||`sqlName`in e||`description`in e||`references`in e||`default`in e}function Zf(e,t,n){if(e){let r=Gf(n,e.name,t.name,t.columnDescriptions);if(r.length>0)return r}let r=ke(t.piiColumns);return[...new Set([...Object.keys(t.columnDescriptions),...t.piiColumns])].map(e=>({path:`/${e}`,name:e,type:`unknown`,required:!1,...t.columnDescriptions[e]===void 0?{}:{description:t.columnDescriptions[e]},...r.has(e)?{pii:!0}:{}}))}function Qf(e){let t=new Map;for(let n of e)if(n&&typeof n==`object`&&!Array.isArray(n))for(let[e,r]of Object.entries(n))t.has(e)||t.set(e,$f(r));return[...t.entries()].map(([e,t])=>({name:e,type:t}))}function $f(e){return e==null?`unknown`:Array.isArray(e)?`array`:typeof e==`object`?`object`:typeof e==`number`?Number.isInteger(e)?`integer`:`number`:typeof e==`boolean`?`boolean`:typeof e==`string`?`string`:`unknown`}function ep(e,t){if(!e)return[];let n=new Map(e.facet===`sql`?Tn([e],t).map(e=>[e.name,e]):[]);return e.children.filter(e=>!Kn(e)).map(r=>({name:r.name,columns:Zf(e,r,t).map(e=>{let t=n.get(r.name)?.columns.find(t=>t.name===e.name);return{name:e.name,type:e.type,...e.pii===!0?{pii:!0}:{},...e.primaryKey===!0||t?.primaryKey===!0?{primaryKey:!0}:{},...t?.unique===!0?{unique:!0}:{},...t?.references?{references:t.references,...t.inferredRef===!0?{inferredRef:!0}:{}}:{}}})}))}function tp({store:e,facet:t,manifest:n,onPickTable:r,onPickColumn:i,onCollapse:a,tenant:o=null,tenancyDeclared:s=!1}){let c=e?.children??[],l=t===`sql`,u=(0,Z.useMemo)(()=>ep(e,n),[e,n]);return(0,Q.jsxs)(`aside`,{className:`flex h-full min-h-0 w-56 shrink-0 flex-col overflow-hidden border-l border-border/60`,"data-slot":`store-query-schema-panel`,children:[(0,Q.jsxs)(`header`,{className:S(we,`justify-between px-2`),children:[(0,Q.jsx)(`p`,{className:S(Te,`min-w-0 truncate font-mono`),children:l?`Schema`:`Namespaces`}),a?(0,Q.jsx)(J,{label:`Collapse schema`,className:`flex self-stretch`,children:(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Collapse schema`,"data-slot":`store-query-schema-collapse`,onClick:a,className:R,children:(0,Q.jsx)(b,{icon:ut,className:`size-3.5`})})}):null]}),(0,Q.jsx)(`ul`,{className:`min-h-0 flex-1 overflow-y-auto`,children:c.length===0?(0,Q.jsx)(`li`,{className:`px-2 py-4 text-[11px] text-muted-foreground`,children:`No resources.`}):c.map(a=>(0,Q.jsx)(np,{store:e,child:a,facet:t,manifest:n,sqlColumns:u.find(e=>e.name===a.name)?.columns,onPickTable:r,onPickColumn:i,tenant:o,tenancyDeclared:s},a.effectRef))})]})}function np({store:e,child:t,facet:n,manifest:r,sqlColumns:i,onPickTable:a,onPickColumn:o,tenant:s,tenancyDeclared:c}){let l=n===`sql`,[u,d]=(0,Z.useState)(!0),f=i??Zf(e,t,r),p=!l||f.length>0;return(0,Q.jsxs)(`li`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center`,children:[p?(0,Q.jsx)(`button`,{type:`button`,"aria-expanded":u,"aria-label":`${u?`Collapse`:`Expand`} ${t.name}`,onClick:()=>d(e=>!e),className:_e,children:(0,Q.jsx)(b,{icon:et,className:S(`size-3 transition-transform`,!u&&`-rotate-90`)})}):(0,Q.jsx)(`span`,{className:`size-6`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>a(t.name),className:`min-w-0 flex-1 truncate px-2 py-1.5 text-left font-mono text-[11px] text-foreground hover:bg-muted/50`,title:l?`SELECT * FROM "${t.name}"`:`list ${t.name}:`,children:t.name})]}),l&&u&&f.length>0?(0,Q.jsx)(`ul`,{className:`border-l border-border/60 ml-3`,children:f.map(e=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>o(t.name,e.name),className:`flex w-full items-center gap-1.5 px-2 py-1 text-left hover:bg-muted/50`,children:[(0,Q.jsx)(Ae,{primaryKey:e.primaryKey,foreignKey:`references`in e&&e.references!==void 0,unique:`unique`in e?e.unique:void 0,inferred:`inferredRef`in e?e.inferredRef:void 0}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[10px] text-muted-foreground`,children:e.name}),`references`in e&&e.references?.table?(0,Q.jsxs)(`span`,{className:`max-w-[4rem] shrink-0 truncate font-mono text-[8px] text-muted-foreground`,children:[`→ `,e.references.table]}):null,(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[9px] tracking-wide text-muted-foreground/70 uppercase`,children:e.type===`unknown`?``:e.type}),e.pii?(0,Q.jsx)(`span`,{className:`shrink-0 rounded border border-sky-500/30 px-1 text-[8px] text-sky-700 dark:text-sky-400`,children:`PII`}):null]})},e.name))}):null,!l&&u&&e?(0,Q.jsx)(rp,{store:e,namespace:t.name,tenant:s,tenancyDeclared:c,onPickField:e=>o(t.name,e)}):null]})}function rp({store:e,namespace:t,tenant:n,tenancyDeclared:r,onPickField:i}){let a=!r||n!==null&&n.length>0,o=cr({ref:e.ref,child:t,prefix:`${t}:`,limit:40,...n?{tenant:n}:{}},a),s=Qf((o.data?.keys??[]).map(e=>e.value));return(0,Q.jsx)(`ul`,{className:`ml-3 border-l border-border/60`,children:a?o.isPending?(0,Q.jsx)(`li`,{className:`px-1.5 py-1 font-mono text-[10px] text-muted-foreground`,children:`Loading…`}):o.isError?(0,Q.jsx)(`li`,{className:`px-1.5 py-1 font-mono text-[10px] text-destructive`,children:`Couldn’t read fields.`}):s.length===0?(0,Q.jsx)(`li`,{className:`px-1.5 py-1 font-mono text-[10px] text-muted-foreground`,children:`No fields.`}):s.map(e=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>i(e.name),className:`flex w-full items-center gap-1.5 px-2 py-1 text-left hover:bg-muted/50`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[10px] text-muted-foreground`,children:e.name}),(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[9px] tracking-wide text-muted-foreground/70 uppercase`,children:e.type===`unknown`?``:e.type})]})},e.name)):(0,Q.jsx)(`li`,{className:`px-1.5 py-1 font-mono text-[10px] text-muted-foreground`,children:`Select a tenant.`})})}function ip({facet:e,onExpand:t}){let n=e===`sql`?`Schema`:`Fields`;return(0,Q.jsx)(J,{label:`Expand ${n.toLowerCase()}`,className:`h-full`,children:(0,Q.jsxs)(`button`,{type:`button`,"aria-label":`Expand ${n.toLowerCase()}`,"data-slot":`store-query-schema-expand`,onClick:t,className:`flex h-full w-7 shrink-0 flex-col items-center gap-2 border-l border-border/60 py-2 text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:[(0,Q.jsx)(b,{icon:at,className:`size-3.5`}),(0,Q.jsx)(`span`,{className:`font-mono text-[10px] font-semibold tracking-[0.08em] uppercase [writing-mode:vertical-rl]`,children:n})]})})}function ap({facet:e,stores:t,selectedEffectRef:n,tenancyDeclared:r,tenants:i,tenant:a,onTenantChange:o,manifest:s=null,leading:c}){let l=oa[e],u=(0,Z.useMemo)(()=>t.filter(t=>t.facet===e),[t,e]),[d,f]=(0,Z.useState)(()=>hd(t,e,n)?.ref??u[0]?.ref??``),p=u.find(e=>e.ref===d)??hd(u,e,null),m=lp(p,e,n),h=p?.children.map(e=>e.name)??[],[g,_]=(0,Z.useState)(()=>cp(Sf(e)??[{id:`q_1`,title:`Query 1`,text:m}],h,e)),[v,y]=(0,Z.useState)(()=>g[0]?.id??`q_1`),x=g.find(e=>e.id===v)??g[0],C=x?.text??m,[w,T]=(0,Z.useState)(null),[E,O]=(0,Z.useState)(null),[k,A]=(0,Z.useState)(null),[j,M]=(0,Z.useState)(null),[N,P]=(0,Z.useState)(!1),[F,I]=(0,Z.useState)(!1),[z,B]=(0,Z.useState)(!0),[V,H]=(0,Z.useState)({asGate:null,asUserId:null}),[ee,ne]=(0,Z.useState)(!0),[re,U]=(0,Z.useState)(()=>wf(e)),[ie,oe]=(0,Z.useState)(()=>Ef(e)),[ce,le]=(0,Z.useState)(!1),[ue,de]=(0,Z.useState)(null),[W,fe]=(0,Z.useState)(``),[me,he]=(0,Z.useState)({start:0,end:0}),[ge,_e]=(0,Z.useState)([]),[ye,be]=(0,Z.useState)(0),[xe,Se]=(0,Z.useState)(!1),Ce=(0,Z.useRef)(null),Ee=(0,Z.useRef)(!1),De=(0,Z.useRef)(null),ke=Qo(),K=te(),Ae=!r||a!==null&&a.length>0,je=p?vd(p.ref):!1,q=e===`sql`,Me=ni(`Enter`),Pe=ni(`S`),Fe=(0,Z.useMemo)(()=>ep(p,s),[p,s]),Ie=(0,Z.useMemo)(()=>q?kt(C):[],[q,C]),Le=(0,Z.useMemo)(()=>Ie.map(e=>e.startLine),[Ie]),Re=me.end!==me.start,Be=(0,Z.useMemo)(()=>q?Pt(C,me.start,me.end,`current`):[C],[me.end,me.start,q,C]),Ve=q&&Be.some(e=>Ot(e));(0,Z.useEffect)(()=>{let r=hd(t,e,n);r&&f(e=>u.some(t=>t.ref===e)?e:r.ref)},[t,e,n,u]);let He=h.join(`\0`);(0,Z.useEffect)(()=>{let t=He.length===0?[]:He.split(`\0`);t.length!==0&&_(n=>cp(n,t,e))},[He,e]),(0,Z.useEffect)(()=>{Cf(e,g)},[e,g]),(0,Z.useEffect)(()=>{Df(e,ie)},[e,ie]),(0,Z.useEffect)(()=>()=>{De.current!==null&&window.clearTimeout(De.current)},[]);let Ue=e=>{x&&_(t=>_f(t,x.id,e))},We=t=>{U(n=>{let r=bf(n,t);return Tf(e,r),r})},Ke=e=>{let t=Math.max(0,Date.now()-e.started);_e([]),be(0),T(e.nextRows),O(e.nextMeta?`${e.nextMeta} · ${t}ms`:`${t}ms`),A(e.sqlText),M(e.nextError),We({at:Date.now(),storeRef:p?.ref??``,text:e.sqlText,ok:e.nextError===null,rowCount:e.nextRows?.length??null,durationMs:t,...e.nextError?{error:e.nextError}:{}})},qe=(e,t)=>{let n=e[t];_e(e),be(t),T(n?.rows??null),M(n?.error??null),O(n?.meta??null),A(n?.executed??e.map(e=>e.executed).join(`
40
+ `)??null)},Je=(e,t=!z,n=V)=>{if(!p)return;if(ne(!0),M(null),!Ae){M(`Select a tenant first.`);return}if(je){M(`oke_console is the operator-plane auth schema — read-only from Store browse.`);return}let r=e.map(e=>e.trim()).filter(e=>e.length>0);if(r.length===0){M(`Nothing to run.`);return}let i=Date.now();Se(!0),_e([]),be(0),(async()=>{try{let e=[],o=!1;for(let i of r){let r=Et(i);r&&(o=!0);try{let o=await ke.mutateAsync({ref:p.ref,sql:i,...r?{allowWrite:!0}:{},...t?{revealPii:!0}:{},...n.asGate?{asGate:n.asGate}:{},...n.asUserId?{asUserId:n.asUserId}:{},...a?{tenant:a}:{}}),s=sp(o.rows),c=[s===null?`${o.rows.length} row${o.rows.length===1?``:`s`}`:`${s} change${s===1?``:`s`}`,`routed ${o.routedRole}`];if(o.masked?c.push(`PII masked`):t&&c.push(`PII visible`),o.rls?.gate??o.asGate){let e=o.rls?.userId?`${o.rls.gate} / ${o.rls.userId}`:o.rls?.gate??o.asGate;c.push(o.gateApplied||o.rls?.applied?`as ${e}`:`as ${e} (not applied)`)}e.push({label:dn(i),rows:o.rows,error:null,meta:c.join(` · `),executed:i})}catch(t){e.push({label:dn(i),rows:null,error:t instanceof Error?t.message:String(t),meta:null,executed:i});break}}o&&K.invalidateQueries({queryKey:_r});let s=Math.max(0,Date.now()-i),c=e[e.length-1],l=r.join(`
41
+ `);qe(e.map(e=>({...e,meta:e.meta?`${e.meta} · ${s}ms`:e.error?null:`${s}ms`})),Math.max(0,e.length-1)),We({at:Date.now(),storeRef:p.ref,text:l,ok:c?.error==null,rowCount:e.reduce((e,t)=>e+(t.rows?.length??0),0),durationMs:s,...c?.error?{error:c.error}:{}})}finally{Se(!1)}})()},Ye=(e,t=!z,n=V)=>{if(!p)return;if(ne(!0),M(null),!Ae){M(`Select a tenant first.`);return}if(q){Je([e],t,n);return}let r=Date.now(),i=Zd(e);if(i.kind===`error`){M(i.message);return}P(!0);let o=a?{tenant:a}:{};(async()=>{try{if(i.kind===`delete`){let t=await L({ref:p.ref,keys:[i.key],...o});if(t.error){Ke({sqlText:e,nextRows:null,nextMeta:null,nextError:op(t.error),started:r});return}await K.invalidateQueries({queryKey:_r});let n=t.data?.deleted??0;Ke({sqlText:e,nextRows:[{key:i.key,deleted:n}],nextMeta:n>0?`delete ${i.key}`:`delete ${i.key} · missing`,nextError:null,started:r});return}if(i.kind===`set`){let t=await se({ref:p.ref,key:i.key,...o,patch:Qd(i),commit:!0});if(t.error){Ke({sqlText:e,nextRows:null,nextMeta:null,nextError:op(t.error),started:r});return}await K.invalidateQueries({queryKey:_r})}let t=i.kind===`list`?i.prefix:i.key,n=await pe({ref:p.ref,prefix:t,limit:i.kind===`list`?200:1,...o});if(n.error){Ke({sqlText:e,nextRows:null,nextMeta:null,nextError:op(n.error),started:r});return}let a=n.data?.keys??[],s=i.kind===`list`?a:a.filter(e=>e.key===i.key);if(i.kind===`ttl`){let t=s[0];Ke({sqlText:e,nextRows:[{key:i.key,ttlMs:t?.ttlMs??null,ttl:Xt(t?.ttlMs??null)}],nextMeta:t?`ttl ${i.key}`:`ttl ${i.key} · missing`,nextError:null,started:r});return}let c=s.length>0?s.map(e=>({key:e.key,value:e.value??null,ttlMs:e.ttlMs??null,sizeBytes:e.sizeBytes??null})):i.kind===`set`&&!i.keepValue?[{key:i.key,value:i.value??null,ttlMs:null,sizeBytes:null}]:[];Ke({sqlText:e,nextRows:c,nextMeta:i.kind===`set`?`set ${i.key}`:`${c.length} key${c.length===1?``:`s`}`,nextError:null,started:r})}finally{P(!1)}})()},Qe=()=>{if(q){Je(Be);return}let e=Math.min(me.start,me.end),t=Math.max(me.start,me.end);Ye(t>e?C.slice(e,t):C)},$e=()=>{Je(Pt(C,me.start,me.end,`all`))},tt=e=>{Je(Be.map(t=>St(t,e)))},rt=e=>{let t=Ie.find(t=>t.startLine===e);t&&Je([t.text])},it=t=>{let n=u.find(e=>e.ref===t);f(t),x&&_(t=>_f(t,x.id,lp(n,e,null))),T(null),O(null),A(null),M(null),_e([]),be(0)},at=e=>{Ue(q?cd(e):md(`${e}:`))},ot=()=>{let t=hf(g,lp(p,e,null)),n=t[t.length-1];n&&t!==g&&(_(t),y(n.id))},st=e=>{pf(e.title)||(oe(t=>yf(t,{id:e.id,title:e.title,text:e.text})),le(!0),De.current!==null&&window.clearTimeout(De.current),De.current=window.setTimeout(()=>le(!1),1200))},ct=(e,t)=>{let n=vf(g,e,t);if(_(n),de(null),!Ee.current)return;Ee.current=!1;let r=n.find(t=>t.id===e);r&&st(r)},lt=()=>{Ee.current=!1,de(null)},ut=e=>{y(e.id),de(e.id),fe(e.title)},dt=()=>{if(x){if(pf(x.title)){Ee.current=!0,ut(x);return}st(x)}},ft=e=>{if(g.find(t=>t.id===e.id)){_(t=>_f(vf(t,e.id,e.title),e.id,e.text)),y(e.id);return}if(g.length>=8){if(!x)return;_(t=>_f(vf(t,x.id,e.title),x.id,e.text));return}let t=[...g,{id:e.id,title:e.title,text:e.text}];_(t),y(e.id)},pt=e=>{ue===e&&lt();let t=gf(g,e,m);_(t),v===e&&y(t[t.length-1]?.id??t[0]?.id??`q_1`)},mt=q?ke.isPending||xe:N,ht=oi(`Enter`);return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`store-query-console`,onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&e.key===`s`&&(e.preventDefault(),dt())},children:[(0,Q.jsx)(xi,{dataSlot:`store-query-header`,className:`relative z-30`,leading:c,icon:(0,Q.jsx)(b,{icon:l.icon,className:`size-4`}),wellClassName:l.wellClass,title:q?`SQL Query`:`KV Query`,badge:(0,Q.jsx)(`span`,{className:`font-mono text-[10px] font-medium tracking-[0.08em] text-muted-foreground`,children:p?.ref??`No store`}),subtitle:(0,Q.jsxs)(`span`,{className:`truncate font-mono text-[11px] leading-none text-muted-foreground`,children:[q?`DML / DDL`:`list / get / set / delete / ttl`,Re?` · selection${Be.length>1?` (${Be.length})`:``}`:q?Ie.length>1?` · ${Ie.length} statements`:` · current statement`:``]}),actions:(0,Q.jsxs)(Q.Fragment,{children:[u.length>1?(0,Q.jsxs)(`div`,{className:`flex h-full items-stretch`,"data-slot":`store-query-store`,children:[(0,Q.jsx)(`span`,{className:S(Te,`flex items-center px-2`),children:`Store`}),(0,Q.jsxs)(ka,{value:p?.ref??``,onValueChange:it,className:`z-40 inline-flex h-full min-w-[8rem]`,children:[(0,Q.jsx)(Aa,{flat:!0,"aria-label":`Query store`,className:`h-full w-auto px-2 font-mono text-[11px] hover:bg-muted/50`,children:(0,Q.jsx)(ja,{})}),(0,Q.jsx)(Ma,{children:u.map(e=>(0,Q.jsx)(Na,{value:e.ref,className:`font-mono text-[11px]`,children:e.name},e.ref))})]})]}):null,r?(0,Q.jsx)(`div`,{className:`flex h-full items-stretch`,"data-slot":`store-query-tenant`,children:(0,Q.jsxs)(ka,{value:a??``,onValueChange:e=>o(e.length>0?e:null),className:`z-40 inline-flex h-full min-w-[8rem]`,children:[(0,Q.jsx)(Aa,{flat:!0,"aria-label":`Tenant`,className:`h-full w-auto px-2 font-mono text-[11px] hover:bg-muted/50`,children:(0,Q.jsx)(ja,{placeholder:`Select tenant…`})}),(0,Q.jsx)(Ma,{children:i.map(e=>(0,Q.jsx)(Na,{value:e,className:`font-mono text-[11px]`,children:e},e))})]})}):null]})}),(0,Q.jsxs)(`div`,{className:`${we} overflow-x-auto`,role:`tablist`,"aria-label":`Query tabs`,children:[g.map(e=>(0,Q.jsxs)(`div`,{className:S(`group/tab flex h-full items-center gap-0.5 border-b-2 px-1`,e.id===v?`border-foreground text-foreground`:`border-transparent text-muted-foreground`),children:[ue===e.id?(0,Q.jsx)(`input`,{autoFocus:!0,value:W,maxLength:48,"aria-label":`Rename query`,"data-slot":`store-query-tab-rename`,onFocus:e=>e.currentTarget.select(),onChange:e=>fe(e.target.value),onBlur:()=>ct(e.id,W),onKeyDown:t=>{t.key===`Enter`&&(t.preventDefault(),ct(e.id,W)),t.key===`Escape`&&(t.preventDefault(),lt())},className:`h-5 min-w-[4.5rem] bg-transparent px-1.5 font-mono text-[11px] text-foreground outline-none`,style:{width:`${Math.max(6,W.length+1)}ch`}}):(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":e.id===v,title:`Double-click to rename`,"data-slot":`store-query-tab`,onClick:()=>y(e.id),onDoubleClick:t=>{t.preventDefault(),ut(e)},className:`max-w-[12rem] truncate px-1.5 font-mono text-[11px]`,children:e.title}),ie.some(t=>t.id===e.id)?(0,Q.jsx)(`span`,{className:`size-1 shrink-0 rounded-full bg-foreground/50`,"aria-label":`Saved`,title:`Saved`}):null,(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Close ${e.title}`,onClick:()=>pt(e.id),className:`flex size-4 items-center justify-center rounded-sm opacity-0 hover:bg-muted group-hover/tab:opacity-100`,children:(0,Q.jsx)(b,{icon:ae,className:`size-2.5`})})]},e.id)),(0,Q.jsx)(J,{label:`New query`,className:`flex self-stretch`,children:(0,Q.jsx)(`button`,{type:`button`,"aria-label":`New query`,disabled:g.length>=8,onClick:ot,"data-slot":`store-query-tab-add`,className:R,children:(0,Q.jsx)(b,{icon:Er,className:`size-3.5`})})})]}),(0,Q.jsxs)(`div`,{className:we,children:[(0,Q.jsxs)(G,{type:`button`,variant:`ghost`,size:`sm`,className:`h-full rounded-none px-2 text-[11px]`,onClick:()=>Ue(q?Rt(C):Vf(C)),"data-slot":`store-query-prettify`,children:[(0,Q.jsx)(b,{icon:Ze,"data-icon":`inline-start`,className:`size-3.5`}),`Prettify`]}),(0,Q.jsx)(J,{label:ce?`Saved`:`Save`,keys:Pe,className:`flex self-stretch`,children:(0,Q.jsxs)(G,{type:`button`,variant:`ghost`,size:`sm`,className:`h-full rounded-none px-2 text-[11px]`,onClick:dt,"data-slot":`store-query-save`,children:[(0,Q.jsx)(b,{icon:ce?D:ki,"data-icon":`inline-start`,className:`size-3.5`}),ce?`Saved`:`Save`]})}),(0,Q.jsx)(up,{entries:re,saved:ie,onPick:e=>{Ue(e.text),Ce.current?.focus()},onPickSaved:e=>{ft(e),Ce.current?.focus()}}),(0,Q.jsxs)(G,{type:`button`,variant:`ghost`,size:`sm`,className:S(`h-full rounded-none px-2 text-[11px]`,F&&`text-foreground`),"aria-pressed":F,onClick:()=>I(e=>!e),"data-slot":`store-query-schema`,children:[(0,Q.jsx)(b,{icon:Xe,"data-icon":`inline-start`,className:`size-3.5`}),q?`Schema`:`Keys`]}),q?(0,Q.jsx)(J,{label:z?`PII hidden. Click to include cleartext (audited).`:`PII included. Click to remask.`,className:`flex self-stretch`,children:(0,Q.jsxs)(G,{type:`button`,variant:`ghost`,size:`sm`,className:S(`h-full rounded-none px-2 text-[11px]`,!z&&`text-amber-800 dark:text-amber-300`),"aria-pressed":!z,"aria-label":z?`Include PII: disabled`:`Include PII: enabled`,onClick:()=>{let e=!z;B(e),k&&!Et(k)&&Ye(k,!e)},"data-slot":`store-query-pii`,children:[(0,Q.jsx)(b,{icon:z?ri:li,"data-icon":`inline-start`,className:`size-3.5`}),`PII`]})}):null,q?(0,Q.jsx)(Mu,{manifest:s,value:V,onChange:e=>{H(e),k&&!Et(k)&&Ye(k,!z,e)}}):null,Ve?(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 text-[10px] text-amber-800 dark:text-amber-300`,title:`This SELECT has no LIMIT`,"data-slot":`store-query-unbounded`,children:[(0,Q.jsx)(b,{icon:nt,className:`size-3`}),`No LIMIT`]}):null,(0,Q.jsx)(`span`,{className:`flex-1`}),(0,Q.jsxs)(`div`,{className:`flex items-stretch`,children:[(0,Q.jsx)(J,{label:Re?`Run selection`:`Run`,keys:Me,className:`flex self-stretch`,children:(0,Q.jsxs)(G,{type:`button`,size:`sm`,className:`h-full gap-1.5 rounded-none`,disabled:!p||mt,onClick:Qe,"data-slot":`store-query-run`,children:[mt?(0,Q.jsx)(b,{icon:Jr,className:`size-3.5 animate-spin`}):(0,Q.jsx)(b,{icon:Oe,className:`size-3.5`}),Re?`Run selection`:`Run`]})}),q?(0,Q.jsxs)(Ir,{children:[(0,Q.jsx)(kr,{render:e=>(0,Q.jsx)(G,{...e,type:`button`,size:`sm`,className:`h-full rounded-none border-l border-primary-foreground/20 px-1.5`,disabled:!p||mt,"aria-label":`More run options`,"data-slot":`store-query-run-menu`,children:(0,Q.jsx)(b,{icon:et,className:`size-3.5`})})}),(0,Q.jsxs)(Pr,{align:`end`,className:`w-56`,children:[(0,Q.jsxs)(Ar,{children:[(0,Q.jsxs)(Dr,{onClick:Qe,children:[`Run current`,(0,Q.jsx)(Lr,{children:(0,Q.jsx)(ve,{keys:Me})})]}),(0,Q.jsxs)(Dr,{onClick:$e,disabled:Ie.length<2,children:[`Run all`,(0,Q.jsx)(Lr,{children:(0,Q.jsx)(ve,{keys:ht})})]})]}),(0,Q.jsx)(jr,{}),(0,Q.jsxs)(Ar,{children:[(0,Q.jsx)(Dr,{onClick:()=>tt(!1),children:`EXPLAIN`}),(0,Q.jsx)(Dr,{onClick:()=>tt(!0),children:`EXPLAIN ANALYZE`})]})]})]}):null]})]}),(0,Q.jsxs)(Ne,{orientation:`vertical`,className:`min-h-0 flex-1`,children:[(0,Q.jsx)(ze,{defaultSize:`72%`,minSize:`18%`,className:`min-h-0 overflow-hidden`,children:(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0`,children:[(0,Q.jsx)(jt,{value:C,onChange:Ue,language:q?`sql`:`kv`,onRun:Qe,onRunAll:q?$e:void 0,onRunLine:q?rt:void 0,runLines:Le,onCursorChange:(e,t)=>he({start:e,end:t}),editorRef:Ce,label:q?`SQL query`:`KV command`,tables:Fe,facet:e}),F?(0,Q.jsx)(tp,{store:p,facet:e,manifest:s,tenant:a,tenancyDeclared:r,onPickTable:at,onPickColumn:(e,t)=>{Ce.current?.insert(q?`"${t}"`:t)},onCollapse:()=>I(!1)}):(0,Q.jsx)(ip,{facet:e,onExpand:()=>I(!0)})]})}),ee?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Ge,{withHandle:!0,className:`justify-end pr-8`}),(0,Q.jsx)(ze,{defaultSize:`28%`,minSize:`20%`,className:`min-h-0 overflow-hidden`,children:(0,Q.jsx)($t,{rows:w,error:j,pending:mt,meta:E,executed:k,executedLanguage:q?`sql`:`kv`,storeRef:p?.ref,sets:ge,activeSet:ye,onSelectSet:e=>qe(ge,e),onToggleCollapse:()=>ne(!1)})})]}):null]}),ee?null:(0,Q.jsx)($t,{rows:w,error:j,pending:mt,meta:E,executed:k,executedLanguage:q?`sql`:`kv`,storeRef:p?.ref,sets:ge,activeSet:ye,onSelectSet:e=>qe(ge,e),collapsed:!0,onToggleCollapse:()=>ne(!0)})]})}function op(e){let t=e.data;return(t&&typeof t==`object`&&`ref`in t&&typeof t.ref==`string`?t.ref:null)??e.message??e.code}function sp(e){if(e.length!==1)return null;let t=e[0]?.changes;return typeof t==`number`&&Number.isFinite(t)?t:null}function cp(e,t,n){let r=!1,i=e.map(e=>{let i=pd(e.text,t,n);return i===e.text?e:(r=!0,{...e,text:i})});return r?i:e}function lp(e,t,n){if(!e)return t===`sql`?cd():md();let r=(n?e.children.find(e=>e.effectRef===n)?.name:void 0)??_d(e);return t===`sql`?cd(r):md(r?`${r}:`:void 0)}function up({entries:e,saved:t,onPick:n,onPickSaved:r}){return(0,Q.jsxs)(Ir,{children:[(0,Q.jsx)(kr,{render:e=>(0,Q.jsxs)(G,{...e,type:`button`,variant:`ghost`,size:`sm`,className:`h-full rounded-none px-2 text-[11px]`,"data-slot":`store-query-history`,children:[(0,Q.jsx)(b,{icon:Ye,"data-icon":`inline-start`,className:`size-3.5`}),`History`]})}),(0,Q.jsxs)(Pr,{align:`start`,className:`w-80`,children:[(0,Q.jsxs)(Ar,{children:[(0,Q.jsx)(Nr,{className:`font-mono text-[10px] tracking-[0.12em] uppercase`,children:`Saved`}),(0,Q.jsx)(jr,{}),t.length===0?(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:`Save a named query to keep it across sessions.`}):t.map(e=>(0,Q.jsxs)(Dr,{className:`flex flex-col items-start gap-0.5 py-1.5`,onClick:()=>r(e),children:[(0,Q.jsx)(`span`,{className:`w-full truncate text-[11px]`,children:e.title}),(0,Q.jsx)(`span`,{className:`w-full truncate font-mono text-[10px] text-muted-foreground`,children:xf(e.text)})]},e.id))]}),(0,Q.jsx)(jr,{}),(0,Q.jsxs)(Ar,{children:[(0,Q.jsx)(Nr,{className:`font-mono text-[10px] tracking-[0.12em] uppercase`,children:`Recent runs`}),(0,Q.jsx)(jr,{}),e.length===0?(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:`No runs this session.`}):e.map(e=>(0,Q.jsxs)(Dr,{className:`flex flex-col items-start gap-0.5 py-1.5`,onClick:()=>n(e),children:[(0,Q.jsx)(`span`,{className:`w-full truncate font-mono text-[11px]`,children:xf(e.text)}),(0,Q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.ok?`${e.rowCount??0} · ${e.durationMs}ms`:e.error??`failed`})]},e.id))]})]})]})}var dp=`#38BDF8`,fp=[`#38BDF8`,`#34D399`,`#FBBF24`,`#A78BFA`,`#FB7185`,`#22D3EE`,`#F472B6`,`#4ADE80`,`#F59E0B`,`#818CF8`];function pp(e){let t=new Set(e.map(e=>e.name)),n=new Map;for(let r of e)n.set(r.name,vp(r,t));return n}function mp(e){let t=pp(e),n=[...new Set(t.values())].sort(),r=new Map;for(let[e,t]of n.entries())r.set(t,fp[e]??Cp(t));let i=new Map;for(let n of e){let e=t.get(n.name)??Sp(n.name);i.set(n.id,{cluster:e,hex:r.get(e)??`#38BDF8`})}return i}function hp(e,t){let n=t?mp(e.tables):new Map(e.tables.map(e=>[e.id,{cluster:`schema`,hex:dp}])),r=new Map;for(let t of e.tables){let e=n.get(t.id)?.hex;e&&r.set(t.name,e)}return{...e,nodes:e.nodes.map(e=>gp(e,n.get(e.id),r)),edges:e.edges.map(e=>_p(e,n.get(e.target)))}}function gp(e,t,n){let r=t??{cluster:`schema`,hex:`#38BDF8`},i={};for(let t of e.data.table.columns){let e=t.references?.table,r=e?n.get(e):void 0;r&&(i[t.name]=r)}return{...e,data:{...e.data,color:r,...Object.keys(i).length>0?{refHex:i}:{}}}}function _p(e,t){let n=t?.hex??`#38BDF8`,r=e.data?.inferred===!0;return{...e,markerEnd:{type:s.ArrowClosed,width:16,height:16,color:n},style:{stroke:n,strokeWidth:1.5,...r?{strokeDasharray:`5 4`}:{}},data:{kind:`references`,inferred:r,relation:e.data?.relation??`many-to-one`,column:e.data?.column??``,hex:n}}}function vp(e,t){let n=yp(e.name,t);if(n)return n;if(bp(e.name,t))return Sp(e.name);let r=e.columns.filter(t=>t.references?.table&&t.references.table!==e.name);if(r.length===1){let e=r[0]?.references?.table;if(e)return yp(e,t)??Sp(e)}return Sp(e.name)}function yp(e,t){let n=e.split(`_`)[0];if(!n||n===e)return null;for(let r of[n,`${n}s`,xp(n)])if(t.has(r)&&r!==e)return Sp(r);return null}function bp(e,t){let n=Sp(e);for(let r of t)if(r!==e&&yp(r,t)===n)return!0;return!1}function xp(e){return e.endsWith(`y`)&&!/[aeiou]y$/i.test(e)?`${e.slice(0,-1)}ies`:/(?:s|x|z|ch|sh)$/i.test(e)?`${e}es`:`${e}s`}function Sp(e){return e.endsWith(`ies`)&&e.length>3?`${e.slice(0,-3)}y`:/(?:ses|xes|zes|ches|shes)$/i.test(e)?e.slice(0,-2):e.endsWith(`s`)&&!e.endsWith(`ss`)&&e.length>1?e.slice(0,-1):e}function Cp(e){let t=0;for(let n=0;n<e.length;n+=1)t=t*31+(e.codePointAt(n)??0)>>>0;return`hsl(${t%360} 70% 62%)`}var wp={"many-to-one":`Many-to-one`,"one-to-one":`One-to-one`,"many-to-many":`Many-to-many`,self:`Self`};function Tp({kind:e,className:t,hex:n}){return(0,Q.jsx)(`svg`,{viewBox:`0 0 24 24`,className:S(`size-3.5 shrink-0`,!n&&`text-muted-foreground`,t),style:n?{color:n}:void 0,"aria-label":wp[e],fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,Q.jsx)(Ep,{kind:e})})}function Ep({kind:e}){return e===`one-to-one`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`path`,{d:`M6 7 V17`}),(0,Q.jsx)(`path`,{d:`M6 12 H18`}),(0,Q.jsx)(`path`,{d:`M18 7 V17`})]}):e===`many-to-many`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`path`,{d:`M3 6 L10 12 L3 18`}),(0,Q.jsx)(`path`,{d:`M10 12 H14`}),(0,Q.jsx)(`path`,{d:`M21 6 L14 12 L21 18`})]}):e===`self`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`path`,{d:`M8 16.5 A5.5 5.5 0 1 1 16.5 16.2`}),(0,Q.jsx)(`path`,{d:`M14.2 13.6 L16.5 16.4 L18.9 13.7`})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`path`,{d:`M3 6 L10 12 L3 18`}),(0,Q.jsx)(`path`,{d:`M10 12 H16`}),(0,Q.jsx)(`path`,{d:`M16 7 V17`}),(0,Q.jsx)(`path`,{d:`M16 12 H21`})]})}function Dp({id:e,sourceX:t,sourceY:n,targetX:r,targetY:i,sourcePosition:a,targetPosition:o,style:s,markerEnd:l,data:f}){let[p,m,h]=u({sourceX:t,sourceY:n,sourcePosition:a,targetX:r,targetY:i,targetPosition:o}),g=f?.relation??`many-to-one`,_=f?.column??``,v=`${f?.inferred===!0?`Inferred`:`Declared`} ${Bn(g,_)}`;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(d,{id:e,path:p,markerEnd:l,style:s}),(0,Q.jsx)(c,{children:(0,Q.jsx)(`div`,{className:`nodrag nopan pointer-events-auto absolute`,style:{transform:`translate(-50%, -50%) translate(${m}px,${h}px)`,opacity:typeof s?.opacity==`number`?s.opacity:1},children:(0,Q.jsxs)(w,{children:[(0,Q.jsx)(O,{render:e=>(0,Q.jsx)(`span`,{...e,"aria-label":v,className:`flex items-center justify-center rounded-sm border border-border/60 bg-background/90 p-0.5 shadow-sm`,children:(0,Q.jsx)(Tp,{kind:g,hex:f?.hex})})}),(0,Q.jsx)(T,{side:`top`,className:`text-[11px]`,children:v})]})})})]})}var Op={relation:Dp};function kp({data:e}){let{table:t,showStore:n,dimmed:r,selected:i,color:a,refHex:o}=e,s=a?.hex??`#38BDF8`;return(0,Q.jsxs)(`div`,{"data-slot":`store-schema-table`,"data-table":t.name,"data-cluster":a?.cluster,className:S(`flex h-full w-full flex-col overflow-hidden rounded-lg border bg-card text-[11px] shadow-sm`,r&&`opacity-30 saturate-[0.4]`),style:{borderColor:i?s:`color-mix(in oklab, ${s} 42%, var(--border))`,boxShadow:i?`0 0 0 2px color-mix(in oklab, ${s} 35%, transparent)`:void 0},children:[(0,Q.jsxs)(`div`,{className:`flex h-8 shrink-0 items-center gap-1.5 border-b px-2`,style:{background:`color-mix(in oklab, ${s} 22%, var(--card))`,borderColor:`color-mix(in oklab, ${s} 28%, var(--border))`},children:[(0,Q.jsx)(`span`,{className:`size-2 shrink-0 rounded-full`,style:{background:s},"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate font-semibold text-foreground`,children:t.name}),(0,Q.jsx)(`span`,{"data-slot":`store-schema-rls`,"data-rls":t.rls===!0?`on`:`off`,title:t.rls===!0?`RLS enabled`:`RLS disabled`,className:S(`shrink-0`,t.rls===!0?`text-emerald-500`:`text-muted-foreground/35`),children:(0,Q.jsx)(b,{icon:t.rls===!0?zi:Ri,className:`size-3`,"aria-hidden":!0})}),n?(0,Q.jsx)(`span`,{className:`ml-auto shrink-0 font-mono text-[9px] tracking-[0.08em] text-muted-foreground uppercase`,children:t.storeName}):(0,Q.jsx)(`span`,{className:`ml-auto shrink-0 tabular-nums text-[10px] text-muted-foreground`,children:t.columns.length})]}),(0,Q.jsx)(`ul`,{className:`flex min-h-0 flex-1 flex-col`,children:t.columns.length===0?(0,Q.jsx)(`li`,{className:`relative flex h-[22px] items-center px-2 text-muted-foreground`,children:`No columns`}):t.columns.map(e=>(0,Q.jsx)(Ap,{column:e,tableName:t.name,junction:jp(t.columns),tableHex:s,refHex:o?.[e.name]},e.name))})]})}function Ap({column:e,tableName:t,junction:n,tableHex:r,refHex:a}){let o=a??r,s=e.type===`integer`?`text-teal-600 dark:text-teal-400`:e.type===`text`?`text-muted-foreground`:`text-muted-foreground/80`;return(0,Q.jsxs)(`li`,{className:`relative flex h-[22px] items-center gap-1.5 px-2`,children:[(0,Q.jsx)(i,{type:`target`,position:p.Left,id:`in:${e.name}`,className:`!size-1.5 !border-0`,style:{background:r}}),(0,Q.jsx)(`span`,{className:S(`size-1.5 shrink-0 rounded-full`,e.nullable===!1?`bg-foreground/70`:`border border-foreground/50`),title:e.nullable===!1?`Not null`:`Nullable`,"aria-hidden":!0}),(0,Q.jsx)(Ae,{primaryKey:e.primaryKey,foreignKey:e.references!==void 0,unique:e.unique,inferred:e.inferredRef,hex:o}),(0,Q.jsx)(`span`,{className:S(`min-w-0 truncate font-mono text-[10px]`,!a&&`text-foreground`),style:a?{color:a}:void 0,title:Np(e),children:e.name}),e.references?.table?(0,Q.jsxs)(`span`,{className:`inline-flex max-w-[6rem] shrink-0 items-center gap-0.5 truncate text-muted-foreground`,title:Np(e,t,n),children:[(0,Q.jsx)(Tp,{kind:Mp(e,t,n),hex:o,className:`size-3`}),(0,Q.jsx)(`span`,{className:`truncate font-mono text-[8px]`,children:e.references.table})]}):null,(0,Q.jsx)(`span`,{className:S(`ml-auto shrink-0 font-mono text-[9px]`,s),children:e.type}),e.pii?(0,Q.jsx)(`span`,{className:`shrink-0 rounded border border-border/70 px-1 text-[8px] font-semibold tracking-[0.08em] text-muted-foreground uppercase`,children:`PII`}):null,(0,Q.jsx)(i,{type:`source`,position:p.Right,id:`out:${e.name}`,className:`!size-1.5 !border-0`,style:{background:o}})]})}function jp(e){return e.filter(e=>e.references?.table).length<2?!1:e.every(e=>e.primaryKey===!0||e.references!==void 0)}function Mp(e,t,n){return e.references?.table===t?`self`:e.unique===!0||e.primaryKey===!0?`one-to-one`:n?`many-to-many`:`many-to-one`}function Np(e,t,n=!1){if(!e.references)return;let r=e.references.column?`${e.references.table}.${e.references.column}`:e.references.table,i=t===void 0?`FK`:Bn(Mp(e,t,n),e.name);return`${e.inferredRef?`Inferred`:`Declared`} ${i} → ${r}`}var Pp={table:kp};function Fp(e){return(0,Q.jsx)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`store-schema-visualizer`,children:(0,Q.jsx)(h,{children:(0,Q.jsx)(Ip,{...e})})})}function Ip({stores:e,manifest:t,selectedEffectRef:n,onSelectTable:r,leading:i}){let{fitView:s}=o(),{theme:c}=ii(),u=ti(),[d,p]=(0,Z.useState)(``),[h,v]=(0,Z.useState)(0),[x,C]=(0,Z.useState)(!1),[w,T]=(0,Z.useState)(!0),[E,O]=(0,Z.useState)(!0),k=c===`system`?window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`:c,A=(0,Z.useMemo)(()=>Tn(e,t),[e,t]),j=(0,Z.useMemo)(()=>hp(wr(A),w),[A,w]),[M,N,F]=_([...j.nodes]),[I,L,R]=l([...j.edges]);(0,Z.useEffect)(()=>{N(zn(j.nodes,d,n,j.edges,E)),L(yn(j.edges,n,E,u!==!0))},[j,E,h,d,u,n,L,N]),(0,Z.useEffect)(()=>{let e=window.setTimeout(()=>{s({padding:.18,duration:240})},40);return()=>window.clearTimeout(e)},[s,h,A.length]);let z=(0,Z.useCallback)(async()=>{let e=Rn(A);if(e.length!==0)try{await navigator.clipboard.writeText(e),C(!0),window.setTimeout(()=>C(!1),1400)}catch{C(!1)}},[A]);return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,Q.jsxs)(`div`,{className:y,"data-slot":`store-schema-toolbar`,children:[i?(0,Q.jsxs)(Q.Fragment,{children:[i,(0,Q.jsx)(`span`,{className:`w-px shrink-0 self-stretch bg-border/60`,"aria-hidden":!0})]}):null,(0,Q.jsx)(`span`,{className:S(Te,`flex items-center px-2`),children:`Schema`}),(0,Q.jsx)(`span`,{className:`w-px shrink-0 self-stretch bg-border/60`,"aria-hidden":!0}),(0,Q.jsx)(Fe,{value:d,onChange:e=>p(e.target.value),placeholder:`Find table…`,"aria-label":`Find table`,"data-slot":`store-schema-find`}),(0,Q.jsxs)(`span`,{className:S(P,`flex items-center px-2`),children:[A.length,` `,A.length===1?`table`:`tables`]}),(0,Q.jsx)(`span`,{className:`w-px shrink-0 self-stretch bg-border/60`,"aria-hidden":!0}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-stretch`,children:[(0,Q.jsxs)(vi,{active:w,"aria-pressed":w,onClick:()=>T(e=>!e),className:`h-full`,"data-slot":`store-schema-colorize`,children:[(0,Q.jsx)(b,{icon:Ti,className:`size-3`,"aria-hidden":!0}),`Colorize`]}),(0,Q.jsxs)(vi,{active:x,disabled:A.length===0,onClick:()=>void z(),className:`h-full disabled:pointer-events-none disabled:opacity-40`,"data-slot":`store-schema-copy-sql`,children:[(0,Q.jsx)(b,{icon:x?D:Pe,className:`size-3`,"aria-hidden":!0}),x?`Copied`:`Copy as SQL`]}),(0,Q.jsx)(vi,{active:!1,disabled:A.length===0,onClick:()=>v(e=>e+1),className:`h-full disabled:pointer-events-none disabled:opacity-40`,"data-slot":`store-schema-auto-layout`,children:`Auto layout`})]})]}),(0,Q.jsxs)(`div`,{className:`relative min-h-0 flex-1`,children:[A.length===0?(0,Q.jsx)(`div`,{className:`flex h-full items-center justify-center p-6`,children:(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No SQL tables to visualize.`})}):(0,Q.jsxs)(a,{nodes:M,edges:I,nodeTypes:Pp,edgeTypes:Op,onNodesChange:F,onEdgesChange:R,colorMode:k,fitView:!0,nodesConnectable:!1,elementsSelectable:!0,proOptions:{hideAttribution:!0},minZoom:.15,maxZoom:1.8,defaultEdgeOptions:{type:`relation`,style:{stroke:`#38BDF8`,strokeWidth:1.5}},onNodeClick:(e,t)=>{O(!0),r(t.id)},onPaneClick:()=>O(!1),"data-slot":`store-schema-canvas`,children:[(0,Q.jsx)(g,{gap:24,size:1,color:`color-mix(in oklab, var(--foreground) 14%, transparent)`}),(0,Q.jsx)(m,{showInteractive:!1}),(0,Q.jsx)(f,{pannable:!0,zoomable:!0,ariaLabel:`Schema graph overview`,bgColor:`var(--card)`,maskColor:`color-mix(in oklab, var(--background) 55%, transparent)`,nodeColor:e=>e.data.color?.hex??`#64748B`,nodeStrokeColor:`transparent`,nodeStrokeWidth:12,nodeBorderRadius:8})]}),(0,Q.jsx)(`div`,{className:`pointer-events-none absolute bottom-3 left-1/2 z-10 max-w-[min(720px,calc(100%-2rem))] -translate-x-1/2`,children:(0,Q.jsxs)(`p`,{className:`flex flex-wrap items-center justify-center gap-x-2 gap-y-0.5 rounded-md border border-border/60 bg-background/80 px-2 py-1 text-[10px] text-muted-foreground backdrop-blur-sm`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(je,{kind:`pk`}),`primary`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(je,{kind:`fk`}),`foreign`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(je,{kind:`unique`}),`unique`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(Tp,{kind:`many-to-one`}),`many`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(Tp,{kind:`one-to-one`}),`one`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(Tp,{kind:`many-to-many`}),`join`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(Tp,{kind:`self`}),`self`]}),(0,Q.jsx)(`span`,{children:`dashed = inferred`}),(0,Q.jsx)(`span`,{children:`filled = not null`})]})})]})]})}function Lp(){let e=Lt(),t=ft(),n=vt();dt(!0);let{selectedResource:r,selectedTenant:i,queryFacet:a,schemaView:o,performanceView:s,performanceFacet:c,setSelectedResource:l,setSelectedTenant:u,setQueryFacet:d,setSchemaView:f,setPerformanceView:p}=qr(),m=He(),h=(0,Q.jsx)(Ue,{open:m.open,onToggle:m.toggle,noun:`store`,controlsId:`store-tree`,dataSlot:`store-tree-toggle`}),g=e.data?.stores??[],_=r??_a(g),v=(0,Z.useMemo)(()=>_?la(g,_):null,[g,_]);return(0,Q.jsx)(`div`,{className:B,"data-slot":`store-page`,children:(0,Q.jsxs)(Ne,{orientation:`horizontal`,className:`min-h-0 flex-1`,children:[(0,Q.jsx)(ze,{panelRef:m.panelRef,collapsible:!0,collapsedSize:0,defaultSize:M.start.defaultSize,minSize:M.start.minSize,onResize:m.onResize,className:`min-h-0 overflow-hidden`,children:(0,Q.jsx)(`div`,{id:`store-tree`,className:`h-full min-h-0 overflow-hidden`,"data-slot":`store-tree`,children:(0,Q.jsx)(qu,{stores:g,selectedEffectRef:_,onSelect:e=>{l(e,{keepView:o||s})},queryFacet:a,schemaActive:o,performanceActive:s,performanceFacet:c,onOpenQuery:e=>{d(a===e?null:e)},onOpenSchema:()=>{f(!o)},onOpenPerformance:e=>{s&&(c??`sql`)===e?p(!1):p(!0,e)}})})}),m.open?(0,Q.jsx)(Ge,{withHandle:!0}):null,(0,Q.jsx)(ze,{defaultSize:M.end.defaultSize,minSize:M.end.minSize,className:`min-h-0 overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`h-full min-h-0 overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,children:o?(0,Q.jsx)(Fp,{stores:g,manifest:t.data??null,selectedEffectRef:_,onSelectTable:e=>l(e,{keepView:!0}),leading:h}):s?(0,Q.jsx)(zd,{stores:g,selectedEffectRef:_,tenant:i,facet:c??`sql`,leading:h}):a?(0,Q.jsx)(ap,{facet:a,stores:g,selectedEffectRef:_,tenancyDeclared:e.data?.tenancyDeclared??!1,tenants:e.data?.tenants??[],tenant:i,onTenantChange:u,manifest:t.data??null,leading:h},a):v?(0,Q.jsx)(Hu,{store:v.store,child:v.child,manifest:t.data??null,tenancyDeclared:e.data?.tenancyDeclared??!1,tenants:e.data?.tenants??[],tenant:i,onTenantChange:u,runs:n.data??[],leading:h}):(0,Q.jsx)(di,{leading:h,icon:Ke.store.icon,title:e.isLoading?`Loading stores…`:e.isError?`Store unavailable`:`Select a resource`,description:e.isLoading?`Reading store catalogs.`:e.isError?e.error.message:`Pick a table, namespace, bucket, or index from the tree.`})})})})]})})}export{Lp as StorePage};