okengine 0.14.1 → 0.15.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/package.json +3 -4
  2. package/site/content/docs/elements/ai.mdx +2 -1
  3. package/site/content/docs/elements/channel.mdx +1 -0
  4. package/site/content/docs/elements/clock.mdx +3 -0
  5. package/site/content/docs/elements/flow.mdx +3 -0
  6. package/site/content/docs/elements/gate.mdx +25 -22
  7. package/site/content/docs/elements/signal.mdx +4 -4
  8. package/site/content/docs/elements/store.mdx +86 -27
  9. package/site/content/docs/elements/vault.mdx +1 -0
  10. package/site/content/docs/get-started/basic-usage.mdx +22 -13
  11. package/site/content/docs/get-started/index.mdx +5 -0
  12. package/site/content/docs/get-started/introduction.mdx +11 -3
  13. package/site/content/docs/get-started/meta.json +1 -1
  14. package/site/content/docs/get-started/project-structure.mdx +932 -0
  15. package/site/content/docs/reference/cli.md +13 -10
  16. package/site/content/docs/reference/client.mdx +25 -21
  17. package/site/content/docs/reference/security.md +1 -1
  18. package/src/auth/bindings.ts +14 -5
  19. package/src/auth/cross-plane.ts +10 -3
  20. package/src/cli/ai-setup/ai-setup.test.ts +62 -0
  21. package/src/cli/ai-setup/apply.ts +32 -1
  22. package/src/cli/attach-host-console.test.ts +3 -2
  23. package/src/cli/attach-host-console.ts +3 -0
  24. package/src/cli/build.test.ts +4 -2
  25. package/src/cli/db-seed.ts +48 -15
  26. package/src/cli/db.test.ts +104 -0
  27. package/src/cli/db.ts +122 -10
  28. package/src/cli/dev-controls.test.ts +20 -0
  29. package/src/cli/dev-controls.ts +13 -0
  30. package/src/cli/dev.test.ts +15 -4
  31. package/src/cli/dev.ts +102 -29
  32. package/src/cli/ensure-drizzle-config.ts +2 -1
  33. package/src/cli/tui/DevLive.tsx +12 -2
  34. package/src/cli/tui/keys.test.ts +2 -1
  35. package/src/cli/tui/keys.ts +3 -2
  36. package/src/compiler/aot.test.ts +1 -1
  37. package/src/compiler/extract.test.ts +409 -33
  38. package/src/compiler/extract.ts +318 -67
  39. package/src/compiler/flow-path.test.ts +96 -0
  40. package/src/compiler/flow-path.ts +173 -0
  41. package/src/compiler/generate-adopt.test.ts +112 -3
  42. package/src/compiler/generate-adopt.ts +280 -26
  43. package/src/compiler/schema-from-ast.ts +609 -0
  44. package/src/console/server/bind.ts +2 -2
  45. package/src/console/server/console.test.ts +3 -0
  46. package/src/console/server/flows.ts +120 -40
  47. package/src/console/server/invoke-user-flow.test.ts +3 -1
  48. package/src/console/server/invoke-user-flow.ts +17 -2
  49. package/src/console/server/iso-at.test.ts +9 -0
  50. package/src/console/server/iso-at.ts +11 -0
  51. package/src/console/server/security-headers.ts +6 -3
  52. package/src/console/server/spa-proxy.test.ts +1 -0
  53. package/src/console/server/sql-catalog.ts +147 -7
  54. package/src/console/server/sql-rls.test.ts +16 -0
  55. package/src/console/server/state.ts +8 -0
  56. package/src/console/server/store.test.ts +7 -4
  57. package/src/console/server/store.ts +142 -58
  58. package/src/console/ui-next/dist/assets/agent-disclosure-C0X1fbWF.js +1 -0
  59. package/src/console/ui-next/dist/assets/{cache-glyph-BanhLsEY.js → cache-glyph-F1FI122b.js} +1 -1
  60. package/src/console/ui-next/dist/assets/{call-pii-button-bqkxMrJH.js → call-pii-button-DEDCl_j3.js} +1 -1
  61. package/src/console/ui-next/dist/assets/collapsible-LPqGvfoz.js +1 -0
  62. package/src/console/ui-next/dist/assets/{confirm-sheet-DDCRmG62.js → confirm-sheet-3ptDzXbz.js} +1 -1
  63. package/src/console/ui-next/dist/assets/{duration-tone-oiRxPVsZ.js → duration-tone-sC3lGABz.js} +1 -1
  64. package/src/console/ui-next/dist/assets/{explorer-empty-HjTnVQoR.js → explorer-empty-BvYrygyO.js} +1 -1
  65. package/src/console/ui-next/dist/assets/flows-page-Dluo1Bd7.js +1 -0
  66. package/src/console/ui-next/dist/assets/{highlighted-json-CvDPvveV.js → highlighted-json-CS_O8L-r.js} +1 -1
  67. package/src/console/ui-next/dist/assets/http-method--sWDdXSB.js +1 -0
  68. package/src/console/ui-next/dist/assets/index-Ca3HZMVq.js +66 -0
  69. package/src/console/ui-next/dist/assets/index-UtTDRQpS.css +2 -0
  70. package/src/console/ui-next/dist/assets/{link-DF7SZ9Ek.js → link-COeyggt-.js} +1 -1
  71. package/src/console/ui-next/dist/assets/{observability-page-BEZDzyYh.js → observability-page-HK9-BO8z.js} +2 -2
  72. package/src/console/ui-next/dist/assets/react-D8E3mtu1.js +1 -0
  73. package/src/console/ui-next/dist/assets/replica-lag-DBIFFf7d.js +18 -0
  74. package/src/console/ui-next/dist/assets/sheet-form-Dnwa5oOR.js +1 -0
  75. package/src/console/ui-next/dist/assets/shortcut-keys-CoqwEIi0.js +1 -0
  76. package/src/console/ui-next/dist/assets/skeleton-BHcfDYcb.js +1 -0
  77. package/src/console/ui-next/dist/assets/store-page-BSohH3wM.js +41 -0
  78. package/src/console/ui-next/dist/assets/trace-detail-sheet-CFIGRnnA.js +2 -0
  79. package/src/console/ui-next/dist/assets/tree-expand-toggle-BgLl34w7.js +54 -0
  80. package/src/console/ui-next/dist/assets/units-page-B0cFE76A.js +1 -0
  81. package/src/console/ui-next/dist/assets/{use-vault-list-Cl79j_ku.js → use-vault-list-BLbZhzyF.js} +1 -1
  82. package/src/console/ui-next/dist/assets/vault-page-B1SbYe10.js +2 -0
  83. package/src/console/ui-next/dist/index.html +6 -6
  84. package/src/console/ui-next/src/client.ts +35 -7
  85. package/src/console/ui-next/src/components/motion/table/index.tsx +16 -0
  86. package/src/console/ui-next/src/components/motion/table/types.ts +4 -0
  87. package/src/console/ui-next/src/components/ui/kbd.tsx +2 -2
  88. package/src/console/ui-next/src/features/flows/traces/http-method.ts +19 -0
  89. package/src/console/ui-next/src/features/flows/traces/trace-detail.test.ts +19 -1
  90. package/src/console/ui-next/src/features/flows/traces/traces-pane.tsx +10 -3
  91. package/src/console/ui-next/src/features/store/detail/browse-section.tsx +45 -1
  92. package/src/console/ui-next/src/features/store/detail/resource-panel.tsx +78 -16
  93. package/src/console/ui-next/src/features/store/detail/store-row-detail-sheet.tsx +155 -14
  94. package/src/console/ui-next/src/features/store/explorer/store-tree.tsx +33 -133
  95. package/src/console/ui-next/src/features/store/files/file-preview.tsx +4 -1
  96. package/src/console/ui-next/src/features/store/grid/rls-policy-sheet.tsx +326 -165
  97. package/src/console/ui-next/src/features/store/grid/sql-insert-sheet.tsx +6 -0
  98. package/src/console/ui-next/src/features/store/grid/store-data-grid.tsx +50 -3
  99. package/src/console/ui-next/src/features/store/lib/files-meta.test.ts +3 -0
  100. package/src/console/ui-next/src/features/store/lib/files-meta.ts +12 -0
  101. package/src/console/ui-next/src/features/store/lib/query-defaults.test.ts +25 -0
  102. package/src/console/ui-next/src/features/store/lib/query-defaults.ts +85 -3
  103. package/src/console/ui-next/src/features/store/lib/query-gate.ts +30 -4
  104. package/src/console/ui-next/src/features/store/lib/rls-policy.test.ts +139 -0
  105. package/src/console/ui-next/src/features/store/lib/rls-policy.ts +223 -21
  106. package/src/console/ui-next/src/features/store/lib/schema-graph.ts +4 -0
  107. package/src/console/ui-next/src/features/store/lib/sql-catalog.test.ts +24 -0
  108. package/src/console/ui-next/src/features/store/lib/sql-catalog.ts +19 -0
  109. package/src/console/ui-next/src/features/store/lib/store-tree.test.ts +6 -0
  110. package/src/console/ui-next/src/features/store/lib/store-tree.ts +13 -0
  111. package/src/console/ui-next/src/features/store/query/query-console.tsx +48 -14
  112. package/src/console/ui-next/src/features/store/query/query-gate-menu.tsx +19 -20
  113. package/src/console/ui-next/src/features/store/query/query-gate-parts.tsx +2 -1
  114. package/src/console/ui-next/src/features/store/query/query-results.tsx +110 -83
  115. package/src/console/ui-next/src/features/store/schema/schema-table-node.tsx +17 -0
  116. package/src/console/ui-next/src/features/units/call/call-api-panel.tsx +112 -72
  117. package/src/console/ui-next/src/features/units/lib/contract-input.test.ts +206 -1
  118. package/src/console/ui-next/src/features/units/lib/contract-input.ts +55 -0
  119. package/src/console/ui-next/src/features/vault/lib/types.ts +1 -1
  120. package/src/docker/compose-health.test.ts +27 -0
  121. package/src/docker/compose-health.ts +19 -3
  122. package/src/docker/docker.test.ts +3 -0
  123. package/src/docker/recipes/pgdog.ts +2 -0
  124. package/src/drivers/clock-postgres.ts +13 -9
  125. package/src/drivers/instances-postgres.ts +4 -6
  126. package/src/drivers/journal-postgres.ts +13 -9
  127. package/src/drivers/pg-rls.test.ts +87 -0
  128. package/src/drivers/pg-rls.ts +233 -7
  129. package/src/drivers/pglite.ts +26 -3
  130. package/src/drivers/postgres.test.ts +23 -0
  131. package/src/drivers/postgres.ts +133 -9
  132. package/src/drivers/types.ts +10 -0
  133. package/src/elements/clock/declare.ts +26 -1
  134. package/src/elements/gate/boot.ts +5 -5
  135. package/src/elements/gate/declare.ts +36 -4
  136. package/src/elements/gate/flatten.ts +1 -1
  137. package/src/elements/gate/runtime.ts +1 -1
  138. package/src/elements/store/declare.ts +9 -6
  139. package/src/elements/store/emit-drizzle.ts +44 -8
  140. package/src/elements/store/resource.test.ts +1 -1
  141. package/src/elements/store/rls-identity.test.ts +95 -0
  142. package/src/elements/store/rls-identity.ts +116 -0
  143. package/src/elements/store/runtime.ts +4 -0
  144. package/src/elements/store/schema-decl.test.ts +37 -0
  145. package/src/elements/store/schema-decl.ts +161 -0
  146. package/src/elements/store/seed.ts +1 -1
  147. package/src/elements/store/sql-condition.test.ts +12 -0
  148. package/src/elements/store/sql-condition.ts +26 -2
  149. package/src/elements/store/sql-rls-isolation.test.ts +165 -0
  150. package/src/elements/store/sql-rls-stamp.test.ts +117 -0
  151. package/src/elements/store/sql-session.ts +81 -3
  152. package/src/elements/store/upsert-app.test.ts +1 -1
  153. package/src/elements/store.ts +14 -0
  154. package/src/http.ts +20 -3
  155. package/src/index.ts +10 -1
  156. package/src/kernel/adopt-barrel-fresh.test.ts +1 -1
  157. package/src/kernel/adopt-routes.ts +30 -2
  158. package/src/kernel/app.ts +131 -14
  159. package/src/kernel/auto-cache.test.ts +8 -8
  160. package/src/kernel/auto-registry.test.ts +49 -9
  161. package/src/kernel/boot.test.ts +4 -4
  162. package/src/kernel/boot.ts +2 -2
  163. package/src/kernel/effects-stamping.test.ts +3 -3
  164. package/src/kernel/element-registries.ts +12 -5
  165. package/src/kernel/errors.ts +24 -0
  166. package/src/kernel/flow-units.ts +64 -0
  167. package/src/kernel/flow.ts +29 -17
  168. package/src/kernel/fx.ts +23 -0
  169. package/src/kernel/horizontal-child.ts +4 -4
  170. package/src/kernel/http-path-pending.ts +20 -0
  171. package/src/kernel/http-resource.ts +4 -0
  172. package/src/kernel/http-stream.test.ts +4 -4
  173. package/src/kernel/pipeline.test.ts +2 -2
  174. package/src/kernel/plugin-elements.test.ts +1 -1
  175. package/src/kernel/plugin-needs.test.ts +1 -1
  176. package/src/kernel/ready.test.ts +2 -2
  177. package/src/kernel/resource-mount.test.ts +14 -0
  178. package/src/kernel/run-duration.test.ts +2 -2
  179. package/src/kernel/stamp-http.test.ts +79 -0
  180. package/src/kernel/stamp-http.ts +75 -0
  181. package/src/kernel/triggers.ts +52 -27
  182. package/src/manifest/types.ts +13 -0
  183. package/src/release/measure.ts +2 -2
  184. package/src/runtime/json-code-block.test.ts +2 -2
  185. package/src/runtime/serve.test.ts +4 -4
  186. package/src/term.test.ts +52 -4
  187. package/src/term.ts +125 -17
  188. package/src/test/reset-element-registries.ts +8 -3
  189. package/src/cli/ask-seed.test.ts +0 -96
  190. package/src/cli/ask-seed.ts +0 -82
  191. package/src/console/ui-next/dist/assets/collapsible-DYb0xU8C.js +0 -1
  192. package/src/console/ui-next/dist/assets/flows-page-DxDsOd4f.js +0 -1
  193. package/src/console/ui-next/dist/assets/http-method-CJCBYL2j.js +0 -1
  194. package/src/console/ui-next/dist/assets/index-Ce6WKWKM.js +0 -66
  195. package/src/console/ui-next/dist/assets/index-D4Ldtj79.css +0 -2
  196. package/src/console/ui-next/dist/assets/query-gate-parts-1m8m1iNp.js +0 -2
  197. package/src/console/ui-next/dist/assets/react-B1ML8gxg.js +0 -1
  198. package/src/console/ui-next/dist/assets/replica-lag-C8_BRt2x.js +0 -18
  199. package/src/console/ui-next/dist/assets/sheet-form-D-ata7jy.js +0 -1
  200. package/src/console/ui-next/dist/assets/shortcut-keys-DO4IsVqv.js +0 -1
  201. package/src/console/ui-next/dist/assets/skeleton-CL_X0GCj.js +0 -1
  202. package/src/console/ui-next/dist/assets/store-page-v3LXdYpr.js +0 -45
  203. package/src/console/ui-next/dist/assets/trace-detail-sheet-DFLFfUUX.js +0 -2
  204. package/src/console/ui-next/dist/assets/units-page-C0gW6Kdo.js +0 -1
  205. package/src/console/ui-next/dist/assets/vault-page-DuKzqwzW.js +0 -2
@@ -1,45 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$n as t,$r as n,Ba as r,Bi as i,Cr as a,Do as o,E as s,Ei as c,Er as l,F as u,Fi as d,Fr as f,Ga as p,Hi as m,Ii as h,Ir as g,Ja as _,Ka as v,Ki as y,L as b,Li as x,Lr as S,Mr as C,Ni as w,P as T,Pi as E,Pr as D,Pt as O,Qi as k,Qn as A,Qr as j,Ra as M,Ri as N,Rr as P,S as F,Si as I,Sr as L,To as R,Ua as ee,Ur as z,Va as B,Vi as V,Vr as te,Wa as H,Wr as ne,Xi as re,Zn as ie,Zr as ae,_i as oe,_r as se,aa as ce,ai as le,ar as ue,br as de,c as fe,ca as pe,cr as me,da as he,di as ge,dr as _e,ea as ve,er as ye,fa as be,gi as xe,hi as Se,hr as Ce,i as U,ii as we,ir as Te,ki as Ee,kr as De,l as Oe,la as W,lr as G,ma as ke,mr as Ae,ni as je,nr as Me,o as Ne,oa as Pe,oi as Fe,or as K,pa as Ie,pi as Le,qa as Re,qi as ze,qr as Be,ra as Ve,rr as He,s as Ue,si as We,sr as Ge,t as Ke,ta as qe,tr as Je,u as Ye,ur as Xe,vr as Ze,wi as Qe,wr as q,x as $e,xr as et,yi as tt,za as nt,zi as rt,zr as it}from"./shortcut-keys-DO4IsVqv.js";import{t as at,x as ot}from"./link-DF7SZ9Ek.js";import{n as st,r as ct}from"./react-dom-Bph1y7z7.js";import{A as lt,a as ut,c as dt,d as ft,f as pt,i as mt,l as ht,m as gt,n as _t,o as vt,p as yt,r as bt,s as xt,t as St,u as Ct}from"./xyflow-D7n4g6go.js";import{a as wt,i as Tt,n as Et,o as Dt,r as Ot,s as kt,t as At}from"./skeleton-CL_X0GCj.js";import{B as jt,R as Mt,_ as Nt,i as Pt,k as Ft,n as It,t as Lt,z as Rt}from"./react-B1ML8gxg.js";import{a as zt,i as Bt,n as Vt,r as Ht}from"./duration-tone-oiRxPVsZ.js";import{r as Ut}from"./preload-helper-oH4irX4C.js";import{A as Wt,C as Gt,N as Kt,S as qt,_ as Jt,a as Yt,b as Xt,c as Zt,d as Qt,f as $t,g as en,h as tn,i as nn,m as rn,n as an,o as on,p as sn,r as cn,s as J,t as Y,u as ln,v as un,x as dn,y as fn}from"./sheet-form-D-ata7jy.js";import{A as pn,B as mn,C as hn,D as gn,E as _n,F as vn,I as yn,L as bn,M as xn,N as Sn,O as Cn,P as wn,R as Tn,S as En,T as Dn,_ as On,a as kn,b as An,c as jn,d as Mn,g as Nn,h as Pn,i as Fn,j as In,k as Ln,l as Rn,m as zn,n as Bn,o as Vn,p as Hn,r as Un,s as Wn,t as Gn,v as Kn,w as qn,x as Jn,y as Yn,z as Xn}from"./query-gate-parts-1m8m1iNp.js";import{a as Zn,i as Qn}from"./shortcut-Cgzuv4k1.js";import{_ as X,a as $n,c as er,d as tr,f as nr,g as rr,h as ir,i as ar,l as or,m as sr,n as cr,o as lr,p as ur,r as dr,s as fr,t as pr,u as mr}from"./collapsible-DYb0xU8C.js";import{a as hr,c as gr,i as _r,n as vr,r as yr,s as br}from"./highlighted-json-CvDPvveV.js";import{t as xr}from"./dagre.esm-ZwcdTuZZ.js";import{A as Sr,B as Cr,C as wr,D as Tr,E as Er,F as Dr,H as Or,I as kr,L as Ar,M as jr,N as Mr,O as Nr,P as Pr,R as Fr,S as Ir,T as Lr,V as Rr,_ as zr,a as Br,b as Vr,c as Hr,d as Ur,f as Wr,g as Gr,h as Kr,i as qr,j as Jr,k as Yr,l as Xr,m as Zr,n as Qr,o as $r,p as ei,r as ti,s as ni,t as ri,u as ii,v as ai,w as oi,x as si,y as ci,z as li}from"./replica-lag-C8_BRt2x.js";import{t as ui}from"./explorer-empty-HjTnVQoR.js";import{a as di,i as fi,o as pi,s as mi,t as hi}from"./call-pii-button-bqkxMrJH.js";import{n as gi,t as _i}from"./confirm-sheet-DDCRmG62.js";var vi=e=>!e.isLayoutDirty&&e.willUpdate(!1);function yi(){let e=new Set,t=new WeakMap,n=()=>e.forEach(vi);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(ct(),1),bi=(0,Z.createContext)(null);function xi(){let e=(0,Z.useRef)(!1);return Mt(()=>(e.current=!0,()=>{e.current=!1}),[]),e}function Si(){let e=xi(),[t,n]=(0,Z.useState)(0),r=(0,Z.useCallback)(()=>{e.current&&n(t+1)},[t]);return[(0,Z.useCallback)(()=>Ft.postRender(r),[r]),t]}var Q=lt(),Ci=e=>e===!0,wi=e=>Ci(e===!0)||e===`id`,Ti=({children:e,id:t,inherit:n=!0})=>{let r=(0,Z.useContext)(jt),i=(0,Z.useContext)(bi),[a,o]=Si(),s=(0,Z.useRef)(null),c=r.id||i;s.current===null&&(wi(n)&&c&&(t=t?c+`-`+t:c),s.current={id:t,group:Ci(n)&&r.group||yi()});let l=(0,Z.useMemo)(()=>({...s.current,forceRender:a}),[o]);return(0,Q.jsx)(jt.Provider,{value:l,children:e})};function Ei({children:e,...t}){let n=(0,Z.useContext)(Pt);t={...n,...t},t.transition=Nt(t.transition,n.transition),t.isStatic=Rt(()=>t.isStatic);let r=(0,Z.useMemo)(()=>t,[JSON.stringify(t.transition),t.transformPagePoint,t.reducedMotion,t.skipAnimations,t.isValidProp]);return(0,Q.jsx)(Pt.Provider,{value:r,children:e})}var Di=e(st(),1);function Oi({className:e,orientation:t=`horizontal`,...n}){return(0,Q.jsx)(Kt,{"data-slot":`separator`,orientation:t,className:a(`shrink-0 bg-border data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch`,e),...n})}function ki(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 Ai(e){return e===`memory`||e===`fs`||e===`s3`?e:`files`}function ji(e){switch(e){case`memory`:return`This process`;case`fs`:return`Local disk`;case`s3`:return`Object store`;default:return`Files driver`}}function Mi(e){return e.kind===`index`||e.kind===`function`||e.kind===`trigger`||e.kind===`extension`||e.kind===`policy`?e.kind:null}function Ni(e){return Mi(e)!==null}function Pi(e){return e.kind===`table`&&typeof e.rls==`boolean`}function Fi(e){let t=Mi(e);return t===`index`?`Indexes`:t===`function`?`Functions`:t===`trigger`?`Triggers`:t===`extension`?`Extensions`:t===`policy`?`RLS Policies`:e.name}function Ii(e){let t=[],n=[];for(let r of e)Ni(r)?n.push(r):t.push(r);return{tables:t,catalog:n}}var Li=[`sql`,`kv`,`files`,`index`];function Ri(e){return Li.includes(e)}var zi={sql:`SQL`,kv:`KV`,files:`Files`,index:`Index`},Bi={sql:{icon:j,label:zi.sql,wellClass:`border-emerald-500/35 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`},kv:{icon:tt,label:zi.kv,wellClass:`border-amber-500/35 bg-amber-500/10 text-amber-700 dark:text-amber-400`},files:{icon:je,label:zi.files,wellClass:`border-sky-500/35 bg-sky-500/10 text-sky-600 dark:text-sky-400`},index:{icon:V,label:zi.index,wellClass:`border-violet-500/35 bg-violet-500/10 text-violet-700 dark:text-violet-400`}};function Vi(e){return Li.map(t=>({facet:t,label:zi[t],stores:e.filter(e=>e.facet===t).map(e=>({store:e,children:e.children}))})).filter(e=>e.stores.length>0)}function Hi(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)||Fi(t).toLowerCase().includes(n)||t.effectRef.toLowerCase().includes(n));(e||i.length>0)&&r.push({...t,children:e?t.children:i})}return r}function Ui(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 Wi(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 Gi(e){return`facet:${e}`}function Ki(e){return`${e}/tables`}function qi(e,t){let n=t[e];return n===void 0?e.startsWith(`facet:`):n}function Ji(e){let t=[];for(let n of e){t.push(Gi(n.facet));for(let e of n.stores)Wi(e.store)||(t.push(e.store.ref),e.store.facet===`sql`&&t.push(Ki(e.store.ref)))}return t}function Yi(e,t){let n=Ui(e,t);if(!n)return[];let r=[Gi(n.store.facet)];return Wi(n.store)?r:(r.push(n.store.ref),n.store.facet===`sql`&&!Ni(n.child)&&r.push(Ki(n.store.ref)),r)}function Xi(e){for(let t of Li)for(let n of e){if(n.facet!==t)continue;let e=n.children.find(e=>!Ni(e));if(e)return e.effectRef}return null}var Zi=`oke_store_hidden_facets`;function Qi(e){return Array.isArray(e)?new Set(e.filter(e=>typeof e==`string`&&Ri(e))):new Set}function $i(){try{if(typeof localStorage>`u`)return new Set;let e=localStorage.getItem(Zi);return e?Qi(JSON.parse(e)):new Set}catch{return new Set}}function ea(e){try{if(typeof localStorage>`u`)return;localStorage.setItem(Zi,JSON.stringify([...e]))}catch{}}function ta(e,t){return e.filter(e=>!t.has(e.facet))}var na={duration:0},ra={type:`spring`,duration:.4,bounce:.3},ia={hidden:{},show:{transition:{staggerChildren:.035,delayChildren:.05}}},aa={hidden:{opacity:0,y:-6,filter:`blur(3px)`},show:{opacity:1,y:0,filter:`blur(0px)`}},oa=(0,Z.createContext)(null);function sa(e){let t=(0,Z.useContext)(oa);if(!t)throw Error(`${e} must be used within <Select>`);return t}function ca({value:e,defaultValue:t,onValueChange:n,disabled:r=!1,className:i,children:o}){let s=It()??!1,c=(0,Z.useId)(),l=(0,Z.useRef)(null),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(t),[m,h]=(0,Z.useState)(()=>new Map),[g,_]=(0,Z.useState)(`bottom`),v=e!==void 0,y=v?e:f,b=(0,Z.useCallback)(e=>{v||p(e),n?.(e),d(!1)},[v,n]),x=(0,Z.useCallback)((e,t)=>{h(n=>n.get(e)===t?n:new Map(n).set(e,t))},[]),S=(0,Z.useCallback)(e=>{h(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]);(0,Z.useEffect)(()=>{if(!u)return;let e=e=>{e.key===`Escape`&&d(!1)},t=e=>{l.current&&!l.current.contains(e.target)&&d(!1)};return window.addEventListener(`keydown`,e),window.addEventListener(`pointerdown`,t),()=>{window.removeEventListener(`keydown`,e),window.removeEventListener(`pointerdown`,t)}},[u]);let C=(0,Z.useMemo)(()=>({value:y,open:u,setOpen:d,select:b,register:x,unregister:S,labelFor:e=>e===void 0?void 0:m.get(e),reduce:s,triggerId:`${c}-trigger`,listId:`${c}-list`,disabled:r,placement:g,setPlacement:_}),[y,u,b,x,S,m,s,c,r,g]);return(0,Q.jsx)(oa.Provider,{value:C,children:(0,Q.jsx)(`div`,{ref:l,className:a(`relative`,i),"data-slot":`motion-select`,children:o})})}function la({className:e,children:t,"aria-label":n,flat:r=!1}){let i=sa(`SelectTrigger`),o=i.placement===`top`,s=i.open?[0,0,12]:[12,0,12],c=i.reduce?{duration:0}:i.open?{duration:.6,times:[0,.4,1],ease:Et}:{duration:.42,times:[0,.5,1],ease:Et};return(0,Q.jsxs)(Lt.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:o?s:12,borderTopRightRadius:o?s:12,borderBottomLeftRadius:o?12:s,borderBottomRightRadius:o?12:s},transition:{borderTopLeftRadius:o?c:na,borderTopRightRadius:o?c:na,borderBottomLeftRadius:o?na:c,borderBottomRightRadius:o?na:c},className:a(`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)(Lt.span,{"aria-hidden":!0,animate:{rotate:i.open?180:0},transition:i.reduce?{duration:0}:ra,className:`text-muted-foreground`,children:(0,Q.jsx)(q,{icon:C,className:`size-3.5`})})]})}function ua({placeholder:e,className:t}){let n=sa(`SelectValue`),r=n.labelFor(n.value);return(0,Q.jsx)(`span`,{className:a(r?`text-foreground`:`text-muted-foreground`,t),children:r??e??`Select`})}function da({className:e,children:t}){let n=sa(`SelectContent`),r=(0,Z.useRef)(null),[i,o]=(0,Z.useState)(0),s=n.open,{setPlacement:c}=n;(0,Z.useLayoutEffect)(()=>{let e=r.current;if(!e)return;let t=()=>o(e.offsetHeight);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()}),(0,Z.useLayoutEffect)(()=>{if(!s)return;let e=document.getElementById(n.triggerId),t=r.current;if(!e||!t)return;let i=e.getBoundingClientRect(),a=t.offsetHeight,o=window.innerHeight-i.bottom,l=i.top;c(o<a+16&&l>o?`top`:`bottom`)},[s,n.triggerId,c]);let l=n.placement===`top`,u=s?8:0,d=s?12:0,f=s?{type:`spring`,duration:.6,bounce:.5,delay:.12}:{type:`spring`,duration:.3,bounce:.1},p=s?{duration:.3,ease:Et,delay:.14}:{duration:.16,ease:Et};return(0,Q.jsx)(Lt.div,{id:n.listId,role:`listbox`,"aria-labelledby":n.triggerId,"aria-hidden":!s,inert:!s,initial:!1,animate:n.reduce?{opacity:+!!s,height:s?i:0}:{opacity:+!!s,height:s?i:0,marginTop:l?0:u,marginBottom:l?u:0,borderTopLeftRadius:l?12:d,borderTopRightRadius:l?12:d,borderBottomLeftRadius:l?d:12,borderBottomRightRadius:l?d:12},transition:n.reduce?{duration:.12}:{opacity:s?{duration:.18}:{duration:.16,delay:.12},height:s?{type:`spring`,duration:.42,bounce:.14}:{duration:.26,ease:Et,delay:.14},marginTop:l?na:f,marginBottom:l?f:na,borderTopLeftRadius:l?na:p,borderTopRightRadius:l?na:p,borderBottomLeftRadius:l?p:na,borderBottomRightRadius:l?p:na},style:{transformOrigin:l?`bottom`:`top`,overflow:`hidden`,pointerEvents:s?`auto`:`none`},className:a(`absolute right-0 left-0 z-20 rounded-xl border border-border bg-background shadow-lg`,l?`bottom-full`:`top-full`,e),children:(0,Q.jsx)(Lt.div,{ref:r,variants:n.reduce?void 0:ia,initial:!1,animate:s?`show`:`hidden`,className:`p-1`,children:t})})}function fa({value:e,disabled:t=!1,className:n,children:r}){let i=sa(`SelectItem`),o=i.value===e,s=typeof r==`string`?r:e,c=i.register,l=i.unregister;return(0,Z.useLayoutEffect)(()=>(c(e,s),()=>l(e)),[c,l,e,s]),(0,Q.jsx)(Lt.li,{variants:i.reduce?void 0:aa,children:(0,Q.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":o,disabled:t,onClick:()=>i.select(e),className:a(`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`,o?`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,o?(0,Q.jsx)(q,{icon:ve,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 ma(){let e=o();return ot({mutationFn:async e=>{let t=await nt(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:Xn}),e.invalidateQueries({queryKey:Rr})])}})}function ha(){let e=o();return ot({mutationFn:async e=>{let t=await M(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:Xn}),e.invalidateQueries({queryKey:Rr})])}})}var ga={type:`spring`,stiffness:800,damping:80,mass:4};function _a({checked:e,onCheckedChange:t,disabled:n,label:r,ariaLabel:i,className:o,size:s=`default`}){let c=(0,Z.useId)(),l=(0,Z.useRef)(null),u=It(),[d,f]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)(!1),h=s===`sm`;(0,Z.useEffect)(()=>{!l.current||u||n&&d&&Bt(l.current,{x:[0,-2,2,-1,0]},{delay:.2,duration:.6})},[n,d,u]);let g=!n&&p&&d&&!u;return(0,Q.jsx)(Ei,{transition:u?{duration:0}:ga,children:(0,Q.jsxs)(`span`,{className:a(`inline-flex items-center gap-2`,o),children:[(0,Q.jsx)(Lt.button,{id:c,type:`button`,role:`switch`,"aria-checked":e,"aria-label":i,disabled:n,onClick:()=>{n||t(!e)},onPointerDown:()=>{f(!0),m(!0)},onPointerUp:()=>f(!1),onPointerLeave:()=>f(!1),initial:!1,"data-state":e?`checked`:`unchecked`,className:a(`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`,h?`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)(Lt.div,{ref:l,layout:!0,animate:{scale:g?.9:1},className:a(`pointer-events-none block rounded-full bg-background shadow-md`,h?`h-3 w-3`:`h-5 w-5`),children:(0,Q.jsx)(`div`,{className:a(h?`size-3`:`size-5`,g&&(e?`ml-1`:`mr-1`)),"aria-hidden":!0})})}),r?(0,Q.jsx)(`label`,{htmlFor:c,className:`text-sm`,children:r}):null]})})}function va({open:e,extraCount:t=0,onOpenChange:n,controls:r}){return(0,Q.jsxs)($t,{active:e||t>0,extraCount:t,"aria-expanded":e,"aria-controls":r,onClick:()=>n(!e),children:[(0,Q.jsx)(q,{icon:We,className:`size-3`,"aria-hidden":!0}),`Advanced`]})}function ya({templates:e,selectedId:t,onSelect:n}){let r=e.find(e=>e.id===t)??null;return(0,Q.jsx)(Yt,{label:`Templates`,hint:r?.detail??`Pick a starter, or fill the fields.`,children:e.map(e=>(0,Q.jsx)(nn,{active:e.id===t,onClick:()=>n(e),children:e.title},e.id))})}var ba=[{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 xa=[$(`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`])];[...ba,...xa];function Sa(e){return/^[0-9]+(\.[0-9]+)*$/.test(e)}var Ca={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`},wa={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 Ta(e){return Ca[e]||e.replace(/^pg_/,``).split(/[_-]+/).filter(e=>e.length>0).map(e=>wa[e]??e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}var Ea=`https://www.postgresql.org/docs/current`,Da={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`},Oa={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 ka(e){let t=Oa[e];if(t)return t;let n=Da[e];return n?`${Ea}/${n}.html`:null}var Aa={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 ja(e){return`"${e.replaceAll(`"`,``)}"`}var Ma=Ta,Na=[`timescaledb`,`pg_cron`,`postgis`],Pa={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 Fa(e){return Pa[e]}function Ia(e){let t=new Map(e.map(e=>[e.name,e]));return Na.flatMap(e=>{let n=t.get(e);return n?[n]:[]})}var La=[`time`,`jobs`,`geo`,`search`,`graph`,`scale`,`security`,`http`,`fdw`,`lang`,`analytics`];function Ra(e){return[e.name,Ma(e.name),e.comment,e.category,Aa[e.category],...e.tags??[],...e.requires??[]].join(` `).toLowerCase()}function za(e,t){let n=t.trim().toLowerCase().split(/\s+/).filter(e=>e.length>0);return n.length===0?e:e.filter(e=>{let t=Ra(e);return n.every(e=>t.includes(e))})}function Ba(e){return La.flatMap(t=>{let n=e.filter(e=>e.category===t);return n.length===0?[]:[{category:t,label:Aa[t],items:n}]})}var Va={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 Ha(e,t){let n=[`CREATE EXTENSION IF NOT EXISTS ${ja(e)}`],r=[],i=t?.schema?.trim()??``;i!==``&&Ua(i)&&r.push(`SCHEMA ${xn(i)}`);let a=t?.version?.trim()??``;return a!==``&&Sa(a)&&r.push(`VERSION '${a}'`),t?.cascade===!0&&r.push(`CASCADE`),r.length>0&&n.push(`WITH ${r.join(` `)}`),`${n.join(` `)};`}function Ua(e){let t=e.trim();return pn(t)&&t.toLowerCase()!==`pg_catalog`}function Wa(e){return+!!e.schema?.trim()+ +!!e.version?.trim()+ +(e.cascade===!0)}function Ga(e,t,n){let r=[...e.requires??[],e.name].map(e=>({name:e,title:Ma(e),already:t.has(e)})),i=r.filter(e=>!e.already),a=i.length>0?i.map(t=>Ha(t.name,t.name===e.name?n:void 0)).join(`
2
- `):`-- ${e.name} is already installed`,o=Va[e.name];return{items:r,sql:a,...o?{note:o}:{}}}var Ka={timescaledb:z,pg_cron:P,postgis:Ee},qa=[{value:`all`,label:`All`},...La.map(e=>({value:e,label:Aa[e]}))];function Ja({open:e,onOpenChange:t,storeRef:n,presentNames:r}){let i=ma(),[o,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(`all`),[d,f]=(0,Z.useState)(null),[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)(null),[_,v]=(0,Z.useState)(`extensions`),[y,b]=(0,Z.useState)(!1),[x,S]=(0,Z.useState)(``),[C,w]=(0,Z.useState)(``),[T,E]=(0,Z.useState)(!1),D=(0,Z.useMemo)(()=>new Set(r),[r]),O=(0,Z.useMemo)(()=>{let e=za(xa,o);return l===`all`?e:e.filter(e=>e.category===l)},[o,l]),k=l===`all`&&o.trim()===``,A=(0,Z.useMemo)(()=>k?Ia(xa):[],[k]),j=(0,Z.useMemo)(()=>{if(!k)return O;let e=new Set(A.map(e=>e.name));return O.filter(t=>!e.has(t.name))},[k,A,O]),M=(0,Z.useMemo)(()=>Ba(j),[j]),N=(0,Z.useMemo)(()=>({...x.trim()===``?{}:{schema:x.trim()},...C.trim()===``?{}:{version:C.trim()},...T?{cascade:!0}:{}}),[x,C,T]),P=(0,Z.useMemo)(()=>h?Ga(h,D,N):null,[h,D,N]),F=e=>{D.has(e.name)||(f(null),v(`extensions`),b(!1),S(``),w(``),E(!1),g(e))},I=async()=>{if(!h||!P)return;let e=P.items.filter(e=>!e.already).map(e=>e.name);if(e.length===0){g(null);return}f(null),m(h.name);try{for(let t of e)await i.mutateAsync({ref:n,child:`extensions`,id:t,patch:{enabled:!0,...t===h.name?N:{}},commit:!0});g(null)}catch(e){f(e instanceof Error?e.message:String(e))}finally{m(null)}};return(0,Q.jsx)(U,{open:e,onOpenChange:e=>{e||(c(``),u(`all`),f(null),m(null),g(null),v(`extensions`),b(!1),S(``),w(``),E(!1)),t(e)},children:(0,Q.jsx)(Ne,{side:`right`,showOverlay:!1,className:`gap-0 p-0 data-[side=right]:sm:max-w-3xl`,"data-slot":`extension-library-sheet`,children:h&&P?(0,Q.jsx)(Ya,{ext:h,plan:P,tab:_,advancedOpen:y,extraCount:Wa(N),schema:x,version:C,cascade:T,error:d,pending:p!==null,onTab:v,onAdvanced:b,onSchema:S,onVersion:w,onCascade:E,onBack:()=>{g(null),f(null)},onConfirm:()=>void I()}):(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)(Ye,{className:`text-sm`,children:`Extend this store`}),(0,Q.jsxs)(`p`,{className:`text-[10px] tabular-nums text-muted-foreground`,children:[O.length,` pack`,O.length===1?``:`s`,o.trim()?` matching “${o.trim()}”`:``]})]}),(0,Q.jsxs)(Ue,{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)(q,{icon:V,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)(s,{value:o,onChange:e=>c(e.target.value),placeholder:`Search packs…`,"aria-label":`Search library`,flat:!0,className:a(an,`font-mono`),autoFocus:!0})]}),(0,Q.jsxs)(Sn,{items:qa,value:l,onValueChange:e=>{e==null||Array.isArray(e)||u(e===`all`?`all`:e)},children:[(0,Q.jsx)(bn,{"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)(Tn,{children:e=>{let t=String(e??`all`),n=t===`all`?`All`:Aa[t];return(0,Q.jsxs)(`span`,{children:[`Category · `,n]})}})}),(0,Q.jsx)(wn,{align:`end`,alignItemWithTrigger:!1,className:`min-w-44`,children:(0,Q.jsx)(vn,{children:qa.map(e=>(0,Q.jsx)(yn,{value:e.value,className:`text-[11px]`,children:e.label},e.value))})})]})]}),d?(0,Q.jsx)(`p`,{className:`border-b border-border/50 px-4 py-2 text-[11px] text-destructive`,role:`alert`,children:d}):null,(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:O.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:[A.length>0?(0,Q.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(Qa,{children:`Popular`}),(0,Q.jsx)(`ul`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-3`,children:A.map(e=>(0,Q.jsx)($a,{ext:e,installed:D.has(e.name),pending:p===e.name,disabled:p!==null,onAdd:()=>F(e)},e.name))})]}):null,M.map(e=>(0,Q.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(Qa,{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)(eo,{ext:e,installed:D.has(e.name),pending:p===e.name,disabled:p!==null,onAdd:()=>F(e)},e.name))})]},e.category))]})})]})]})})})}function Ya({ext:e,plan:t,tab:n,advancedOpen:r,extraCount:i,schema:a,version:o,cascade:c,error:l,pending:u,onTab:d,onAdvanced:f,onSchema:p,onVersion:m,onCascade:h,onBack:g,onConfirm:_}){let v=Ma(e.name),y=e.name===`timescaledb`||e.name===`pg_cron`||e.name===`postgis`?Ka[e.name]:rt;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:g,className:`flex w-fit items-center gap-1 text-[11px] text-muted-foreground hover:text-foreground`,children:[(0,Q.jsx)(q,{icon:D,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)(q,{icon:y,className:`size-4`,"aria-hidden":!0})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(Ye,{className:`text-sm`,children:[`Install `,v]}),(0,Q.jsx)(Ue,{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)(Xa,{active:n===`extensions`,onClick:()=>d(`extensions`),children:`Extensions`}),(0,Q.jsx)(Xa,{active:n===`sql`,onClick:()=>d(`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)(no,{}):(0,Q.jsx)(ar,{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)(va,{open:r,extraCount:i,onOpenChange:f,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)(s,{value:a,onChange:e=>p(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)(s,{value:o,onChange:e=>m(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)(_a,{size:`sm`,checked:c,onCheckedChange:h,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,l?(0,Q.jsx)(`p`,{className:`mt-3 text-[11px] text-destructive`,role:`alert`,children:l}):null]}),(0,Q.jsxs)(fe,{children:[(0,Q.jsx)(Zt,{split:!0,onClick:g,children:`Cancel`}),(0,Q.jsx)(Zt,{variant:`default`,disabled:u,"data-slot":`extension-library-install`,"data-name":e.name,onClick:_,children:u?`Installing…`:`Install pack`})]})]})}function Xa({active:e,onClick:t,children:n}){return(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":e,onClick:t,className:a(`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 Za({name:e,title:t,className:n}){let r=ka(e);return r?(0,Q.jsxs)(`a`,{href:r,target:`_blank`,rel:`noreferrer`,className:a(`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)(q,{icon:Qe,className:`size-3 shrink-0 text-muted-foreground/50 group-hover/ext-link:text-muted-foreground`,"aria-hidden":!0})]}):(0,Q.jsx)(`p`,{className:a(`font-medium tracking-tight text-foreground`,n),children:t})}function Qa({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 $a({ext:e,installed:t,pending:n,disabled:r,onAdd:i}){let a=e.name,o=Ma(e.name),s=Fa(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)(q,{icon:Ka[a],className:`size-4 text-foreground`,"aria-hidden":!0})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(Za,{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)(to,{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:Aa[e.category]}),s?(0,Q.jsxs)(`p`,{className:`truncate text-[10px] text-muted-foreground/80`,children:[`Built by `,s]}):null]}),(0,Q.jsx)(ro,{installed:t,pending:n,disabled:r,name:e.name,onAdd:i})]})]})}function eo({ext:e,installed:t,pending:n,disabled:r,onAdd:i}){let a=Fa(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)(Za,{name:e.name,title:Ma(e.name),className:`text-[13px]`}),(0,Q.jsx)(`p`,{className:`font-mono text-[11px] text-muted-foreground`,children:e.name}),(0,Q.jsx)(to,{tags:e.tags})]}),t?(0,Q.jsx)(no,{}):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:Aa[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)(ro,{installed:!1,pending:n,disabled:r,name:e.name,onAdd:i})]})]})}function to({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 no(){return(0,Q.jsx)(ar,{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 ro({installed:e,pending:t,disabled:n,name:r,onAdd:i}){return e?(0,Q.jsx)(no,{}):(0,Q.jsx)(F,{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 io=`github-light`,ao=`github-dark`;function oo(e){return vr.includes(e)}var so=new Map;function co(e,t){return`${t}\u0000${e}`}function lo(){let{theme:e}=Ut(),[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 uo(e,t){let n=co(e,t),r=so.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=so.get(n);if(r){a({key:n,code:e,language:t,lines:r});return}let i=!1;return yr().then(n=>n.codeToTokensWithThemes(e,{lang:t,themes:{light:io,dark:ao}})).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})));so.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 fo({code:e,tokens:t,className:n}){let r=lo();return(0,Q.jsx)(`code`,{className:a(`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=uo(e,t),i=0,o=e.split(`
3
- `).map(e=>{let t={content:e,offset:i};return i+=e.length+1,t});return(0,Q.jsx)(`pre`,{className:a(`m-0 overflow-x-auto whitespace-pre font-mono text-xs leading-5 text-foreground/85`,n),children:o.map((e,t)=>(0,Q.jsxs)(Z.Fragment,{children:[(0,Q.jsx)(fo,{code:e.content,tokens:r?.[t]}),t<o.length-1?`
4
- `:null]},`${e.offset}-${e.content}`))})}var mo=[`INSERT`,`UPDATE`,`DELETE`],ho=[{id:`read`,label:`Read`,icon:pe},{id:`write`,label:`Write`,icon:h},{id:`both`,label:`Both`,icon:m}];function go({open:e,onOpenChange:t,storeRef:n,tables:r,manifest:i=null}){let o=ma(),c=Ln(e),[l,u]=(0,Z.useState)(``),[d,f]=(0,Z.useState)(r[0]??``),[p,h]=(0,Z.useState)(`SELECT`),[g,_]=(0,Z.useState)(`PERMISSIVE`),[v,y]=(0,Z.useState)(`true`),[b,x]=(0,Z.useState)(`true`),[S,C]=(0,Z.useState)(!0),[w,T]=(0,Z.useState)(null),[E,D]=(0,Z.useState)(!1),[O,k]=(0,Z.useState)(``),[A,j]=(0,Z.useState)(null),[M,N]=(0,Z.useState)(!1),[P,F]=(0,Z.useState)(``),[L,R]=(0,Z.useState)([]),[ee,z]=(0,Z.useState)(()=>Dn(`read`)),B=_n(p),V=gn(p),te=(0,Z.useMemo)(()=>Pn(Kn(i),c.data??null),[i,c.data]),H=(0,Z.useMemo)(()=>({gates:L,actions:ee,roles:[]}),[L,ee]),ne=(0,Z.useMemo)(()=>{try{let e=In({name:l||`policy_name`,table:d||`table`,command:p,behavior:g,roles:`public`,using:V.using?v:``,withCheck:V.withCheck?b:``});return Cn(e,S)}catch{return null}},[l,d,p,g,V,v,b,S]),re=e=>{j(e.id),u(e.name),h(e.command),_(e.behavior??`PERMISSIVE`),z(t=>An(t,e.command)),y(e.using??`true`),x(e.withCheck??`true`)},ie=e=>{let t=qn(e,p);h(t),z(Dn(e)),R([])},ae=e=>{h(e),z(t=>An(t,e))},oe=e=>{R(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},se=async()=>{T(null);try{let e=In({name:l,table:d,command:p,behavior:g,roles:`public`,using:V.using?v:``,withCheck:V.withCheck?b:``});await o.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:S},commit:!0}),t(!1)}catch(e){T(e instanceof Error?e.message:String(e))}};return(0,Q.jsx)(U,{open:e,onOpenChange:e=>{e||N(!1),t(e)},children:(0,Q.jsxs)(Ne,{side:`right`,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.jsx)(Oe,{className:`shrink-0 gap-2 border-b border-border/50`,children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-3 pr-8`,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)(q,{icon:m,className:`size-4`,"aria-hidden":!0})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(Ye,{className:`text-sm`,children:`Create policy`}),(0,Q.jsx)(Ue,{className:`text-[11px]`,children:"Review the `CREATE POLICY` SQL before it runs"})]})]})}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 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)($t,{active:M,"aria-expanded":M,"aria-controls":M?`rls-policy-templates-sheet`:void 0,onClick:()=>N(e=>!e),children:[(0,Q.jsx)(q,{icon:I,className:`size-3`,"aria-hidden":!0}),`Templates`]})]}),(0,Q.jsx)(s,{value:l,onChange:e=>u(e.target.value),placeholder:`read_all`,"aria-label":`Policy name`,flat:!0,className:a(Y,`font-mono`)})]}),(0,Q.jsxs)(ln,{children:[(0,Q.jsx)(J,{label:`Table`,split:`start`,children:(0,Q.jsxs)(ca,{value:d,onValueChange:f,children:[(0,Q.jsx)(la,{flat:!0,className:a(Y,`font-mono`),children:(0,Q.jsx)(ua,{placeholder:`Select a table`})}),(0,Q.jsx)(da,{children:r.map(e=>(0,Q.jsx)(fa,{value:e,className:`font-mono text-[12px]`,children:e},e))})]})}),(0,Q.jsx)(J,{label:`Behavior`,split:`end`,children:(0,Q.jsxs)(ca,{value:g,onValueChange:e=>_(e),children:[(0,Q.jsx)(la,{flat:!0,className:Y,children:(0,Q.jsx)(ua,{})}),(0,Q.jsxs)(da,{children:[(0,Q.jsx)(fa,{value:`PERMISSIVE`,children:`Permissive`}),(0,Q.jsx)(fa,{value:`RESTRICTIVE`,children:`Restrictive`})]})]})})]}),(0,Q.jsx)(cn,{label:`Gate`,hint:`Who this policy pairs with`}),(0,Q.jsx)(yo,{advanced:E,onAdvancedChange:D,mode:B,onModeChange:ie,catalog:te,query:P,onQueryChange:F,selection:H,onToggleGate:oe}),E||B===`write`?(0,Q.jsx)(ko,{commands:E?Jn:mo,value:p,onChange:ae}):null,(0,Q.jsx)(cn,{label:`Rows`,hint:V.using&&V.withCheck?`Existing rows and new rows`:V.withCheck?`New rows`:`Existing rows`}),V.using?(0,Q.jsx)(J,{label:`USING`,children:(0,Q.jsx)(s,{value:v,onChange:e=>y(e.target.value),placeholder:`true`,flat:!0,className:a(Y,`font-mono`)})}):null,V.withCheck?(0,Q.jsx)(J,{label:`WITH CHECK`,children:(0,Q.jsx)(s,{value:b,onChange:e=>x(e.target.value),placeholder:`true`,flat:!0,className:a(Y,`font-mono`)})}):null]}),(0,Q.jsxs)(`div`,{className:`shrink-0 border-t border-border/50 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.jsx)(`p`,{className:`text-[10px] font-semibold tracking-[0.12em] text-muted-foreground uppercase`,children:`SQL`}),(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)(_a,{size:`sm`,checked:S,onCheckedChange:C,ariaLabel:`Enable RLS on this table`})]})]}),ne?(0,Q.jsx)(`div`,{className:`max-h-28 overflow-y-auto px-4 pb-3`,children:(0,Q.jsx)(po,{code:ne,language:`sql`,className:`overflow-visible whitespace-pre-wrap break-words text-[11px] leading-relaxed`})}):(0,Q.jsx)(`p`,{className:`px-4 pb-3 text-[11px] text-muted-foreground`,children:`Fill name, table, and an expression.`}),w?(0,Q.jsx)(on,{children:w}):null]}),(0,Q.jsxs)(fe,{children:[(0,Q.jsx)(Zt,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(Zt,{variant:`default`,disabled:o.isPending||!ne,onClick:()=>void se(),children:o.isPending?`Creating…`:`Create policy`})]})]}),M?(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)(vo,{query:O,onQueryChange:k,selectedId:A,onSelect:re})}):null]})})}var _o={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 vo({query:e,onQueryChange:t,selectedId:n,onSelect:r}){let i=hn(En,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:`shrink-0 border-b border-border/50`,children:[(0,Q.jsx)(`p`,{className:`px-3 pt-2.5 pr-10 text-[10px] font-semibold tracking-[0.12em] text-muted-foreground uppercase`,children:`Templates`}),(0,Q.jsxs)(`label`,{className:`relative block`,children:[(0,Q.jsx)(q,{icon:V,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)(s,{value:e,onChange:e=>t(e.target.value),placeholder:`Search templates`,"aria-label":`Search templates`,flat:!0,className:a(an,`font-mono`)})]})]}),(0,Q.jsx)(`ul`,{className:`min-h-0 flex-1 overflow-y-auto p-2`,children:i.length===0?(0,Q.jsx)(`li`,{className:`px-2 py-3 text-[10px] text-muted-foreground`,children:`No matching templates.`}):i.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:a(`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:a(`rounded px-1.5 py-px font-mono text-[9px] font-semibold tracking-wide`,_o[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)(q,{icon:ve,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 yo({advanced:e,onAdvancedChange:t,mode:n,onModeChange:r,catalog:i,query:o,onQueryChange:s,selection:c,onToggleGate:l}){let u=Yn(c);return(0,Q.jsxs)(`div`,{className:a(!e&&`border-b border-border/50`),children:[(0,Q.jsx)(bo,{mode:n,onChange:r,advanced:e,extraCount:u,onAdvancedChange:t}),e?(0,Q.jsx)(Co,{catalog:i,query:o,onQueryChange:s,selection:c,onToggleGate:l}):null]})}function bo({mode:e,onChange:t,advanced:n,extraCount:r,onAdvancedChange:i}){let o=(0,Z.useId)(),s=It();return(0,Q.jsx)(Ti,{id:o,children:(0,Q.jsxs)(`div`,{role:`group`,"aria-label":`Gate`,className:a(`flex w-full items-center`,n&&`border-b border-border/50`),children:[ho.map(r=>{let a=!n&&e===r.id;return(0,Q.jsxs)(xo,{active:a,reduceMotion:s,onClick:()=>{i(!1),t(r.id)},children:[(0,Q.jsx)(q,{icon:r.icon,className:`size-3.5`,"aria-hidden":!0}),r.label]},r.id)}),(0,Q.jsxs)(xo,{active:n,reduceMotion:s,"aria-expanded":n,"aria-controls":`rls-gate-advanced`,onClick:()=>i(!n),children:[(0,Q.jsx)(q,{icon:We,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 xo({active:e,reduceMotion:t,onClick:n,children:r,...i}){return(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":e,onClick:n,className:a(`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)(Lt.span,{layoutId:`rls-gate-pill`,className:`absolute inset-0 z-0 bg-muted`,style:{borderRadius:0},transition:t?{duration:0}:Ot}):null,(0,Q.jsx)(`span`,{className:`relative z-10 inline-flex items-center gap-1.5`,children:r})]})}var So={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 Co({catalog:e,query:t,onQueryChange:n,selection:r,onToggleGate:i}){let o=zn(e,t),c=Nn(o),l=On(o),u=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)(q,{icon:V,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)(s,{value:t,onChange:e=>n(e.target.value),placeholder:`Search policy or scope`,"aria-label":`Search policy or scope`,flat:!0,className:a(an,`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)(q,{icon:it,className:`size-2.5`,"aria-hidden":!0})]},e))}):null,(0,Q.jsxs)(wo,{empty:u?`No matches.`:`No policy or scope gates declared.`,hasRows:c.length+l.length>0,children:[c.length>0?(0,Q.jsx)(To,{label:`Policy`,hint:`gate.policy`}):null,c.map(e=>(0,Q.jsx)(Eo,{icon:Do(e.variant),label:e.name,detail:Oo(e),selected:r.gates.includes(e.name),onSelect:()=>i(e.name),pressed:!0},e.name)),l.length>0?(0,Q.jsx)(To,{label:`Scope`,hint:`gate.scope`}):null,l.map(e=>(0,Q.jsx)(Eo,{icon:Do(e.variant),label:e.name,detail:Oo(e),selected:r.gates.includes(e.name),onSelect:()=>i(e.name),pressed:!0},e.name))]})]})}function wo({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 To({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 Eo({icon:e,label:t,detail:n,selected:r,onSelect:i,pressed:o=!1}){return(0,Q.jsx)(`li`,{className:`border-b border-border/50 last:border-b-0`,children:(0,Q.jsxs)(`button`,{type:`button`,role:o?`checkbox`:`radio`,"aria-checked":r,"aria-pressed":o?r:void 0,onClick:i,className:a(`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:a(`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)(q,{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)(q,{icon:ve,className:`mt-0.5 size-3.5 shrink-0`,"aria-hidden":!0}):null]})})}function Do(e){return e===`public`?Pe:e===`scope`?tt:m}function Oo(e){return e.description?e.description:e.variant===`public`?`Intentionally unauthenticated`:e.variant===`scope`?`auth.scopes.has("${e.name}")`:`ABAC policy`}function ko({commands:e,value:t,onChange:n}){return(0,Q.jsx)(Yt,{label:`FOR`,hint:So[t],children:e.map(e=>(0,Q.jsx)(nn,{active:t===e,onClick:()=>n(e),children:e},e))})}function Ao(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 jo(){return ot({mutationFn:async e=>{let t=await p(e),n=Ao(t);if(n)throw n;if(!t.data)throw Error(`Empty SQL result`);return t.data}})}function Mo({value:e,onChange:t,label:n,className:r,onSubmit:i}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(null),c=e.endsWith(`
5
- `)?e:`${e}\n`;return(0,Q.jsxs)(`div`,{className:a(`relative min-h-56 bg-muted/15`,r),children:[(0,Q.jsx)(`div`,{ref:o,className:`pointer-events-none absolute inset-0 overflow-hidden`,children:(0,Q.jsx)(Mr,{code:c,language:`sql`,className:`overflow-visible whitespace-pre-wrap break-words px-4 py-3 text-[11px] leading-5`})}),(0,Q.jsx)(`textarea`,{ref:s,value:e,onChange:e=>t(e.target.value),onScroll:()=>{let e=s.current,t=o.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 No=[{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 Po(e){let t=e.orReplace===!0?`OR REPLACE `:``,n=Lo(e.args)?e.args.trim():``,r=Lo(e.returns)?e.returns.trim():``,i=[`CREATE ${t}FUNCTION ${Bo(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!==``&&Lo(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:Ro(e.language)),i.push(`$$;`),i.join(`
10
- `)}Po({name:`function_name`,args:``,returns:`void`,language:`plpgsql`,body:`BEGIN
11
- -- Write your function logic here
12
- END;`});function Fo(e){return/^\s*CREATE\s+(OR\s+REPLACE\s+)?FUNCTION\b/i.test(e)}function Io(e){return/AS\s+\$\$\n?([\s\S]*?)\n?\$\$;?\s*$/i.exec(e)?.[1]??null}function Lo(e){let t=e.trim();return t.length<=2e3&&!/;/.test(t)&&!/--/.test(t)&&!/\/\*/.test(t)}function Ro(e){return e===`sql`?` SELECT NULL;`:`BEGIN
13
- -- Write your function logic here
14
- END;`}function zo(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 Bo(e){let t=e.trim().replace(/\(\s*\)$/,``);return(t.length>0?t:`function_name`).split(`.`).map(e=>xn(e)).join(`.`)}var Vo=[`plpgsql`,`sql`],Ho=[`VOLATILE`,`STABLE`,`IMMUTABLE`],Uo=[`INVOKER`,`DEFINER`],Wo=[`UNSAFE`,`RESTRICTED`,`SAFE`];function Go(){return`BEGIN
15
- -- Write your function logic here
16
- END;`}function Ko({open:e,onOpenChange:t,storeRef:n}){let r=o(),{mutate:i,isPending:c,reset:l}=jo(),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(`void`),[g,_]=(0,Z.useState)(`plpgsql`),[v,y]=(0,Z.useState)(`VOLATILE`),[b,x]=(0,Z.useState)(!1),[S,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)(``),[I,L]=(0,Z.useState)(``),[R,ee]=(0,Z.useState)(``),[z,B]=(0,Z.useState)(null),[V,te]=(0,Z.useState)(null),H=(e,t=R)=>{let n=e.name??u,r=e.args??f,i=e.returns??m,a=e.language??g,o=e.volatility??v,s=e.orReplace??b,c=e.security??w,l=e.strict??E,d=e.leakproof??O,p=e.parallel??A,h=e.searchPath??M,_=Number(e.cost??P),y=Number(e.rows??I);ee(Po({name:n.trim()||`function_name`,args:r,returns:i,language:a,volatility:o,body:e.body??Io(t)??Go(),orReplace:s,security:c,strict:l,leakproof:d,parallel:p,...h.trim()===``?{}:{searchPath:h},...Number.isFinite(_)&&_>0?{cost:_}:{},...Number.isFinite(y)&&y>0?{rows:y}:{}}))};(0,Z.useEffect)(()=>{e&&(d(``),p(``),h(`void`),_(`plpgsql`),y(`VOLATILE`),x(!1),C(!1),T(`INVOKER`),D(!1),k(!1),j(`UNSAFE`),N(``),F(``),L(``),te(null),B(null),ee(Po({name:`function_name`,args:``,returns:`void`,language:`plpgsql`,body:Go()})),l())},[e,l]);let ne=e=>{te(e.id);let t=u.trim()===``?e.id.replaceAll(`-`,`_`):u;h(e.returns),_(e.language),y(e.volatility??`VOLATILE`),p(e.args??``),u.trim()===``&&d(t),H({name:t,args:e.args??``,returns:e.returns,language:e.language,volatility:e.volatility??`VOLATILE`,body:e.body},R)},re=()=>{if(!Fo(R)){B(`This sheet runs CREATE FUNCTION only`);return}B(null),i({ref:n,sql:R,allowWrite:!0},{onSuccess:()=>{r.invalidateQueries({queryKey:Xn}),t(!1)},onError:e=>B(e instanceof Error?e.message:String(e))})};return(0,Q.jsx)(U,{open:e,onOpenChange:t,children:(0,Q.jsxs)(Ne,{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(),c||re())},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)(q,{icon:Se,className:`size-4`,"aria-hidden":!0})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(Ye,{className:`text-sm`,children:`New function`}),(0,Q.jsx)(Ue,{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)(ya,{templates:No,selectedId:V,onSelect:ne}),(0,Q.jsx)(J,{label:`Function name`,children:(0,Q.jsx)(s,{value:u,onChange:e=>{let t=e.target.value;d(t),H({name:t})},placeholder:`function_name`,flat:!0,className:a(Y,`font-mono`)})}),(0,Q.jsxs)(ln,{children:[(0,Q.jsx)(J,{label:`Arguments`,split:`start`,children:(0,Q.jsx)(s,{value:f,onChange:e=>{let t=e.target.value;p(t),H({args:t})},placeholder:`optional — id text`,flat:!0,className:a(Y,`font-mono`)})}),(0,Q.jsx)(J,{label:`Returns`,split:`end`,children:(0,Q.jsx)(s,{value:m,onChange:e=>{let t=e.target.value;h(t),H({returns:t})},placeholder:`void`,flat:!0,className:a(Y,`font-mono`)})})]}),(0,Q.jsx)(Yt,{label:`Language`,children:Vo.map(e=>(0,Q.jsx)(nn,{active:g===e,onClick:()=>{_(e),H({language:e})},children:e},e))}),(0,Q.jsx)(Yt,{label:`Volatility`,children:Ho.map(e=>(0,Q.jsx)(nn,{active:v===e,onClick:()=>{y(e),H({volatility:e})},children:e},e))}),(0,Q.jsx)(Qt,{label:`Replace if it already exists`,children:(0,Q.jsx)(_a,{size:`sm`,checked:b,onCheckedChange:e=>{x(e),H({orReplace:e})},ariaLabel:`Replace if it already exists`})}),(0,Q.jsx)(cn,{label:`Options`,children:(0,Q.jsx)(va,{open:S,extraCount:zo({security:w,strict:E,leakproof:O,parallel:A,searchPath:M,cost:Number(P),rows:Number(I)}),onOpenChange:C,controls:`sql-function-advanced`})}),S?(0,Q.jsxs)(`div`,{id:`sql-function-advanced`,children:[(0,Q.jsx)(Yt,{label:`Security`,children:Uo.map(e=>(0,Q.jsx)(nn,{active:w===e,onClick:()=>{T(e),H({security:e})},children:e},e))}),(0,Q.jsx)(Yt,{label:`Parallel`,children:Wo.map(e=>(0,Q.jsx)(nn,{active:A===e,onClick:()=>{j(e),H({parallel:e})},children:e},e))}),(0,Q.jsxs)(ln,{children:[(0,Q.jsx)(Qt,{label:`STRICT`,className:`border-r border-b-0`,children:(0,Q.jsx)(_a,{size:`sm`,checked:E,onCheckedChange:e=>{D(e),H({strict:e})},ariaLabel:`STRICT`})}),(0,Q.jsx)(Qt,{label:`LEAKPROOF`,className:`border-b-0`,children:(0,Q.jsx)(_a,{size:`sm`,checked:O,onCheckedChange:e=>{k(e),H({leakproof:e})},ariaLabel:`LEAKPROOF`})})]}),(0,Q.jsx)(J,{label:`SET search_path`,children:(0,Q.jsx)(s,{value:M,onChange:e=>{let t=e.target.value;N(t),H({searchPath:t})},placeholder:`public, pg_temp`,flat:!0,className:a(Y,`font-mono`)})}),(0,Q.jsxs)(ln,{children:[(0,Q.jsx)(J,{label:`COST`,split:`start`,children:(0,Q.jsx)(s,{value:P,onChange:e=>{let t=e.target.value;F(t),H({cost:t})},placeholder:`optional`,inputMode:`decimal`,flat:!0,className:a(Y,`font-mono`)})}),(0,Q.jsx)(J,{label:`ROWS`,split:`end`,children:(0,Q.jsx)(s,{value:I,onChange:e=>{let t=e.target.value;L(t),H({rows:t})},placeholder:`optional`,inputMode:`decimal`,flat:!0,className:a(Y,`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)(cn,{label:`SQL`,hint:`Editable before it runs`}),(0,Q.jsx)(Mo,{value:R,onChange:ee,onSubmit:c?void 0:re,label:`CREATE FUNCTION SQL`,className:`min-h-36 max-h-48`}),z?(0,Q.jsx)(on,{slot:`sql-function-error`,children:z}):null]}),(0,Q.jsxs)(fe,{children:[(0,Q.jsx)(Zt,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(Zt,{variant:`default`,disabled:c||!Fo(R),onClick:re,"data-slot":`sql-function-submit`,children:c?`Creating…`:`Create function`})]})]})})}var qo=[{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 Jo(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}${xn(e.name)}`,` ON ${xn(e.table)}${i}`,` (${Qo(e.columns)})`],o=e.include?.trim()??``;o!==``&&Zo(o)&&a.push(` INCLUDE (${Qo(o)})`),e.nullsNotDistinct===!0&&a.push(` NULLS NOT DISTINCT`);let s=e.with?.trim()??``;s!==``&&Zo(s)&&a.push(` WITH (${s})`);let c=e.where?.trim()??``;return c!==``&&Zo(c)&&a.push(` WHERE ${c}`),`${a.join(`
17
- `)};`}function Yo(e){return+(e.concurrently===!0)+ +!!e.include?.trim()+ +(e.nullsNotDistinct===!0)+ +!!e.with?.trim()}Jo({name:`index_name`,table:`table_name`,columns:`column_name`});function Xo(e){return/^\s*CREATE\s+(UNIQUE\s+)?INDEX\b/i.test(e)}function Zo(e){let t=e.trim();return t.length>0&&t.length<=2e3&&!/;/.test(t)&&!/--/.test(t)&&!/\/\*/.test(t)}function Qo(e){if(!Zo(e))return xn(`column_name`);let t=e.split(`,`).map(e=>e.trim()).filter(e=>e.length>0);return t.length===0?xn(`column_name`):t.map(e=>pn(e)?xn(e):e).join(`, `)}var $o=[`btree`,`hash`,`gin`,`gist`,`brin`];function es({open:e,onOpenChange:t,storeRef:n,tables:r}){let i=o(),{mutate:c,isPending:l,reset:u}=jo(),[d,f]=(0,Z.useState)(``),[p,m]=(0,Z.useState)(r[0]??``),[h,g]=(0,Z.useState)(`column_name`),[_,v]=(0,Z.useState)(`btree`),[y,b]=(0,Z.useState)(!1),[x,S]=(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,I]=(0,Z.useState)(``),[L,R]=(0,Z.useState)(null),[ee,z]=(0,Z.useState)(null),B=(0,Z.useMemo)(()=>Jo({name:d.trim()||`index_name`,table:p.trim()||`table_name`,columns:h,method:_,unique:y,ifNotExists:x,concurrently:D,nullsNotDistinct:j,...C.trim()===``?{}:{where:C},...k.trim()===``?{}:{include:k},...N.trim()===``?{}:{with:N}}),[d,p,h,_,y,x,C,D,k,j,N]);(0,Z.useEffect)(()=>{if(!e)return;let t=r[0]??``;f(``),m(t),g(`column_name`),v(`btree`),b(!1),S(!1),w(``),E(!1),O(!1),A(``),M(!1),P(``),z(null),R(null),I(Jo({name:`index_name`,table:t||`table_name`,columns:`column_name`})),u()},[e,r,u]),(0,Z.useEffect)(()=>{I(B)},[B]);let V=e=>{z(e.id),g(e.columns),v(e.method??`btree`),b(e.unique===!0),w(e.where??``),d.trim()===``&&f(e.id.replaceAll(`-`,`_`))},te=()=>{if(!Xo(F)){R(`This sheet runs CREATE INDEX only`);return}R(null),c({ref:n,sql:F,allowWrite:!0},{onSuccess:()=>{i.invalidateQueries({queryKey:Xn}),t(!1)},onError:e=>R(e instanceof Error?e.message:String(e))})};return(0,Q.jsx)(U,{open:e,onOpenChange:t,children:(0,Q.jsxs)(Ne,{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(),l||te())},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)(q,{icon:tt,className:`size-4`,"aria-hidden":!0})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(Ye,{className:`text-sm`,children:`Create index`}),(0,Q.jsx)(Ue,{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)(ya,{templates:qo,selectedId:ee,onSelect:V}),(0,Q.jsxs)(ln,{children:[(0,Q.jsx)(J,{label:`Index name`,split:`start`,children:(0,Q.jsx)(s,{value:d,onChange:e=>f(e.target.value),placeholder:`index_name`,flat:!0,className:a(Y,`font-mono`)})}),(0,Q.jsx)(J,{label:`Table`,split:`end`,children:(0,Q.jsxs)(ca,{value:p,onValueChange:m,children:[(0,Q.jsx)(la,{flat:!0,className:a(Y,`font-mono`),children:(0,Q.jsx)(ua,{placeholder:`Select a table`})}),(0,Q.jsx)(da,{children:r.map(e=>(0,Q.jsx)(fa,{value:e,className:`font-mono text-[12px]`,children:e},e))})]})})]}),(0,Q.jsx)(J,{label:`Columns`,children:(0,Q.jsx)(s,{value:h,onChange:e=>g(e.target.value),placeholder:`column_name`,flat:!0,className:a(Y,`font-mono`)})}),(0,Q.jsx)(Yt,{label:`Method`,children:$o.map(e=>(0,Q.jsx)(nn,{active:_===e,onClick:()=>v(e),children:e},e))}),(0,Q.jsx)(J,{label:`WHERE`,children:(0,Q.jsx)(s,{value:C,onChange:e=>w(e.target.value),placeholder:`optional`,flat:!0,className:a(Y,`font-mono`)})}),(0,Q.jsxs)(ln,{children:[(0,Q.jsx)(Qt,{label:`Unique`,className:`border-r border-b-0`,children:(0,Q.jsx)(_a,{size:`sm`,checked:y,onCheckedChange:b,ariaLabel:`Unique`})}),(0,Q.jsx)(Qt,{label:`Skip if it exists`,className:`border-b-0`,children:(0,Q.jsx)(_a,{size:`sm`,checked:x,onCheckedChange:S,ariaLabel:`Skip if it already exists`})})]}),(0,Q.jsx)(cn,{label:`Options`,children:(0,Q.jsx)(va,{open:T,extraCount:Yo({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)(Qt,{label:`Concurrently`,children:(0,Q.jsx)(_a,{size:`sm`,checked:D,onCheckedChange:O,ariaLabel:`Create index concurrently`})}),(0,Q.jsx)(J,{label:`INCLUDE`,children:(0,Q.jsx)(s,{value:k,onChange:e=>A(e.target.value),placeholder:`covering columns`,flat:!0,className:a(Y,`font-mono`)})}),(0,Q.jsx)(Qt,{label:`NULLS NOT DISTINCT`,children:(0,Q.jsx)(_a,{size:`sm`,checked:j,onCheckedChange:M,ariaLabel:`NULLS NOT DISTINCT`})}),(0,Q.jsx)(J,{label:`WITH`,children:(0,Q.jsx)(s,{value:N,onChange:e=>P(e.target.value),placeholder:`fillfactor = 70`,flat:!0,className:a(Y,`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)(cn,{label:`SQL`,hint:`Editable before it runs`}),(0,Q.jsx)(Mo,{value:F,onChange:I,onSubmit:l?void 0:te,label:`CREATE INDEX SQL`,className:`min-h-36 max-h-48`}),L?(0,Q.jsx)(on,{slot:`sql-index-error`,children:L}):null]}),(0,Q.jsxs)(fe,{children:[(0,Q.jsx)(Zt,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(Zt,{variant:`default`,disabled:l||!Xo(F),onClick:te,"data-slot":`sql-index-submit`,children:l?`Creating…`:`Create index`})]})]})})}var ts=[{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 ns(e){let t=os(e.events,e.updateOf),n=[`CREATE ${e.orReplace===!0?`OR REPLACE `:``}${e.constraint===!0?`CONSTRAINT `:``}TRIGGER ${xn(e.name)}`,` ${e.timing} ${t}`,` ON ${xn(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=ss(e.referencingOld,e.referencingNew);r!==``&&n.push(` ${r}`),n.push(` FOR EACH ${e.level}`);let i=e.when?.trim()??``;i!==``&&is(i)&&n.push(` WHEN (${i})`);let a=e.functionArgs!==void 0&&is(e.functionArgs.trim())?e.functionArgs.trim():``;return n.push(` EXECUTE FUNCTION ${cs(e.functionName)}(${a});`),n.join(`
18
- `)}ns({name:`trigger_name`,table:`table_name`,timing:`AFTER`,events:[`INSERT`,`UPDATE`,`DELETE`],level:`ROW`,functionName:`function_name`});function rs(e){return/^\s*CREATE\s+(OR\s+REPLACE\s+)?(CONSTRAINT\s+)?TRIGGER\b/i.test(e)}function is(e){let t=e.trim();return t.length>0&&t.length<=2e3&&!/;/.test(t)&&!/--/.test(t)&&!/\/\*/.test(t)}function as(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 os(e,t){let n=e.length>0?e:[`INSERT`],r=t?.trim()??``;return n.map(e=>e===`UPDATE`&&r!==``&&is(r)?`UPDATE OF ${r}`:e).join(` OR `)}function ss(e,t){let n=[],r=e?.trim()??``,i=t?.trim()??``;return r!==``&&is(r)&&n.push(`OLD TABLE AS ${xn(r)}`),i!==``&&is(i)&&n.push(`NEW TABLE AS ${xn(i)}`),n.length>0?`REFERENCING ${n.join(` `)}`:``}function cs(e){let t=e.trim().replace(/\(\s*\)$/,``);return(t.length>0?t:`function_name`).split(`.`).map(e=>xn(e)).join(`.`)}var ls=[`BEFORE`,`AFTER`,`INSTEAD OF`],us=[`INSERT`,`UPDATE`,`DELETE`],ds=[`ROW`,`STATEMENT`],fs=[{id:`immediate`,label:`IMMEDIATE`},{id:`deferred`,label:`DEFERRED`}];function ps({open:e,onOpenChange:t,storeRef:n,tables:r}){let i=o(),{mutate:c,isPending:l,reset:u}=jo(),[d,f]=(0,Z.useState)(``),[p,m]=(0,Z.useState)(r[0]??``),[h,g]=(0,Z.useState)(`AFTER`),[_,v]=(0,Z.useState)([`INSERT`]),[y,b]=(0,Z.useState)(`ROW`),[x,S]=(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,I]=(0,Z.useState)(``),[L,R]=(0,Z.useState)(``),[ee,z]=(0,Z.useState)(``),[B,V]=(0,Z.useState)(``),[te,H]=(0,Z.useState)(null),[ne,re]=(0,Z.useState)(null),ie=(0,Z.useMemo)(()=>ns({name:d.trim()||`trigger_name`,table:p.trim()||`table_name`,timing:h,events:_,level:y,functionName:x.trim()||`function_name`,orReplace:T,constraint:k,...C.trim()===``?{}:{when:C},...j===null?{}:{defer:j},...N.trim()===``?{}:{updateOf:N},...F.trim()===``?{}:{referencingOld:F},...L.trim()===``?{}:{referencingNew:L},...ee.trim()===``?{}:{functionArgs:ee}}),[d,p,h,_,y,x,C,T,k,j,N,F,L,ee]);(0,Z.useEffect)(()=>{if(!e)return;let t=r[0]??``;f(``),m(t),g(`AFTER`),v([`INSERT`]),b(`ROW`),S(``),w(``),E(!1),O(!1),A(!1),M(null),P(``),I(``),R(``),z(``),re(null),H(null),V(ns({name:`trigger_name`,table:t||`table_name`,timing:`AFTER`,events:[`INSERT`],level:`ROW`,functionName:`function_name`})),u()},[e,r,u]),(0,Z.useEffect)(()=>{V(ie)},[ie]);let ae=e=>{re(e.id),g(e.timing),v(e.events),b(e.level),d.trim()===``&&f(e.id.replaceAll(`-`,`_`))},oe=e=>{if(_.includes(e)){if(_.length===1)return;v(_.filter(t=>t!==e));return}let t=[..._,e];v(t),e===`TRUNCATE`&&b(`STATEMENT`)},se=()=>{if(!rs(B)){H(`This sheet runs CREATE TRIGGER only`);return}H(null),c({ref:n,sql:B,allowWrite:!0},{onSuccess:()=>{i.invalidateQueries({queryKey:Xn}),t(!1)},onError:e=>H(e instanceof Error?e.message:String(e))})};return(0,Q.jsx)(U,{open:e,onOpenChange:t,children:(0,Q.jsxs)(Ne,{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(),l||se())},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)(q,{icon:he,className:`size-4`,"aria-hidden":!0})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(Ye,{className:`text-sm`,children:`New trigger`}),(0,Q.jsx)(Ue,{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)(ya,{templates:ts,selectedId:ne,onSelect:ae}),(0,Q.jsxs)(ln,{children:[(0,Q.jsx)(J,{label:`Trigger name`,split:`start`,children:(0,Q.jsx)(s,{value:d,onChange:e=>f(e.target.value),placeholder:`trigger_name`,flat:!0,className:a(Y,`font-mono`)})}),(0,Q.jsx)(J,{label:`Table`,split:`end`,children:(0,Q.jsxs)(ca,{value:p,onValueChange:m,children:[(0,Q.jsx)(la,{flat:!0,className:a(Y,`font-mono`),children:(0,Q.jsx)(ua,{placeholder:`Select a table`})}),(0,Q.jsx)(da,{children:r.map(e=>(0,Q.jsx)(fa,{value:e,className:`font-mono text-[12px]`,children:e},e))})]})})]}),(0,Q.jsx)(Yt,{label:`Timing`,children:ls.map(e=>(0,Q.jsx)(nn,{active:h===e,onClick:()=>g(e),children:e},e))}),(0,Q.jsx)(Yt,{label:`Events`,children:us.map(e=>(0,Q.jsx)(nn,{active:_.includes(e),onClick:()=>oe(e),children:e},e))}),(0,Q.jsx)(Yt,{label:`For each`,children:ds.map(e=>(0,Q.jsx)(nn,{active:y===e,onClick:()=>b(e),children:e},e))}),(0,Q.jsxs)(ln,{children:[(0,Q.jsx)(J,{label:`Function`,split:`start`,children:(0,Q.jsx)(s,{value:x,onChange:e=>S(e.target.value),placeholder:`function_name`,flat:!0,className:a(Y,`font-mono`)})}),(0,Q.jsx)(J,{label:`WHEN`,split:`end`,children:(0,Q.jsx)(s,{value:C,onChange:e=>w(e.target.value),placeholder:`optional`,flat:!0,className:a(Y,`font-mono`)})})]}),(0,Q.jsx)(Qt,{label:`Replace if it already exists`,children:(0,Q.jsx)(_a,{size:`sm`,checked:T,onCheckedChange:E,ariaLabel:`Replace if it already exists`})}),(0,Q.jsx)(cn,{label:`Options`,children:(0,Q.jsx)(va,{open:D,extraCount:as({constraint:k,...j===null?{}:{defer:j},updateOf:N,referencingOld:F,referencingNew:L,functionArgs:ee,events:_}),onOpenChange:O,controls:`sql-trigger-advanced`})}),D?(0,Q.jsxs)(`div`,{id:`sql-trigger-advanced`,children:[(0,Q.jsx)(Yt,{label:`Also fire on`,children:(0,Q.jsx)(nn,{active:_.includes(`TRUNCATE`),onClick:()=>oe(`TRUNCATE`),children:`TRUNCATE`})}),_.includes(`UPDATE`)?(0,Q.jsx)(J,{label:`UPDATE OF`,children:(0,Q.jsx)(s,{value:N,onChange:e=>P(e.target.value),placeholder:`column_name`,flat:!0,className:a(Y,`font-mono`)})}):null,(0,Q.jsx)(J,{label:`Function args`,children:(0,Q.jsx)(s,{value:ee,onChange:e=>z(e.target.value),placeholder:`optional`,flat:!0,className:a(Y,`font-mono`)})}),(0,Q.jsx)(Qt,{label:`CONSTRAINT`,children:(0,Q.jsx)(_a,{size:`sm`,checked:k,onCheckedChange:e=>{A(e),e||M(null)},ariaLabel:`CONSTRAINT trigger`})}),k?(0,Q.jsx)(Yt,{label:`Defer`,children:fs.map(e=>(0,Q.jsx)(nn,{active:j===e.id,onClick:()=>M(j===e.id?null:e.id),children:e.label},e.id))}):null,(0,Q.jsxs)(ln,{children:[(0,Q.jsx)(J,{label:`OLD TABLE AS`,split:`start`,children:(0,Q.jsx)(s,{value:F,onChange:e=>I(e.target.value),placeholder:`optional`,flat:!0,className:a(Y,`font-mono`)})}),(0,Q.jsx)(J,{label:`NEW TABLE AS`,split:`end`,children:(0,Q.jsx)(s,{value:L,onChange:e=>R(e.target.value),placeholder:`optional`,flat:!0,className:a(Y,`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)(cn,{label:`SQL`,hint:`Editable before it runs`}),(0,Q.jsx)(Mo,{value:B,onChange:V,onSubmit:l?void 0:se,label:`CREATE TRIGGER SQL`,className:`min-h-36 max-h-48`}),te?(0,Q.jsx)(on,{slot:`sql-trigger-error`,children:te}):null]}),(0,Q.jsxs)(fe,{children:[(0,Q.jsx)(Zt,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(Zt,{variant:`default`,disabled:l||!rs(B),onClick:se,"data-slot":`sql-trigger-submit`,children:l?`Creating…`:`Create trigger`})]})]})})}function ms({open:e,onOpenChange:t,phrase:n,title:r,description:i,willNotFire:a,pending:o=!1,error:s,onConfirm:c}){return(0,Q.jsx)(_i,{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 hs=`M5 13l4 4L19 7`,gs=`M6 12h12`;function _s({checked:e,onCheckedChange:t,disabled:n,indeterminate:r,label:i,className:o,id:s,"aria-label":c,"aria-describedby":l}){let u=(0,Z.useId)(),d=s??u,f=It(),p=e||r,m=r?gs:hs;return(0,Q.jsxs)(`label`,{htmlFor:d,className:a(`inline-flex items-center gap-3`,n?`cursor-not-allowed`:`cursor-pointer`,o),children:[(0,Q.jsx)(Lt.button,{id:d,type:`button`,role:`checkbox`,"aria-checked":r?`mixed`:e,"aria-label":c,"aria-describedby":l,disabled:n,onClick:()=>{n||t(!e)},whileTap:f||n?void 0:{scale:.94},transition:{duration:.12,ease:Et},"data-state":e?`checked`:r?`indeterminate`:`unchecked`,className:a(`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`,p?`border-foreground bg-foreground text-background`:`border-muted-foreground/40 bg-background hover:border-muted-foreground`),children:(0,Q.jsx)(zt,{initial:!1,children:p?(0,Q.jsxs)(Lt.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:f?{opacity:1}:{opacity:0,scale:.5},animate:f?{opacity:1}:{opacity:1,scale:1},exit:f?{opacity:0}:{opacity:0,scale:.5},transition:f?{duration:0}:{duration:.16,ease:Et},"aria-hidden":!0,children:[(0,Q.jsx)(`title`,{children:r?`Partially selected`:`Selected`}),(0,Q.jsx)(Lt.path,{d:m,initial:f?{pathLength:1}:{pathLength:0},animate:{pathLength:1},transition:f?{duration:0}:{duration:r?.2:.3,ease:Et,delay:.04}})]},r?`indeterminate`:`checked`):null})}),i?(0,Q.jsx)(`span`,{children:i}):null]})}function vs({className:e,...t}){return(0,Q.jsx)(`nav`,{"aria-label":`breadcrumb`,"data-slot":`breadcrumb`,className:a(e),...t})}function ys({className:e,...t}){return(0,Q.jsx)(`ol`,{"data-slot":`breadcrumb-list`,className:a(`flex flex-wrap items-center gap-1.5 text-sm wrap-break-word text-muted-foreground`,e),...t})}function bs({className:e,...t}){return(0,Q.jsx)(`li`,{"data-slot":`breadcrumb-item`,className:a(`inline-flex items-center gap-1`,e),...t})}function xs({className:e,render:t,...n}){return $e({defaultTagName:`a`,props:O({className:a(`transition-colors hover:text-foreground`,e)},n),render:t,state:{slot:`breadcrumb-link`}})}function Ss({className:e,...t}){return(0,Q.jsx)(`span`,{"data-slot":`breadcrumb-page`,role:`link`,"aria-disabled":`true`,"aria-current":`page`,className:a(`font-normal text-foreground`,e),...t})}function Cs({children:e,className:t,...n}){return(0,Q.jsx)(`li`,{"data-slot":`breadcrumb-separator`,role:`presentation`,"aria-hidden":`true`,className:a(`[&>svg]:size-3.5`,t),...n,children:e??(0,Q.jsx)(q,{icon:g,className:`cn-rtl-flip`})})}function ws(e){return e.length===0||e.startsWith(`/`)||e.includes(`..`)?!1:/^[\x20-\x7E]+$/.test(e)}function Ts(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 Es(e){let t=e.replace(/^\/+|\/+$/g,``).split(`/`).filter(e=>e.length>0);return t.length===0?``:`${t.map(e=>ws(e)?e:Ts(e,`folder`)).join(`/`)}/`}function Ds(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 Os(){let e=new Uint8Array(4);return crypto.getRandomValues(e),[...e].map(e=>e.toString(16).padStart(2,`0`)).join(``)}function ks(e,t=``,n=Os()){let r=Ds(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`${Es(t)}${Ts(s)}-${n}${r}`}var As=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`avif`,`bmp`,`ico`]),js=new Set([`txt`,`md`,`csv`,`tsv`,`log`,`json`,`xml`,`yml`,`yaml`,`toml`,`ini`,`cfg`,`conf`]),Ms=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(`.`)),Ns=new Set([`mp4`,`webm`,`mov`,`m4v`,`ogv`]),Ps=new Set([`mp3`,`wav`,`ogg`,`m4a`,`aac`,`flac`,`opus`,`oga`]),Fs=new Set([`zip`,`tar`,`gz`,`tgz`,`7z`]);function Is(e){let t=e.replace(/\/+$/,``),n=t.lastIndexOf(`/`);return n===-1?t:t.slice(n+1)}function Ls(e){let t=Is(e),n=t.lastIndexOf(`.`);return n<=0||n===t.length-1?``:t.slice(n+1).toLowerCase()}function Rs(e){let t=Ls(e);return t===`pdf`?`pdf`:t===`patch`||t===`diff`?`patch`:As.has(t)?`image`:Ns.has(t)?`video`:Ps.has(t)?`audio`:Fs.has(t)?`archive`:Ms.has(t)?`code`:js.has(t)?`text`:`binary`}function zs(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 Bs(e){return e===`text`||e===`code`||e===`patch`}function Vs(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 Hs(e,t){if(Ls(t)!==`json`)return e;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function Us(e){let t=e.replace(/^\/+/,``).replace(/\/+$/,``);return t.length===0?``:`${t}/`}function Ws(e){let t=Us(e);if(t.length===0)return``;let n=t.slice(0,-1),r=n.lastIndexOf(`/`);return r===-1?``:`${n.slice(0,r+1)}`}function Gs(e){let t=Us(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 Ks(e,t){let n=Gs(e),r=n[0];return r&&r.name===t?n.slice(1):n}function qs(e,t){let n=Us(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 Js(e,t){let n=t.trim().toLowerCase();return n.length===0?[]:e.filter(e=>{let t=(e.originalName??Is(e.key)).toLowerCase();return e.key.toLowerCase().includes(n)||t.includes(n)}).map(e=>({kind:`file`,name:e.originalName??Is(e.key),key:e.key,sizeBytes:e.sizeBytes??0,warnings:e.warnings??[]})).sort((e,t)=>e.key.localeCompare(t.key))}function Ys(e,t){let n=Us(t);return n.length===0?e.map(e=>e.key):e.filter(e=>e.key.startsWith(n)).map(e=>e.key)}var Xs={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 Zs({kind:e,className:t,well:n=!0}){let r=e===`folder`?Le:e===`image`?ne:e===`pdf`?we:e===`video`?x:e===`audio`?d:je;return(0,Q.jsx)(`span`,{className:a(`inline-flex shrink-0 items-center justify-center`,n&&`size-7 rounded-md border`,n?Xs[e]:L(Xs[e]),t),"aria-hidden":!0,children:(0,Q.jsx)(q,{icon:r,className:`size-3.5`})})}function Qs(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 $s(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 ec(e,t){return e===`utf8`?new TextEncoder().encode(t):$s(t)}function tc(e,t,n){let r=new Blob([nc(t)],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=e,a.click(),URL.revokeObjectURL(i)}function nc(e){let t=new Uint8Array(e.byteLength);return t.set(e),t.buffer}var rc=[`console.store.object`];function ic(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 ac(e,t){return R({queryKey:[...rc,e],enabled:t&&e!==null,queryFn:async()=>{if(!e)throw Error(`Missing file get input`);let t=await r(e),n=ic(t);if(n)throw n;if(!t.data)throw Error(`Empty store object`);return t.data}})}function oc(){let e=o();return ot({mutationFn:async e=>{let t=await nt({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=ic(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:Xn}),e.invalidateQueries({queryKey:rc}),e.invalidateQueries({queryKey:Rr})])}})}function sc({open:e,onOpenChange:t,storeRef:r,tenant:i,objectKey:a,sizeBytes:o,originalName:s,warnings:c=[],onDelete:l}){let u=ac((0,Z.useMemo)(()=>a?{ref:r,key:a,...i?{tenant:i}:{}}:null,[r,a,i]),e&&a!==null),d=a?Rs(a):null,f=a?Is(a):null,p=(0,Z.useMemo)(()=>u.data?ec(u.data.encoding,u.data.body):null,[u.data]),m=d?Vs(d):`none`,h=(0,Z.useMemo)(()=>{if(!u.data||!p||u.data.truncated||m!==`image`&&m!==`pdf`&&m!==`video`&&m!==`audio`)return null;let e=new Blob([nc(p)],{type:u.data.contentType});return URL.createObjectURL(e)},[u.data,p,m]);if((0,Z.useEffect)(()=>()=>{h&&URL.revokeObjectURL(h)},[h]),!a||!d||!f)return(0,Q.jsx)(Q.Fragment,{});let g=u.data&&Bs(d)&&u.data.encoding===`utf8`?u.data.body:null;return(0,Q.jsx)(U,{open:e,onOpenChange:t,children:(0,Q.jsxs)(Ne,{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)(Zs,{kind:d}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(Ye,{className:`truncate text-sm`,children:u.data?.originalName??s??f}),(0,Q.jsxs)(Ue,{className:`font-mono text-[11px]`,children:[zs(d),(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`mx-1 text-border`,children:`·`}),Tr(u.data?.sizeBytes??o??0)]})]})]})}),(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:u.isLoading?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 p-4`,children:[(0,Q.jsx)(At,{className:`h-28 w-full`}),(0,Q.jsx)(At,{className:`h-3 w-2/3`}),(0,Q.jsx)(At,{className:`h-3 w-1/2`})]}):u.isError?(0,Q.jsx)(`p`,{className:`px-4 py-4 text-[11px] text-destructive`,children:u.error.message}):(0,Q.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Q.jsx)(cc,{kind:d,name:f,mode:m,text:g,objectUrl:h,truncated:u.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:[u.data?.originalName??s?(0,Q.jsx)(uc,{label:`Original name`,value:u.data?.originalName??s??``}):null,(0,Q.jsx)(uc,{label:`Key`,mono:!0,value:a}),(0,Q.jsx)(uc,{label:`Type`,value:u.data?.contentType??`—`}),(0,Q.jsx)(uc,{label:`Size`,value:Tr(u.data?.sizeBytes??o??0)})]}),c.length>0||(u.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:(u.data?.warnings??c).map(e=>(0,Q.jsxs)(`li`,{className:`flex items-start gap-1.5`,children:[(0,Q.jsx)(q,{icon:De,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)(F,{type:`button`,variant:`outline`,size:`sm`,disabled:!p||u.data?.truncated,onClick:()=>{!p||!u.data||tc(f,p,u.data.contentType)},children:[(0,Q.jsx)(q,{icon:we,className:`size-3.5`,"aria-hidden":!0}),`Download`]}),(0,Q.jsx)(F,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`Copy key`,onClick:()=>void navigator.clipboard.writeText(a),children:(0,Q.jsx)(q,{icon:Be})})]}),l?(0,Q.jsxs)(F,{type:`button`,variant:`destructive`,size:`sm`,onClick:l,"data-slot":`file-preview-delete`,children:[(0,Q.jsx)(q,{icon:n,className:`size-3.5`,"aria-hidden":!0}),`Delete`]}):null]})]})})}function cc({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:[zs(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=Ls(t);return e===`csv`||e===`tsv`?(0,Q.jsx)(lc,{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:[Hs(r,t),a?`
19
- … truncated`:``]})}return(0,Q.jsxs)(`p`,{className:`px-4 py-6 text-center text-[11px] text-muted-foreground`,children:[zs(e),` — download to open`,a?` (preview truncated)`:``,`.`]})}function lc({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 uc({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:a(`break-all text-foreground/80`,n&&`font-mono text-[10px]`),children:t})]})}function dc(){let e=new Uint8Array(4);return crypto.getRandomValues(e),[...e].map(e=>e.toString(16).padStart(2,`0`)).join(``)}function fc({open:e,onOpenChange:t,storeRef:n,tenant:r,prefix:i,existingKeys:o,pendingFiles:c=[]}){let{mutate:l,isPending:u,reset:d}=oc(),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(``),[g,_]=(0,Z.useState)(``),[v,y]=(0,Z.useState)(null),[b,x]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{if(!e)return;let t=c[0]??null;y(t);let n=t?Is(t.name):``,r=dc();h(r),p(n),_(n?ks(n,i,r):``),x(null),d()},[e,i,c,d]);let S=async()=>{let e=f.trim();if(!v){x(`Choose a file to upload`);return}if(e.length===0){x(`Original name is required`);return}let a=g.trim().length>0?g.trim():ks(e,i);if(o.includes(a)){x(`That key is already in this bucket`);return}let s=new Uint8Array(await v.arrayBuffer());x(null),l({ref:n,key:a,...r?{tenant:r}:{},body:Qs(s),encoding:`base64`,originalName:e},{onSuccess:()=>t(!1),onError:e=>x(e instanceof Error?e.message:String(e))})};return(0,Q.jsx)(U,{open:e,onOpenChange:t,children:(0,Q.jsxs)(Ne,{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)(Ye,{className:`text-sm`,children:`Upload object`}),(0,Q.jsx)(Ue,{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)(J,{label:`Original name`,hint:`Shown in the browser. Unicode is fine.`,children:(0,Q.jsx)(s,{value:f,onChange:e=>{let t=e.target.value;p(t);let n=m.length>0?m:dc();m.length===0&&h(n),_(t.trim().length>0?ks(t.trim(),i,n):``)},"aria-label":`Original name`,flat:!0,className:Y,autoFocus:!0})}),(0,Q.jsx)(J,{label:`Object key`,hint:`URL-safe. Generated from the original name.`,children:(0,Q.jsx)(s,{value:g,readOnly:!0,"aria-label":`Object key`,flat:!0,className:a(Y,`font-mono text-muted-foreground`)})}),(0,Q.jsx)(J,{label:`File`,hint:v?`${Is(v.name)} · ${v.size} B`:void 0,children:(0,Q.jsx)(s,{type:`file`,"aria-label":`File`,flat:!0,className:a(Y,`pt-1.5`),onChange:e=>{let t=e.target.files?.[0]??null;if(y(t),!t)return;let n=Is(t.name),r=m.length>0?m:dc();m.length===0&&h(r),p(n),_(ks(n,i,r))}})}),b?(0,Q.jsx)(on,{slot:`file-upload-error`,children:b}):null]}),(0,Q.jsxs)(fe,{children:[(0,Q.jsx)(Zt,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(Zt,{variant:`default`,disabled:u,onClick:()=>void S(),"data-slot":`file-upload-submit`,children:u?`Uploading…`:`Upload`})]})]})})}function pc({store:e,child:t,tenant:r,data:i,fetching:o=!1,onRefresh:c}){let[l,u]=(0,Z.useState)(``),[d,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(`list`),[g,_]=(0,Z.useState)(null),[v,y]=(0,Z.useState)(new Set),[b,x]=(0,Z.useState)(!1),[S,C]=(0,Z.useState)([]),[w,T]=(0,Z.useState)(null),[E,O]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{u(``),p(``),_(null),y(new Set)},[t.effectRef]);let k=i.keys??[],A=d.trim().length>0,j=(0,Z.useMemo)(()=>A?{folders:[],files:Js(k,d)}:qs(k,l),[k,l,d,A]),M=(0,Z.useMemo)(()=>[...j.folders,...j.files],[j]),N=Ks(l,t.name),P=j.files.find(e=>e.key===g)??null,L=ha(),R=(e,t)=>{y(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},ee=e=>{if(e.kind===`folder`){u(e.prefix),_(null),y(new Set);return}_(e.key)},z=()=>{if(v.size===0&&g)return[g];let e=[];for(let t of v)t.endsWith(`/`)?e.push(...Ys(k,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)(X,{label:`Up one folder`,children:(0,Q.jsx)(F,{type:`button`,variant:`ghost`,size:`icon-xs`,disabled:l.length===0||A,"aria-label":`Parent folder`,onClick:()=>{u(Ws(l)),_(null)},children:(0,Q.jsx)(q,{icon:D,className:`size-3.5`})})}),(0,Q.jsx)(vs,{className:`min-w-0 flex-1`,children:(0,Q.jsxs)(ys,{className:`flex-nowrap gap-1 text-[11px]`,children:[(0,Q.jsx)(bs,{children:l.length===0||A?(0,Q.jsx)(Ss,{className:`font-mono text-[11px]`,children:t.name}):(0,Q.jsx)(xs,{href:`#`,className:`font-mono text-[11px]`,onClick:e=>{e.preventDefault(),u(``),_(null)},children:t.name})}),N.map((e,t)=>(0,Q.jsxs)(`span`,{className:`contents`,children:[(0,Q.jsx)(Cs,{className:`mx-0`}),(0,Q.jsx)(bs,{children:t===N.length-1?(0,Q.jsx)(Ss,{className:`font-mono text-[11px]`,children:e.name}):(0,Q.jsx)(xs,{href:`#`,className:`font-mono text-[11px]`,onClick:t=>{t.preventDefault(),u(e.prefix),_(null)},children:e.name})})]},e.prefix))]})}),(0,Q.jsxs)(`div`,{className:`relative w-44`,children:[(0,Q.jsx)(q,{icon:V,className:`pointer-events-none absolute top-1/2 left-2 size-3 -translate-y-1/2 text-muted-foreground`}),(0,Q.jsx)(s,{value:d,onChange:e=>p(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)(X,{label:m===`list`?`Grid view`:`List view`,children:(0,Q.jsx)(F,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":m===`list`?`Grid view`:`List view`,onClick:()=>h(e=>e===`list`?`grid`:`list`),children:(0,Q.jsx)(q,{icon:m===`list`?pe:I,className:`size-3.5`})})}),(0,Q.jsx)(X,{label:`Upload into this folder`,children:(0,Q.jsxs)(F,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px] text-muted-foreground`,"data-slot":`file-upload`,onClick:()=>{C([]),x(!0)},children:[(0,Q.jsx)(q,{icon:le,className:`size-3.5`}),`Upload`]})}),(0,Q.jsx)(X,{label:z().length>0?`Delete ${z().length} object${z().length===1?``:`s`}`:`Select objects to delete`,children:(0,Q.jsxs)(F,{type:`button`,variant:`destructive`,size:z().length>0?`xs`:`icon-xs`,disabled:z().length===0,onClick:()=>T(z()),"aria-label":`Delete selected`,"data-slot":`file-delete`,children:[(0,Q.jsx)(q,{icon:n,className:`size-3.5`}),z().length>0?z().length:null]})}),(0,Q.jsx)(X,{label:`Reload from the store`,children:(0,Q.jsx)(F,{type:`button`,variant:`ghost`,size:`icon-xs`,disabled:o,"aria-label":`Refresh`,"data-slot":`browse-refresh`,onClick:c,children:(0,Q.jsx)(q,{icon:f,className:o?`size-3.5 animate-spin`:`size-3.5`})})})]}),(0,Q.jsxs)(`div`,{className:a(`flex min-h-0 flex-1 flex-col`,E&&`bg-sky-500/5`),onDragOver:e=>{e.preventDefault(),O(!0)},onDragLeave:()=>O(!1),onDrop:e=>{e.preventDefault(),O(!1);let t=[...e.dataTransfer.files];t.length!==0&&(C(t),x(!0))},"data-slot":`file-drop`,children:[M.length===0?(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center px-6`,children:(0,Q.jsx)($n,{role:`status`,"data-slot":`files-empty`,children:(0,Q.jsxs)(fr,{children:[(0,Q.jsx)(er,{variant:`icon`,children:(0,Q.jsx)(q,{icon:Le})}),(0,Q.jsx)(or,{children:A?`No matching objects`:`This folder is empty`}),(0,Q.jsx)(lr,{children:A?`Try another name or clear the filter.`:`Drop files here or upload into this prefix.`})]})})}):m===`grid`?(0,Q.jsx)(hc,{entries:M,selectedKey:g,checked:v,onOpen:ee,onToggle:R}):(0,Q.jsx)(mc,{entries:M,selectedKey:g,checked:v,searching:A,onOpen:ee,onToggle:R}),(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:[j.folders.length,` folder`,j.folders.length===1?``:`s`,(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`mx-1 text-border`,children:`·`}),j.files.length,` object`,j.files.length===1?``:`s`,o?` · refreshing`:``]}),(0,Q.jsx)(`span`,{children:`Drop to upload · click a folder to open · click a file to inspect`})]})]}),(0,Q.jsx)(sc,{open:g!==null,onOpenChange:e=>{e||_(null)},storeRef:e.ref,tenant:r,objectKey:g,sizeBytes:P?.sizeBytes,originalName:P?.name,warnings:P?.warnings,onDelete:g?()=>{T([g])}:void 0}),(0,Q.jsx)(fc,{open:b,onOpenChange:x,storeRef:e.ref,tenant:r,prefix:l,existingKeys:k.map(e=>e.key),pendingFiles:S}),(0,Q.jsx)(ms,{open:w!==null,onOpenChange:e=>{e||T(null)},phrase:`DELETE`,title:`Delete ${w?.length??0} ${w?.length===1?`object`:`objects`}`,description:`Permanently delete ${w?.length??0} object(s) from ${e.ref}. This is not a flow execution.`,pending:L.isPending,error:L.isError?L.error.message:null,onConfirm:t=>{w&&L.mutate({ref:e.ref,...r?{tenant:r}:{},keys:w,confirmation:t.confirmation,reason:t.reason},{onSuccess:()=>{T(null),y(new Set),_(null),c()}})}})]})}function mc({entries:e,selectedKey:t,checked:n,searching:r,onOpen:i,onToggle:o}){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 s=e.kind===`folder`?e.prefix:e.key,c=e.kind===`file`&&e.key===t;return(0,Q.jsxs)(`div`,{role:`listitem`,"data-slot":e.kind===`folder`?`file-folder`:`file-object`,className:a(`flex h-8 cursor-default items-center gap-2 border-b border-border/60 px-3 text-xs`,c&&`bg-muted/70`,!c&&`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)(_s,{checked:n.has(s),onCheckedChange:e=>o(s,e),"aria-label":`Select ${e.name}`})}),(0,Q.jsx)(Zs,{kind:e.kind===`folder`?`folder`:Rs(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)(q,{icon:De,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`:zs(Rs(e.name))}),(0,Q.jsx)(`span`,{className:`w-16 text-right font-mono text-[11px] tabular-nums text-muted-foreground`,children:Tr(e.sizeBytes)})]},s)})]})}function hc({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 o=e.kind===`folder`?e.prefix:e.key,s=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:a(`relative flex flex-col items-center gap-2 rounded-lg border px-2 py-3 text-center`,s?`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)(_s,{checked:n.has(o),onCheckedChange:e=>i(o,e),"aria-label":`Select ${e.name}`})}),(0,Q.jsx)(Zs,{kind:e.kind===`folder`?`folder`:Rs(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`:Tr(e.sizeBytes)})]},o)})})}function gc(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 _c(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 vc(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}var yc=(e,t)=>Math.abs(e-t)<1.01,bc=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},xc,Sc=()=>{if(xc!==void 0)return xc;if(typeof navigator>`u`)return xc=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return xc=!0;let e=navigator.maxTouchPoints;return xc=navigator.platform===`MacIntel`&&e!==void 0&&e>0},Cc=e=>{let{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},wc=e=>e,Tc=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},Ec=(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(Cc(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(Cc(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(r):r()});return a.observe(n,{box:`border-box`}),()=>{a.unobserve(n)}},Dc={passive:!0},Oc=typeof window>`u`||`onscrollend`in window,kc=(e,t,n)=>{let r=e.scrollElement;if(!r)return;let i=e.targetWindow;if(!i)return;let a=e.options.useScrollendEvent&&Oc,o=0,s=a?null:bc(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,Dc),a&&r.addEventListener(`scrollend`,u,Dc),()=>{r.removeEventListener(`scroll`,l),a&&r.removeEventListener(`scrollend`,u)}},Ac=(e,t)=>kc(e,t,t=>{let{horizontal:n,isRtl:r}=e.options;return n?t.scrollLeft*(r&&-1||1):t.scrollTop}),jc=(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`]},Mc=(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})},Nc=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.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.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:wc,rangeExtractor:Tc,onChange:()=>{},measureElement:jc,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=_c(()=>(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._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,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.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,!(!Sc()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};e.addEventListener(`touchstart`,t,Dc),e.addEventListener(`touchend`,n,Dc),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&&(Sc()&&(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._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=_c(()=>[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.getMeasurements=_c(()=>[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=gc(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=_c(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,r)=>e.length===0||t===0?(this.range=null,null):(this.range=Ic(e,t,n,r,r===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=_c(()=>{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),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(e<0||e>=this.options.count)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.getVirtualItems=_c(()=>[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 vc(t[Pc(0,t.length-1,r?e=>n[e*2]:e=>vc(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){return e===0?!1:Sc()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?(this._iosDeferredAdjustment+=e,!1):(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&&yc(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()}},Pc=(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 Fc(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 Ic(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=Fc(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=Pc(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 Lc=typeof document<`u`?Z.useLayoutEffect:Z.useEffect;function Rc({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,Di.flushSync)(i):i()),(o=r.onChange)==null||o.call(r,t,n)}},[l]=Z.useState(()=>{let e=new Nc(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),Lc(()=>l._didMount(),[]),Lc(()=>(o(l),l._willUpdate())),Lc(()=>{s(l)}),l}function zc(e){return Rc({observeElementRect:Ec,observeElementOffset:Ac,scrollToFn:Mc,...e})}var Bc=188;function Vc({items:e,ariaLabel:t,trigger:n,triggerClassName:r}){let i=It(),o=(0,Z.useRef)(null),[s,c]=(0,Z.useState)(null),l=s!==null;(0,Z.useEffect)(()=>{if(!l)return;let e=()=>c(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)}},[l]);let u=()=>{if(l){c(null);return}let e=o.current;if(!e)return;let t=e.getBoundingClientRect();c({top:t.bottom+4,left:Math.max(8,t.right-Bc)})};return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{ref:o,type:`button`,"aria-label":t,"aria-haspopup":`menu`,"aria-expanded":l,onClick:e=>{e.stopPropagation(),u()},className:r,children:n}),l&&s&&typeof document<`u`?(0,Di.createPortal)((0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`fixed inset-0 z-40`,onPointerDown:()=>c(null)}),(0,Q.jsx)(Lt.div,{role:`menu`,className:`fixed z-50 overflow-hidden rounded-xl border border-border bg-background p-1 shadow-xl`,style:{top:s.top,left:s.left,width:Bc},initial:i?{opacity:0}:{opacity:0,scale:.96,y:-4},animate:i?{opacity:1}:{opacity:1,scale:1,y:0},transition:i?{duration:0}:Tt,children:e.map(e=>(0,Q.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{c(null),e.onSelect()},className:a(`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 Hc({rowEl:e,id:t,index:r,onInsertRow:i,onDeleteRow:a,onEnter:o,onLeave:s}){if((0,Z.useEffect)(()=>(window.addEventListener(`scroll`,s,!0),()=>window.removeEventListener(`scroll`,s,!0)),[s]),!e||typeof document>`u`)return null;let c=e.getBoundingClientRect();return(0,Di.createPortal)((0,Q.jsx)(`div`,{style:{position:`fixed`,top:c.top+c.height/2,left:c.left,transform:`translate(-50%, -50%)`,zIndex:40},onPointerEnter:o,onPointerLeave:s,children:(0,Q.jsx)(Vc,{ariaLabel:`Row ${r+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)(q,{icon:E,className:`size-3`}),items:[...i?[{label:`Insert before`,icon:(0,Q.jsx)(q,{icon:S}),onSelect:()=>i(r,`before`)},{label:`Insert after`,icon:(0,Q.jsx)(q,{icon:C}),onSelect:()=>i(r,`after`)}]:[],...a?[{label:`Delete row`,icon:(0,Q.jsx)(q,{icon:n}),destructive:!0,onSelect:()=>a(t,r)}]:[]]})}),document.body)}var Uc=`48px`,Wc=a(`[&_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!`),Gc=`inset 0 1px 0 var(--color-sky-500)`;function Kc(e){return a(`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 qc(e){return e===`right`?`justify-end`:e===`center`?`justify-center`:`justify-start`}function Jc(e){return e===`right`?`text-right`:e===`center`?`text-center`:`text-left`}function Yc(e,t){return t.cell?t.cell(e):e[t.key]}function Xc(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 Zc(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 Qc(e,t,n){return e?{inRange:ii(e,t,n),isHead:e.head.row===t&&e.head.col===n}:{inRange:!1,isHead:!1}}function $c({count:e,columns:t,selectable:n,rowHeight:r,slack:i=!0}){return(0,Q.jsx)(Q.Fragment,{children:Array.from({length:e},(e,o)=>(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:a(`px-4`,Jc(e.align)),children:(0,Q.jsx)(`div`,{className:a(`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]},o))})}function el(e,t,r,i){return[...r?[{label:`Insert before`,icon:(0,Q.jsx)(q,{icon:D}),onSelect:()=>r(t,`before`)},{label:`Insert after`,icon:(0,Q.jsx)(q,{icon:g}),onSelect:()=>r(t,`after`)}]:[],...i?[{label:`Delete column`,icon:(0,Q.jsx)(q,{icon:n}),destructive:!0,onSelect:()=>i(e.key,t)}]:[]]}function tl({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,Di.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)(Vc,{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)(q,{icon:w,className:`size-3`}),items:el(e,t,r,i)})}),document.body)}function nl({columns:e,rowHeight:t,reduce:n,thRefs:r,selectable:i,allSelected:o,someSelected:s,onToggleAll:c,sort:l,onToggleSort:u,resizable:d,onResizeStart:f,onResizeMove:p,onResizeEnd:m,reorderable:h,dragKey:g,dropIndex:_,onReorderStart:v,onReorderMove:y,onReorderEnd:b,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)(tl,{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)(_s,{checked:o,indeterminate:s&&!o,onCheckedChange:()=>c(),"aria-label":`Select all rows`,className:Wc})})}):null,e.map((i,o)=>{let s=l?.key===i.key,c=g===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:Gc}:void 0,"aria-sort":s?l?.direction===`asc`?`ascending`:`descending`:void 0,"data-drop":g?_===o:void 0,"data-dropend":g?_===e.length&&o===e.length-1:void 0,className:a(`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)(Lt.div,{className:a(`flex h-full w-full min-w-0 items-center`,qc(i.align)),style:{height:t},animate:n?{opacity:c?.5:1}:{scale:c?1.04:1,opacity:c?.5:1},transition:wt,children:[h?(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Reorder ${i.key}`,onPointerDown:e=>v(i.key,e),onPointerMove:y,onPointerUp:b,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)(q,{icon:xe,className:`size-3.5`})}):null,i.sortable?(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>u(i.key),className:a(`flex h-full min-w-0 flex-1 select-none items-center gap-1 px-4 transition-colors hover:text-foreground`,qc(i.align),s&&`text-foreground`),children:[i.header,(0,Q.jsx)(Lt.span,{"aria-hidden":!0,className:`inline-flex shrink-0`,animate:{rotate:s&&l?.direction===`desc`?180:0,opacity:s?1:.35},transition:n?{duration:0}:{duration:.18,ease:Et},children:(0,Q.jsx)(q,{icon:S,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:a(`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`,Jc(i.align))}):(0,Q.jsx)(`div`,{className:a(`min-w-0 flex-1 truncate px-4`,Jc(i.align)),children:i.header})]}),d?(0,Q.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize ${i.key}`,onPointerDown:e=>f(i.key,e),onPointerMove:p,onPointerUp:m,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 rl({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 il({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 al({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=Xc(e.row,n),i=Xc(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 sl=`input, textarea, button, [role='checkbox']`,cl=4;function ll(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 ul(e,t,n){return e?e.anchor.row===t&&e.anchor.col===n&&e.head.row===t&&e.head.col===n:!1}function dl(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(sl))return;t.current=!0,n.current=!1,i.current={x:l.clientX,y:l.clientY,row:e,col:s},r.current=!l.shiftKey&&ul(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||ll(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)>cl&&(n.current=!0,r.current=!1);let c=ll(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 fl({data:e,columns:t,getRowId:n,selectable:r=!1,selectedRowIds:i,defaultSelectedRowIds:o,onSelectionChange:s,sort:c,defaultSort:l=null,onSortChange:u,resizable:d=!1,minColumnWidth:f=64,onColumnResize:p,reorderable:m=!1,onColumnOrderChange:h,onCellEdit:g,onColumnRename:_,onInsertRow:v,onDeleteRow:y,onInsertColumn:b,onDeleteColumn:x,onRowDoubleClick:S,cellRange:C=null,onCellRangeChange:w,onCellActivate:T,rowHeight:E=48,height:D=440,overscan:O=10,onEndReached:k,loading:A=!1,skeletonRows:j=3,emptyState:M=`No data`,className:N}){let P=!!It(),F=(0,Z.useRef)(null),I=(0,Z.useRef)({}),L=(0,Z.useMemo)(()=>e.map((e,t)=>({row:e,id:n?n(e,t):String(t)})),[e,n]),{orderedColumns:R,dragKey:ee,dropIndex:z,startReorder:B,moveReorder:V,endReorder:te}=rl({columns:t,thRefs:I,onColumnOrderChange:h}),{sort:H,sortedRows:ne,toggleSort:re}=al({rows:L,columns:t,sort:c,defaultSort:l,onSortChange:u}),{widths:ie,startResize:ae,moveResize:oe,endResize:se}=il({orderedColumns:R,thRefs:I,minColumnWidth:f,onColumnResize:p}),{selected:ce,allSelected:le,someSelected:ue,toggleAll:de,toggleRow:fe}=ol({sortedRows:ne,selectedRowIds:i,defaultSelectedRowIds:o,onSelectionChange:s}),pe=dl({enabled:w!==void 0,range:C,onChange:w,onActivate:T}),me=zc({count:ne.length,getScrollElement:()=>F.current,estimateSize:()=>E,overscan:O}),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||y),Se=R.length>0&&R.every(e=>ie[e.key]!=null),Ce=(0,Z.useRef)(!1);(0,Z.useEffect)(()=>{A||(Ce.current=!1)},[A]);let U=(0,Z.useCallback)(()=>{let e=F.current;!e||!k||A||Ce.current||e.scrollHeight-e.scrollTop-e.clientHeight<E*4&&(Ce.current=!0,k())},[k,A,E]),[we,Te]=(0,Z.useState)(null),Ee=(0,Z.useRef)(null),De=(0,Z.useCallback)(e=>{Ee.current&&clearTimeout(Ee.current),Ee.current=null,Te(e)},[]),Oe=(0,Z.useCallback)(()=>{Ee.current&&clearTimeout(Ee.current),Ee.current=setTimeout(()=>Te(null),100)},[]),W=(0,Z.useRef)({}),[G,ke]=(0,Z.useState)(null),Ae=(0,Z.useRef)(null),je=(0,Z.useCallback)((e,t)=>{Ae.current&&clearTimeout(Ae.current),Ae.current=null,ke({id:e,index:t})},[]),Me=(0,Z.useCallback)(()=>{Ae.current&&clearTimeout(Ae.current),Ae.current=setTimeout(()=>ke(null),100)},[]),Ne=G?W.current[G.id]??null:null,Pe=t.length+ +!!r,Fe=!R.some(e=>e.fill&&ie[e.key]==null),K=Pe+ +!!Fe;return(0,Q.jsxs)(`div`,{className:a(`w-full overflow-hidden border border-border/60 bg-background text-sm`,N),children:[(0,Q.jsx)(`div`,{ref:F,"data-slot":`table-scroller`,onScroll:U,onPointerDown:pe.onScrollerPointerDown,onPointerMove:pe.onScrollerPointerMove,onPointerUp:pe.onPointerUp,onPointerCancel:pe.onPointerUp,className:a(`overflow-auto`,w?`select-none`:void 0),style:{height:D},children:(0,Q.jsxs)(`table`,{className:a(`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:Uc}}):null,R.map(e=>{let t=ie[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)(nl,{columns:R,rowHeight:E,reduce:P,thRefs:I,selectable:r,allSelected:le,someSelected:ue,onToggleAll:de,sort:H,onToggleSort:re,resizable:d,onResizeStart:ae,onResizeMove:oe,onResizeEnd:se,reorderable:m,dragKey:ee,dropIndex:z,onReorderStart:B,onReorderMove:V,onReorderEnd:te,onInsertColumn:b,onDeleteColumn:x,onColumnRename:_,activeColumn:we,onColumnActivate:De,onColumnDeactivate:Oe,slack:Fe}),(0,Q.jsx)(`tbody`,{children:ne.length===0?A?(0,Q.jsx)($c,{count:j,columns:R,selectable:r,rowHeight:E,slack:Fe}):(0,Q.jsx)(`tr`,{children:(0,Q.jsx)(`td`,{colSpan:K,className:`px-4 py-8 text-center text-muted-foreground`,children:M})}):(0,Q.jsxs)(Q.Fragment,{children:[ye>0?(0,Q.jsx)(`tr`,{children:(0,Q.jsx)(`td`,{colSpan:K,style:{height:ye,padding:0,border:`none`}})}):null,he.map(e=>{let t=ne[e.index];if(!t)return null;let n=ce.has(t.id);return(0,Q.jsxs)(`tr`,{ref:e=>{W.current[t.id]=e},"data-selected":n,style:{height:E},onPointerEnter:xe?()=>je(t.id,e.index):void 0,onPointerLeave:xe?Me:void 0,onDoubleClick:e=>{if(!S)return;let n=e.target;n instanceof Element&&n.closest(`input, textarea, button, [role='checkbox'], [data-slot='cell-display']`)||S(t.row,t.id)},className:a(`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:a(`px-4 align-middle`,Kc(n),n&&`bg-sky-500/10`),children:(0,Q.jsx)(`div`,{className:`flex items-center justify-center`,style:{height:E},children:(0,Q.jsx)(_s,{checked:n,onCheckedChange:()=>fe(t.id),"aria-label":`Select row ${e.index+1}`,className:Wc})})}):null,R.map((r,i)=>{let o=Qc(C,e.index,i);return(0,Q.jsx)(`td`,{"data-slot":`table-cell`,"data-row":String(e.index),"data-col":String(i),"data-range":o.inRange?`in`:void 0,"data-range-head":o.isHead?`true`:void 0,className:a(`relative h-full cursor-cell overflow-hidden p-0`,Jc(r.align),Kc(n),!o.inRange&&`has-[[data-pending=true]]:bg-amber-500/10`,o.inRange&&`bg-sky-500/15`,o.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)(Jr,{value:Zc(t.row,r.key),label:typeof r.header==`string`?r.header:r.key,onChange:e=>g?.(t.id,r.key,e)})}):Yc(t.row,r)},r.key)}),Fe?(0,Q.jsx)(`td`,{"aria-hidden":!0,className:a(Kc(n),n&&`bg-sky-500/10`)}):null]},t.id)}),be>0?(0,Q.jsx)(`tr`,{children:(0,Q.jsx)(`td`,{colSpan:K,style:{height:be,padding:0,border:`none`}})}):null,A?(0,Q.jsx)($c,{count:j,columns:R,selectable:r,rowHeight:E,slack:Fe}):null]})})]})}),xe&&G?(0,Q.jsx)(Hc,{rowEl:Ne,id:G.id,index:G.index,onInsertRow:v,onDeleteRow:y,onEnter:()=>je(G.id,G.index),onLeave:Me}):null]})}function pl(){return ot({mutationFn:async e=>{let t=await H(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 ml({refName:e,child:t,tenant:n,rowId:r,column:i,maskedValue:a}){let o=pl(),[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)(T,{children:[(0,Q.jsx)(b,{render:a=>(0,Q.jsx)(F,{...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)(q,{icon:pe,className:`size-3`,"aria-hidden":!0})})}),(0,Q.jsx)(u,{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:hl(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:hl(s.value)}),(0,Q.jsxs)(T,{children:[(0,Q.jsx)(b,{render:e=>(0,Q.jsx)(F,{...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)(q,{icon:W,className:`size-3`,"aria-hidden":!0})})}),(0,Q.jsx)(u,{side:`top`,className:`text-[11px]`,children:`Hide cleartext`})]})]})}function hl(e){if(e==null)return`—`;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{return JSON.stringify(e)}catch{return`[unserializable]`}}function gl({open:e,onOpenChange:t,storeRef:n,childName:r,tenant:i,existingKeys:o}){let{mutate:c,isPending:l,reset:u}=ma(),[d,f]=(0,Z.useState)(`${r}:`),[p,m]=(0,Z.useState)(`{
20
-
21
- }`),[h,g]=(0,Z.useState)(``),[_,v]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{e&&(f(`${r}:`),m(`{
22
-
23
- }`),g(``),v(null),u())},[e,r,u]),(0,Q.jsx)(U,{open:e,onOpenChange:t,children:(0,Q.jsxs)(Ne,{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)(Ye,{className:`text-sm`,children:`Add key`}),(0,Q.jsx)(Ue,{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)(J,{label:`Key`,children:(0,Q.jsx)(s,{value:d,onChange:e=>f(e.target.value),"aria-label":`Key`,flat:!0,className:a(Y,`font-mono`),autoFocus:!0})}),(0,Q.jsx)(J,{label:`Value`,children:(0,Q.jsx)(`textarea`,{value:p,onChange:e=>m(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)(J,{label:`TTL`,children:(0,Q.jsx)(s,{value:h,onChange:e=>g(e.target.value),"aria-label":`TTL`,placeholder:`30m`,flat:!0,className:a(Y,`font-mono`)})}),_?(0,Q.jsx)(on,{slot:`kv-add-error`,children:_}):null]}),(0,Q.jsxs)(fe,{children:[(0,Q.jsx)(Zt,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(Zt,{variant:`default`,disabled:l,onClick:()=>{let e=d.trim();if(e.length===0||e.endsWith(`:`)){v(`Key needs a name after the prefix`);return}if(o.includes(e)){v(`That key is already on this page`);return}let r=wr(p);if(!r.ok){v(r.error);return}let a=Sr(h);if(a===void 0){v(`TTL must be a duration like 30m, 1h, or empty`);return}v(null),c({ref:n,key:e,...i?{tenant:i}:{},patch:{value:r.value,...a===null?{}:{ttl:a}},commit:!0},{onSuccess:()=>t(!1),onError:e=>v(e instanceof Error?e.message:String(e))})},"data-slot":`kv-add-submit`,children:l?`Adding…`:`Add key`})]})]})})}function _l({open:e,onOpenChange:t,storeRef:n,childName:r,tenant:i,columns:o}){let{mutate:c,isPending:l,reset:u}=ma(),d=(0,Z.useMemo)(()=>Kr(o),[o]),[f,p]=(0,Z.useState)({}),[m,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{e&&(p(Zr(d)),_(null),u())},[e,d,u]);let v=(e,t)=>{p(n=>({...n,[e]:t}))},y=()=>{let e=ei(d,f);if(!e.ok){_(e.error);return}_(null),c({ref:n,child:r,...i?{tenant:i}:{},patch:e.patch,commit:!0},{onSuccess:()=>{if(m){p(Zr(d));return}t(!1)},onError:e=>_(e instanceof Error?e.message:String(e))})};return(0,Q.jsx)(U,{open:e,onOpenChange:t,children:(0,Q.jsxs)(Ne,{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)(Ye,{className:`text-sm`,children:[`Add new row to `,r]}),(0,Q.jsx)(Ue,{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)(J,{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)(s,{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:a(Y,`font-mono`),autoFocus:e.key===`id`})},e.key)}),g?(0,Q.jsx)(on,{slot:`sql-insert-error`,children:g}):null]}),(0,Q.jsx)(Qt,{label:`Create more`,children:(0,Q.jsx)(_a,{size:`sm`,checked:m,onCheckedChange:h,ariaLabel:`Create more`})}),(0,Q.jsxs)(fe,{children:[(0,Q.jsx)(Zt,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(Zt,{variant:`default`,disabled:l,onClick:y,"data-slot":`sql-insert-submit`,children:l?`Saving…`:`Save`})]})]})})}function vl({open:e,openHeight:t=`auto`,className:n,style:r,transition:i,...o}){let s=It()??!1;return(0,Q.jsx)(Lt.div,{...o,"aria-hidden":!e,inert:!e||void 0,initial:!1,animate:s?{opacity:+!!e}:{opacity:+!!e,clipPath:e?`inset(0 0 0% 0)`:`inset(0 0 100% 0)`,y:e?0:-4},transition:i??{duration:s?0:e?.22:.14,ease:Et},className:a(`overflow-hidden`,n),style:{...r,height:e?t:0,pointerEvents:e?void 0:`none`,transformOrigin:`top`}})}function yl({value:e,type:t}){return e?(0,Q.jsxs)(`span`,{className:a(`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 bl({file:e,lines:t,status:n=`streaming`,open:r,defaultOpen:i=!0,onOpenChange:o,collapseOnComplete:s=!0,maxHeight:l=220,language:u=`typescript`,copyText:d,onCopy:f,className:p}){let m=It()??!1,h=(0,Z.useId)(),g=`${h}-trigger`,_=`${h}-content`,v=(0,Z.useRef)(null),y=(0,Z.useRef)(n),b=(0,Z.useRef)(void 0),[x,S]=(0,Z.useState)(!1),[w,T]=(0,Z.useState)(i),E=r??w,D=n===`streaming`,O=t.filter(e=>e.type===`added`).length,k=t.filter(e=>e.type===`removed`).length,A=!!(d||f),j=uo(t.map(e=>e.content).join(`
24
- `),u),M=(0,Z.useCallback)(e=>{r===void 0&&T(e),o?.(e)},[o,r]);(0,Z.useEffect)(()=>{y.current!==`streaming`&&n===`streaming`&&M(!0),y.current===`streaming`&&n===`complete`&&s&&M(!1),y.current=n},[s,M,n]),(0,Z.useEffect)(()=>()=>{b.current&&window.clearTimeout(b.current)},[]),(0,Z.useLayoutEffect)(()=>{let e=v.current;if(!e||!E||!D)return;let t=requestAnimationFrame(()=>{e.scrollHeight<=e.clientHeight||(typeof e.scrollTo==`function`?e.scrollTo({top:e.scrollHeight,behavior:m?`auto`:`smooth`}):e.scrollTop=e.scrollHeight)});return()=>cancelAnimationFrame(t)});let N=(0,Z.useCallback)(async()=>{f?await f():d&&await navigator.clipboard?.writeText(d),S(!0),b.current&&window.clearTimeout(b.current),b.current=window.setTimeout(()=>S(!1),1600)},[d,f]);return(0,Q.jsxs)(`div`,{"data-state":n,"aria-busy":D,className:a(`w-full text-sm`,p),children:[(0,Q.jsxs)(`button`,{id:g,type:`button`,"aria-expanded":E,"aria-controls":_,onClick:()=>M(!E),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)(q,{icon:re,"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)(yl,{value:O,type:`added`}),(0,Q.jsx)(yl,{value:k,type:`removed`}),D?(0,Q.jsx)(q,{icon:c,"aria-label":`Applying changes`,className:a(`size-3.5 text-muted-foreground`,!m&&`animate-spin`)}):null,(0,Q.jsx)(Lt.span,{"aria-hidden":`true`,animate:{rotate:E?180:0},transition:m?{duration:0}:Dt,className:`shrink-0 text-muted-foreground/45 transition-colors group-hover:text-muted-foreground`,children:(0,Q.jsx)(q,{icon:C,className:`size-3.5`})})]}),(0,Q.jsx)(vl,{id:_,role:`region`,"aria-labelledby":g,open:E,children:(0,Q.jsxs)(`div`,{className:`relative overflow-hidden rounded-lg border border-border/70 bg-muted/20`,children:[(0,Q.jsxs)(`div`,{ref:v,"data-slot":`file-diff-viewport`,"aria-live":`polite`,className:`overflow-auto`,style:{maxHeight:l},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:a(`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:a(`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)(fo,{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)(Lt.button,{type:`button`,"aria-label":x?`Copied`:`Copy diff`,title:x?`Copied`:`Copy diff`,onClick:()=>void N(),whileTap:m?void 0:{scale:.9},transition:wt,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)(q,{icon:x?ve:Be,className:`size-3.5`})}):null]})})]})}function xl(e,t){return`${e}\0${t}`}function Sl(e,t,n){let r=new Map(e),i=xl(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 Cl(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 wl(e){return[...e.values()].map(e=>({rowId:e.rowId,key:e.key,prev:e.prev,next:e.next}))}function Tl(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 El(e){let{range:t,rowIds:n,columnKeys:r,text:i,writable:a}=e,o=[];for(let e of Ur(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 Dl(e){return e==null?`NULL`:typeof e==`number`&&Number.isFinite(e)?String(e):typeof e==`boolean`?e?`TRUE`:`FALSE`:`'${(typeof e==`string`?e:Ml(e)??`[unserializable]`).replaceAll(`'`,`''`)}'`}function Ol(e){return`${e.table} > row ${e.rowId} > ${e.key}`}function kl(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}" = ${Dl(e.next)}`).join(`, `);r.push(`${o}\nUPDATE "${e.table}" SET ${s} WHERE "${t}" = ${Dl(i)};`)}return r.join(`
25
-
26
- `)}function Al(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?jl(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 jl(e){try{return JSON.stringify(e,null,2)??`undefined`}catch{return`undefined`}}function Ml(e){try{return JSON.stringify(e)}catch{return null}}function Nl({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)(()=>wl(n),[n]),p=i===`kv`,m=(0,Z.useMemo)(()=>p?Al({updates:f}):kl({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,_=Qn(`S`);return(0,Q.jsx)(U,{open:e,onOpenChange:t,children:(0,Q.jsxs)(Ne,{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)(Ye,{children:`Pending Changes`}),(0,Q.jsx)(Ue,{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)(Pl,{active:u===`visual`,onClick:()=>d(`visual`),id:`visual`,children:`Visual`}),(0,Q.jsx)(Pl,{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=Ol({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)(F,{type:`button`,variant:`ghost`,size:`icon-xs`,disabled:a,"aria-label":`Undo ${t}`,onClick:()=>s(e.rowId,e.key),children:(0,Q.jsx)(q,{icon:Ve,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:Lr(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:Lr(e.next)})]})]})]},`${e.rowId}\0${e.key}`)})}):(0,Q.jsx)(bl,{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)(on,{children:o}):null,(0,Q.jsxs)(fe,{children:[(0,Q.jsx)(Zt,{split:!0,disabled:a||g===0,onClick:c,children:`Clear All`}),(0,Q.jsxs)(Zt,{variant:`default`,disabled:a||g===0,onClick:l,"data-slot":`commit-all`,children:[a?`Committing…`:`Commit All (${g})`,(0,Q.jsx)(Ke,{keys:_,className:`ml-1.5`})]})]})]})})}function Pl({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:a(`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 Fl={past:[],future:[]};function Il(e,t,n=100){let r=[...e.past,t];return{past:r.length>n?r.slice(r.length-n):r,future:[]}}function Ll(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 Rl(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 zl(e){return{at:e.at,updates:e.updates.map(e=>({...e,prev:e.next,next:e.prev}))}}var Bl={short:26,medium:34,tall:44,"extra-tall":56};function Vl(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 Hl(e){switch(e){case`integer`:case`number`:return`123`;case`json`:return`{ }`;case`boolean`:return`01`;default:return`abc`}}function Ul(e){return e===`integer`||e===`number`}function Wl(e,t){if(e.format===`ttl`){let e=Sr(t);return e===void 0?{ok:!1}:{ok:!0,next:e}}return{ok:!0,next:t.trim()===``?null:zr(e.type,t)}}function Gl(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 Kl({model:e,facet:t,storeRef:r,childName:a,tenant:o,masked:c=!1,routedRole:l,limit:u,toolbarExtras:d,indexSearch:f,insertOpen:p=!1,onInsertOpenChange:m,onDeleteRows:h}){let[g,_]=(0,Z.useState)(``),[v,y]=(0,Z.useState)([]),[b,x]=(0,Z.useState)(new Set),[S,C]=(0,Z.useState)(`medium`),[w,T]=(0,Z.useState)(null),[E,D]=(0,Z.useState)(null),[O,k]=(0,Z.useState)(null),[A,j]=(0,Z.useState)(Fl),[M,P]=(0,Z.useState)(new Map),[I,L]=(0,Z.useState)(null),[R,ee]=(0,Z.useState)(null),[z,B]=(0,Z.useState)(null),[te,H]=(0,Z.useState)(null),[ne,re]=(0,Z.useState)(!1),[ie,ae]=(0,Z.useState)(null),[oe,se]=(0,Z.useState)(!1),[ce,ue]=(0,Z.useState)(!1),[de,fe]=(0,Z.useState)(440),me=(0,Z.useRef)(null),he=(0,Z.useRef)(null),ge=(0,Z.useRef)(null),_e=(0,Z.useRef)(M),ye=(0,Z.useRef)([]);_e.current=M;let be=ma(),xe=h!==void 0,Se=e.editable&&(t===`sql`||t===`kv`),Ce=Bl[S],U=(0,Z.useMemo)(()=>e.columns.filter(e=>!b.has(e.key)),[e.columns,b]),Te=(e,n)=>{if(t===`kv`&&n===`size`){let t=M.get(xl(e.id,`value`))?.next??e.cells.value;return Yr(t)}return M.get(xl(e.id,n))?.next??e.cells[n]},Ee=f!==void 0,De=Ee?f.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(Er(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,M,Ee]),W=(0,Z.useMemo)(()=>{if(!w)return Oe;let t=U.find(e=>e.key===w.key)??e.columns.find(e=>e.key===w.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:Lr(r).localeCompare(Lr(i));return w.direction===`asc`?a:-a}),n},[Oe,w,M,U,e.columns]);(0,Z.useEffect)(()=>{y([]),x(new Set),D(null),j(Fl),P(new Map),ye.current=[],L(null),ee(null),B(null),H(null),re(!1),ae(null),se(!1),T(null),_(``)},[t,r,a,o]),(0,Z.useEffect)(()=>{if(!O)return;let e=setTimeout(()=>k(null),2e3);return()=>clearTimeout(e)},[O]),(0,Z.useEffect)(()=>{let e=me.current;if(!e)return;let t=new ResizeObserver(e=>{let t=e[0]?.contentRect.height;t&&fe(Math.max(120,Math.round(t)))});return t.observe(e),()=>t.disconnect()},[]);let G=(0,Z.useMemo)(()=>e.rows.filter(e=>v.includes(e.id)),[e.rows,v]),ke=(e,t)=>Se&&e.editable&&!(e.pii&&c&&Gr(t)),Ae=(e,t)=>{_e.current=e,ye.current=t,P(e)},je=(t,n)=>{let r=e.rows.find(e=>e.id===t),i=e.columns.find(e=>e.key===n);return!r||!i?!1:ke(i,r.cells[n])},Me=t=>{if(t.length===0)return 0;let n=_e.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=Wl(a,i.text);if(!s.ok)continue;let c=s.next,l=Sl(n,r,{rowId:t.id,key:a.key,prev:o,next:c});n=l.pending,r=l.log}return Ae(n,r),t.length},Ne=e=>{let t=v.length>0?W.filter(e=>v.includes(e.id)):W,n=U.map(e=>e.key);if(t.length===0||n.length===0)return;let r=v.length>0?`selection`:`page`,i=a.replace(/[^\w.-]+/g,`_`);if(e===`csv`){let e=t.map(e=>n.map(t=>ti(Te(e,t))));tu(`${i}-${r}.csv`,`\uFEFF${$r(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});tu(`${i}-${r}.json`,`${JSON.stringify(e,null,2)}\n`,`application/json`)}k(`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=Br(t);if(n.length===0){k(`No rows in import file`);return}let{hits:r,unmatched:i}=qr({records:n,rowIds:new Set(e.rows.map(e=>e.id)),writable:je});if(r.length===0){D(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);D(null),k(i>0?`Imported ${a} cell(s) · ${i} row(s) unmatched`:`Imported ${a} cell(s)`)}catch(e){D(e instanceof Error?e.message:`Could not parse import file`)}})},Fe=(e,t,n)=>{let r=e.cells[t.key];if(!ke(t,r))return;let i=Wl(t,n);if(!i.ok){D(`TTL must be a duration like 30m, 1h, or empty to clear`);return}D(null);let a=i.next,o=Sl(_e.current,ye.current,{rowId:e.id,key:t.key,prev:r,next:a});Ae(o.pending,o.log)},K=(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(!ke(a,o))return;let s=Sl(_e.current,ye.current,{rowId:i.id,key:a.key,prev:o,next:Ir(o,r)?o:r});Ae(s.pending,s.log)},Ie=(e,t)=>{let n=xl(e,t),r=new Map(_e.current);r.delete(n),Ae(r,ye.current.filter(e=>e!==n))},Le=async(e,n)=>{if(e.length===0)return!0;let i=new Map;for(let t of e){let e=i.get(t.rowId)??{};e[t.key]=t.next,i.set(t.rowId,e)}ue(!0),D(null);let s=!0;try{await Promise.all([...i.entries()].map(([e,n])=>be.mutateAsync({ref:r,...t===`sql`?{child:a,id:e}:{key:e},...o?{tenant:o}:{},patch:ai(n),commit:!0}))),n?.track!==!1&&j(t=>Il(t,{updates:e,at:Date.now()})),n?.notice&&k(n.notice)}catch(e){s=!1,D(e instanceof Error?e.message:String(e))}finally{ue(!1)}return s},Re=()=>{if(ce)return;if(_e.current.size>0){let e=Cl(_e.current,ye.current);Ae(e.pending,e.log);return}let{history:e,batch:t}=Ll(A);t&&(j(e),Le(zl(t).updates,{track:!1,notice:`Undid ${t.updates.length} cell(s)`}))},ze=()=>{if(ce||M.size>0)return;let{history:e,batch:t}=Rl(A);t&&(j(e),Le(t.updates,{track:!1,notice:`Redid ${t.updates.length} cell(s)`}))},Be=(t,n,r)=>{if(ce)return;let i=e.rows.find(e=>e.id===t),a=e.columns.find(e=>e.key===n);!i||!a||!ke(a,i.cells[n])||(L({rowId:t,key:n}),H(r===void 0?null:r),B({rowId:t,key:n}))},He=(t,n,r)=>{if(ce)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=Wl(a,r);if(!e.ok)return;Le([{rowId:t,key:n,prev:i.cells[n],next:e.next}],{notice:e.next===!0?`Enabled ${t}`:`Disabled ${t}`});return}if(R&&Hr(R)>1){Me(El({range:R,rowIds:W.map(e=>e.id),columnKeys:U.map(e=>e.key),text:r,writable:je}));return}Fe(i,a,r)}},Ue=()=>{_e.current.size!==0&&re(!0)},We=()=>{if(ce||_e.current.size===0)return;let e=wl(_e.current);Le(e,{notice:`Applied ${e.length} change(s)`}).then(e=>{e&&(Ae(new Map,[]),re(!1))})},Ge=()=>{ce||(Ae(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 W.filter(e=>v.includes(e.id));let e=I?.rowId??v[0]??W[0]?.id;if(!e)return[];let t=W.findIndex(t=>t.id===e);return t<0?[]:W.slice(t)},qe=e=>{if(!Se||ce||e.length===0)return;let t=U.map(e=>e.key),n=[];if(R){let r=Xr(R),i=[];for(let e=r.minRow;e<=r.maxRow;e++){let t=W[e];t&&i.push(t.id)}n=Tl({matrix:e,rowIds:i,columnKeys:t,startCol:r.minCol,writable:je})}else{let r=Ke();if(r.length===0)return;let i=I?.key,a=Math.max(0,i?U.findIndex(e=>e.key===i):0);n=Tl({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:je})}let r=Me(n);r>0&&k(`Pasted ${r} cell(s)`)},Je=async()=>{let t=[];if(R){let e=Xr(R);for(let n=e.minRow;n<=e.maxRow;n++){let r=W[n];if(!r)continue;let i=[];for(let t=e.minCol;t<=e.maxCol;t++){let e=U[t];i.push(e?Lr(Te(r,e.key)):``)}t.push(i)}}else{let n=v.length>0?W.filter(e=>v.includes(e.id)):[];if(n.length>0)for(let e of n)t.push(U.map(t=>Lr(Te(e,t.key))));else if(I){let n=e.rows.find(e=>e.id===I.rowId);n&&t.push([Lr(Te(n,I.key))])}}if(t.length!==0)try{await navigator.clipboard.writeText(ni(t)),k(`Copied ${t.length} row(s)`)}catch{D(`Clipboard write blocked — allow clipboard access in the browser prompt.`)}},Ye=e=>e instanceof Node&&(he.current===e||he.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)(()=>U.map(e=>({key:e.key,header:(0,Q.jsx)(ql,{col:e}),sortable:!0,align:Ul(e.type)?`right`:`left`,width:e.key===`comment`?void 0:`${Vl(e.type,e.key)}px`,fill:e.key===`comment`,sortValue:t=>{let n=Te(t,e.key);return typeof n==`number`?n:Lr(n)},cell:t=>{let n=M.get(xl(t.id,e.key)),i=n?n.next:t.cells[e.key];return(0,Q.jsx)(Xl,{row:t,col:e,storeRef:r,childName:a,tenant:o,masked:c,editable:Se&&e.editable&&!(e.pii&&c&&Gr(t.cells[e.key])),saving:ce,dirty:n!==void 0,editing:z?.rowId===t.id&&z.key===e.key,draftSeed:z?.rowId===t.id&&z.key===e.key?te:null,displayValue:i,onFocus:()=>L({rowId:t.id,key:e.key}),onStartEdit:()=>Be(t.id,e.key),onEditEnd:()=>{B(null),H(null)},onCommit:n=>He(t.id,e.key,n),onInspect:()=>ae({rowId:t.id,column:e.key}),onUpgrade:t.cells.upgrade===!0?()=>{Le([{rowId:t.id,key:`upgrade`,prev:t.cells.upgrade,next:!0}],{notice:`Upgraded ${t.id}`,track:!1})}:void 0})}})),[U,r,a,o,c,ce,Se,M,z,te,Le]),$e=e=>{let t=e.ctrlKey||e.metaKey;if(t&&e.key.toLowerCase()===`f`){e.preventDefault(),he.current?.focus();return}if(!(Ye(e.target)||Xe(e.target))){if(t&&e.key.toLowerCase()===`enter`){_e.current.size>0&&(e.preventDefault(),ne?We():Ue());return}if(t&&e.key.toLowerCase()===`s`){_e.current.size>0&&(e.preventDefault(),ne?We():Ue());return}if(t&&e.key.toLowerCase()===`z`){e.preventDefault(),e.shiftKey?ze():Re();return}if(t&&e.key.toLowerCase()===`y`){e.preventDefault(),ze();return}if(e.key===`Escape`){if(Ye(e.target)||!z&&!R)return;e.preventDefault(),B(null),H(null),ee(null),e.currentTarget.focus({preventScroll:!0});return}if(!z){if(e.key===`Enter`&&R){e.preventDefault();let t=W[R.head.row],n=U[R.head.col];t&&n&&Be(t.id,n.key);return}if(R&&Se&&e.key.length===1&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let t=W[R.head.row],n=U[R.head.col];t&&n&&(e.preventDefault(),Be(t.id,n.key,e.key));return}if((e.key===`Delete`||e.key===`Backspace`)&&R&&Se){e.preventDefault();let t=Me(El({range:R,rowIds:W.map(e=>e.id),columnKeys:U.map(e=>e.key),text:``,writable:je}));t>0&&k(`Cleared ${t} cell(s)`)}}}},et=e=>{Ye(e.target)||Ze(e.target)||v.length===0&&!I&&!R||(e.preventDefault(),Je())},tt=e=>{if(!Se||Ye(e.target))return;let t=e.clipboardData.getData(`text/plain`),n=Wr(t);!(v.length>1||n.length>1||(n[0]?.length??0)>1)&&e.target instanceof HTMLInputElement||n.length!==0&&(e.preventDefault(),qe(n))},nt=ie?e.rows.find(e=>e.id===ie.rowId):void 0,rt=ie?e.columns.find(e=>e.key===ie.column):void 0,at=nt&&rt?Te(nt,rt.key):void 0,ot=nt!==void 0&&rt!==void 0&&!ce&&ke(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:[d,d?(0,Q.jsx)(Oi,{orientation:`vertical`,className:`mx-0.5 my-2 h-4 self-center`}):null,(0,Q.jsxs)(X,{label:Ee?`Search this index`:`Find in this page`,keys:Qn(`F`),className:`relative min-w-40 flex-1`,children:[(0,Q.jsx)(q,{icon:V,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)(s,{ref:he,value:De,onChange:e=>Ee?f.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)(s,{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:f.topK,onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&t>=1&&t<=100&&f.onTopKChange(t)}})]}):null,w?(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:[w.key,` `,w.direction===`desc`?`↓`:`↑`]}):null,(0,Q.jsx)(Oi,{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)(nu,{label:`Add key`,disabled:ce,onClick:()=>se(!0),slot:`add-kv-key`,children:(0,Q.jsx)(q,{icon:N,className:`size-3.5`,"aria-hidden":!0})}):null,Se?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`input`,{ref:ge,type:`file`,accept:`.csv,.tsv,.txt,.json,text/csv,application/json`,className:`sr-only`,tabIndex:-1,"aria-hidden":!0,onChange:Pe}),(0,Q.jsx)(nu,{label:`Import CSV or JSON`,disabled:ce,onClick:()=>ge.current?.click(),slot:`import-rows`,children:(0,Q.jsx)(q,{icon:le,className:`size-3.5`,"aria-hidden":!0})})]}):null,(0,Q.jsxs)(sn,{children:[(0,Q.jsx)(X,{label:v.length>0?`Export ${v.length} selected row${v.length===1?``:`s`}`:`Export this page as CSV or JSON`,children:(0,Q.jsx)(Gt,{disabled:W.length===0,render:e=>(0,Q.jsx)(F,{...e,type:`button`,variant:`ghost`,size:`icon-xs`,disabled:W.length===0,"aria-label":`Export rows`,"data-slot":`export-rows`,children:(0,Q.jsx)(q,{icon:we,className:`size-3.5`,"aria-hidden":!0})})})}),(0,Q.jsx)(tn,{align:`end`,className:`w-40`,children:(0,Q.jsxs)(en,{children:[(0,Q.jsx)(un,{children:v.length>0?`Export selection`:`Export page`}),(0,Q.jsx)(Jt,{onClick:()=>Ne(`csv`),children:`CSV`}),(0,Q.jsx)(Jt,{onClick:()=>Ne(`json`),children:`JSON`})]})})]}),Se?(0,Q.jsxs)(Q.Fragment,{children:[M.size>0?(0,Q.jsx)(nu,{label:`Discard uncommitted changes`,disabled:ce,onClick:Ge,slot:`discard-changes`,children:(0,Q.jsx)(q,{icon:it,className:`size-3.5`,"aria-hidden":!0})}):null,(0,Q.jsx)(X,{label:M.size>0?`Review ${M.size} uncommitted change${M.size===1?``:`s`}`:`No uncommitted changes`,children:(0,Q.jsxs)(F,{type:`button`,variant:M.size>0?`outline`:`ghost`,size:`xs`,disabled:M.size===0||ce,onClick:Ue,"aria-label":M.size>0?`Review ${M.size} uncommitted changes`:`Review changes`,"data-slot":`apply-changes`,className:M.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:[M.size>0?(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`oke-changes-border-run pointer-events-none absolute inset-0`}):null,(0,Q.jsx)(q,{icon:ve,className:`relative size-3.5`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`relative`,children:`Changes`}),M.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:M.size}):null]})})]}):null,(0,Q.jsx)(nu,{label:`Undo edit`,keys:Qn(`Z`),disabled:M.size===0&&A.past.length===0||ce,onClick:Re,slot:`undo-edit`,children:(0,Q.jsx)(q,{icon:Ve,className:`size-3.5`,"aria-hidden":!0})}),(0,Q.jsx)(nu,{label:`Redo edit`,keys:Zn(`Z`),disabled:A.future.length===0||ce||M.size>0,onClick:ze,slot:`redo-edit`,children:(0,Q.jsx)(q,{icon:i,className:`size-3.5`,"aria-hidden":!0})}),(0,Q.jsxs)(sn,{children:[(0,Q.jsx)(X,{label:`Row height and columns`,children:(0,Q.jsx)(Gt,{render:e=>(0,Q.jsx)(F,{...e,type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`View options`,"data-slot":`view-menu`,children:(0,Q.jsx)(q,{icon:pe,className:`size-3.5`,"aria-hidden":!0})})})}),(0,Q.jsxs)(tn,{align:`end`,className:`w-48`,children:[(0,Q.jsxs)(en,{children:[(0,Q.jsx)(un,{children:`Row height`}),(0,Q.jsxs)(fn,{value:S,onValueChange:e=>C(e),children:[(0,Q.jsx)(Xt,{value:`short`,"data-slot":`row-height-menu`,children:`Short`}),(0,Q.jsx)(Xt,{value:`medium`,children:`Medium`}),(0,Q.jsx)(Xt,{value:`tall`,children:`Tall`}),(0,Q.jsx)(Xt,{value:`extra-tall`,children:`Extra tall`})]})]}),(0,Q.jsx)(dn,{}),(0,Q.jsxs)(en,{children:[(0,Q.jsx)(un,{children:`Columns`}),e.columns.map(e=>{let t=!b.has(e.key),n=t&&U.length===1;return(0,Q.jsx)(rn,{checked:t,disabled:n,onCheckedChange:t=>{x(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&&h?(0,Q.jsx)(X,{label:G.length>0?`Delete ${G.length} selected row${G.length===1?``:`s`}`:`Select rows to delete`,children:(0,Q.jsxs)(F,{type:`button`,variant:`destructive`,size:G.length>0?`xs`:`icon-xs`,className:G.length>0?`ml-1 h-6`:`ml-1`,disabled:G.length===0,onClick:()=>h(G),"aria-label":G.length>0?`Delete ${G.length} selected rows`:`Delete selected rows`,"data-slot":`delete-selected`,children:[(0,Q.jsx)(q,{icon:n,className:`size-3.5`,"aria-hidden":!0}),G.length>0?G.length:null]})}):null]})]}),(0,Q.jsx)(`div`,{ref:me,className:`min-h-0 flex-1`,"data-slot":`grid-viewport`,"aria-label":`${a} rows`,children:(0,Q.jsx)(fl,{data:W,columns:Qe,getRowId:e=>e.id,selectable:xe,selectedRowIds:v,onSelectionChange:y,sort:w,onSortChange:T,resizable:!0,reorderable:!0,onCellEdit:Se?He:void 0,onDeleteRow:e.editable&&h?t=>{let n=e.rows.find(e=>e.id===t);n&&h([n])}:void 0,cellRange:R,onCellRangeChange:Se?e=>{if(ee(e),!e)return;let t=W[e.head.row],n=U[e.head.col];t&&n&&L({rowId:t.id,key:n.key});let r=me.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=W[e],r=U[t];n&&r&&Be(n.id,r.key)}:void 0,rowHeight:Ce,height:de,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)(Nl,{open:ne,onOpenChange:re,pending:M,table:a,facet:t===`kv`?`kv`:`sql`,saving:ce,error:E,onUndoCell:Ie,onClearAll:Ge,onCommitAll:We}):null,Se&&t===`sql`&&m?(0,Q.jsx)(_l,{open:p,onOpenChange:m,storeRef:r,childName:a,tenant:o,columns:e.columns}):null,Se&&t===`kv`?(0,Q.jsx)(gl,{open:oe,onOpenChange:se,storeRef:r,childName:a,tenant:o,existingKeys:e.rows.map(e=>e.id)}):null,ie&&nt&&rt?(0,Q.jsx)(ci,{open:!0,onOpenChange:e=>{e||ae(null)},rowId:ie.rowId,column:ie.column,storeRef:r,value:at,originalValue:nt.cells[rt.key],editable:ot,onChange:ot?e=>K(ie.rowId,ie.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`]}),l?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`text-border`,children:`·`}),(0,Q.jsx)(`span`,{children:l})]}):null,t===`sql`&&c?(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,M.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:[M.size,` uncommitted`]})]}):null,ce?(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,O?(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:O})]}):null,E?(0,Q.jsx)(`span`,{className:`text-destructive`,role:`alert`,"data-slot":`cell-edit-error`,children:E}):null,Ee&&De.trim()?(0,Q.jsxs)(`span`,{className:`ml-auto truncate`,role:`status`,"data-slot":`find-scope`,children:[`Index query · topK `,f.topK]}):g.trim()?(0,Q.jsxs)(`span`,{className:`ml-auto truncate`,role:`status`,"data-slot":`find-scope`,children:[`This page only · limit `,u]}):G.length>0?(0,Q.jsxs)(`span`,{className:`ml-auto`,children:[G.length,` row`,G.length===1?``:`s`,` checked`]}):(0,Q.jsx)(`span`,{className:`ml-auto opacity-60`,children:`Click to select · drag a range · click again or type to edit · Changes to review`})]})]})}function ql({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:Hl(e.type)}),e.primaryKey?(0,Q.jsx)(q,{icon:tt,className:`size-3 shrink-0 text-amber-600 dark:text-amber-400`,"aria-label":`Primary key`}):null,e.pii?(0,Q.jsx)(q,{icon:m,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 Jl=`text-[#9a5b12] dark:text-[#e8c48a]`,Yl=`absolute inset-0 flex min-w-0 items-center overflow-hidden px-4 font-mono text-[11px]`;function Xl({row:e,col:t,storeRef:n,childName:r,tenant:i,masked:o,editable:s,saving:c,dirty:l,editing:u,draftSeed:d,displayValue:f,onFocus:p,onStartEdit:m,onEditEnd:h,onCommit:g,onInspect:_,onUpgrade:v}){let y=f,b=Ul(t.type),x=y==null;if(t.pii&&o&&Gr(e.cells[t.key])&&!l)return(0,Q.jsx)(`span`,{className:Yl,children:(0,Q.jsx)(ml,{refName:n,child:r,...i?{tenant:i}:{},rowId:e.id,column:t.key,maskedValue:e.cells[t.key]})});if(t.type===`boolean`){let t=f===!0;return(0,Q.jsx)(`span`,{className:a(Yl,`justify-center`,l&&Jl),"data-slot":s?`cell-display`:void 0,"data-pending":l?`true`:void 0,onClick:e=>e.stopPropagation(),children:(0,Q.jsx)(_a,{size:`sm`,checked:t,disabled:!s||c,ariaLabel:t?`Disable ${e.id}`:`Enable ${e.id}`,onCheckedChange:e=>{s&&!c&&g(e?`true`:`false`)}})})}if(s&&u)return(0,Q.jsx)(`span`,{className:a(Yl,l&&Jl,b&&`tabular-nums`),"data-slot":`cell-editor`,"data-pending":l?`true`:void 0,children:(0,Q.jsx)(Jr,{value:d??Gl(t,y),label:`Edit ${t.key}`,dirty:l,autoFocus:!0,placeholder:t.format===`ttl`?`30m`:void 0,onFocus:p,onIdle:h,onChange:e=>{c||g(e)},className:a(`h-full min-w-0 font-mono text-[11px]`,b&&`text-right tabular-nums`,Vr(y)&&`text-right`)})});let S=si(y)!==null,C=Er(t,y);return(0,Q.jsxs)(`span`,{role:s?`button`:void 0,tabIndex:s?-1:void 0,"data-slot":s?`cell-display`:void 0,"data-pending":l?`true`:void 0,className:a(Yl,`group/cell gap-1`,s&&`cursor-cell`,l&&Jl,b&&`tabular-nums`,x&&!l&&`text-muted-foreground/40`,t.type===`json`&&!x&&!l&&`text-muted-foreground`),title:t.format===`name-key`&&typeof e.cells.url==`string`?e.cells.url:C,onDoubleClick:s?e=>{e.stopPropagation(),c||m()}:void 0,children:[t.format===`source`?(0,Q.jsx)($l,{value:C}):t.format===`name-key`?(0,Q.jsx)(Zl,{title:C,url:typeof e.cells.url==`string`?e.cells.url:null}):(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,dir:Vr(y)?`rtl`:`ltr`,children:C}),t.format===`name-key`?(0,Q.jsx)(Ql,{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:c,onUpgrade:v}):null,S?(0,Q.jsx)(eu,{onInspect:_}):null]})}function Zl({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)(q,{icon:Qe,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 Ql({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 $l({value:e}){let t=e===`library`;return(0,Q.jsxs)(ar,{variant:`outline`,className:a(`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)(q,{icon:t?rt:ae,className:`size-3`,"aria-hidden":!0}),t?`Library`:`Builtin`]})}function eu({onInspect:e}){return(0,Q.jsxs)(T,{children:[(0,Q.jsx)(b,{render:t=>(0,Q.jsx)(`button`,{...t,type:`button`,"aria-label":`Open as table`,"data-slot":`json-inspect`,className:a(`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)(q,{icon:I,className:`size-3`,"aria-hidden":!0})})}),(0,Q.jsx)(u,{side:`left`,className:`text-[11px]`,children:`Open as table`})]})}function tu(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 nu({label:e,keys:t,disabled:n,onClick:r,slot:i,children:a}){return(0,Q.jsxs)(T,{children:[(0,Q.jsx)(b,{render:t=>(0,Q.jsx)(F,{...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)(u,{side:`bottom`,className:`text-[11px]`,children:[e,t&&t.length>0?(0,Q.jsx)(Ke,{keys:t}):null]})]})}var ru=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/;function iu(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=>ru.test(e))}function ou(e){let t=e.trim();if(t.length===0)return{kind:`empty`};if(au(t)){let e=iu(t);if(e&&e.length>=2)return{kind:`vector`,vector:e}}return{kind:`text`,q:t}}function su(e){return[...new Set(e)].sort((e,t)=>e.localeCompare(t))}function cu({child:e}){let t=su(e.writers),n=su(e.readers);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,"data-slot":`touched-by-lists`,children:[(0,Q.jsx)(lu,{title:`Writers`,ids:t,empty:`No Manifest flow declares writes for this resource.`}),(0,Q.jsx)(lu,{title:`Readers`,ids:n,empty:`No Manifest flow declares reads for this resource.`})]})}function lu({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)(at,{to:`/flows`,search:{flow:e},className:`text-[10px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline`,children:`Flows`}),(0,Q.jsx)(at,{to:`/overview`,search:{flow:e},className:`text-[10px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline`,children:`Graph`})]},e))})]})}var uu=[10,25,50,100,250,500],du=280;function fu(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 pu({store:e,child:t,manifest:n,tenancyDeclared:r,tenants:i,tenant:a,onTenantChange:o,piiMasked:s=!0}){let[c,l]=(0,Z.useState)(500),[d,p]=(0,Z.useState)(``),[g,_]=(0,Z.useState)(5),[v,y]=(0,Z.useState)(null),[x,S]=(0,Z.useState)(!1),[C,w]=(0,Z.useState)(!1),[E,D]=(0,Z.useState)(!1),[O,k]=(0,Z.useState)(!1),[A,j]=(0,Z.useState)(!1),[M,P]=(0,Z.useState)(!1),I=fu(d,du),L=(0,Z.useMemo)(()=>ou(I),[I]),R=!r||a!==null&&a.length>0,ee=(0,Z.useMemo)(()=>R?{ref:e.ref,child:t.name,...a?{tenant:a}:{},limit:c,...e.facet===`index`&&L.kind===`vector`?{vector:L.vector,topK:g}:{},...e.facet===`index`&&L.kind===`text`?{q:L.q,topK:g}:{},...e.facet===`sql`&&!s?{revealPii:!0}:{}}:null,[e.ref,e.facet,t.name,a,R,c,L,g,s]),z=mn(ee,R),B=ha(),V=Mi(t),te=V===`extension`,H=V===`policy`,ne=V===`function`,re=V===`index`,ie=V===`trigger`,ae=Ni(t)&&!te,oe=e.ref===`sql:oke_console`||ae,{columnTypes:se,primaryKeyColumns:le}=(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]),ue=(0,Z.useMemo)(()=>{if(!z.data)return null;let n=oi({facet:e.facet,data:z.data,piiColumns:t.piiColumns,columnTypes:se,columnDescriptions:t.columnDescriptions,primaryKeyColumns:le});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`}))}:H?{...n,editable:!1,columns:n.columns.filter(e=>e.key!==`id`&&e.key!==`schema`).map(e=>({...e,editable:!1}))}:te&&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`}:{}}))}:oe?{...n,editable:!1,columns:n.columns.map(e=>({...e,editable:!1}))}:n},[z.data,e.facet,e.ref,t,se,le,oe,te,H]),de=n=>{if(!v)return;let r=v.map(e=>e.id);B.mutate({ref:e.ref,...e.facet===`sql`?{child:t.name}:{},...a?{tenant:a}:{},...ue?.deleteKind===`keys`?{keys:r}:{ids:r},confirmation:n.confirmation,reason:n.reason},{onSuccess:()=>{y(null)}})},fe=new Set(t.writers).size,me=new Set(t.readers).size,ge=R&&ue!==null,_e=(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(T,{children:[(0,Q.jsx)(b,{render:e=>(0,Q.jsx)(F,{...e,type:`button`,variant:`ghost`,size:`icon-xs`,onClick:()=>void z.refetch(),disabled:z.isFetching,"aria-label":`Refresh`,"data-slot":`browse-refresh`,children:(0,Q.jsx)(q,{icon:f,className:z.isFetching?`size-3.5 animate-spin`:`size-3.5`,"aria-hidden":!0})})}),(0,Q.jsx)(u,{side:`bottom`,className:`text-[11px]`,children:`Reload from the store`})]}),e.facet===`sql`&&!oe&&!Ni(t)?(0,Q.jsx)(X,{label:`Insert a row`,children:(0,Q.jsxs)(F,{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:()=>P(!0),children:[(0,Q.jsx)(q,{icon:N,className:`size-3.5`,"aria-hidden":!0}),`Insert data`]})}):null,re&&e.ref!==`sql:oke_console`?(0,Q.jsx)(X,{label:`CREATE INDEX`,children:(0,Q.jsxs)(F,{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:()=>k(!0),children:[(0,Q.jsx)(q,{icon:tt,className:`size-3.5`,"aria-hidden":!0}),`Create index`]})}):null,ne&&e.ref!==`sql:oke_console`?(0,Q.jsx)(X,{label:`CREATE FUNCTION`,children:(0,Q.jsxs)(F,{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:()=>D(!0),children:[(0,Q.jsx)(q,{icon:Se,className:`size-3.5`,"aria-hidden":!0}),`New function`]})}):null,ie&&e.ref!==`sql:oke_console`?(0,Q.jsx)(X,{label:`CREATE TRIGGER`,children:(0,Q.jsxs)(F,{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:()=>j(!0),children:[(0,Q.jsx)(q,{icon:he,className:`size-3.5`,"aria-hidden":!0}),`New trigger`]})}):null,H&&e.ref!==`sql:oke_console`?(0,Q.jsx)(X,{label:`CREATE POLICY on a table`,children:(0,Q.jsxs)(F,{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:()=>w(!0),children:[(0,Q.jsx)(q,{icon:m,className:`size-3.5`,"aria-hidden":!0}),`Create policy`]})}):null,te&&e.ref!==`sql:oke_console`?(0,Q.jsx)(X,{label:`Add Timescale, PostGIS, pg_cron…`,children:(0,Q.jsxs)(F,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px] text-muted-foreground`,"data-slot":`extension-library`,onClick:()=>S(!0),children:[(0,Q.jsx)(q,{icon:rt,className:`size-3.5`,"aria-hidden":!0}),`Library`]})}):null,(0,Q.jsxs)(sn,{children:[(0,Q.jsx)(X,{label:`${fe} writer${fe===1?``:`s`} · ${me} reader${me===1?``:`s`}`,children:(0,Q.jsx)(Gt,{render:e=>(0,Q.jsxs)(F,{...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":`${fe} writers, ${me} readers`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(q,{icon:h,className:`size-3`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:fe})]}),(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)(q,{icon:pe,className:`size-3`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:me})]})]})})}),(0,Q.jsx)(tn,{align:`start`,className:`w-72 p-3`,children:(0,Q.jsx)(cu,{child:t})})]}),r?(0,Q.jsx)(X,{label:`Tenant for this browse`,children:(0,Q.jsxs)(`div`,{className:`relative flex items-center`,children:[(0,Q.jsx)(q,{icon:Pe,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)(q,{icon:ce,className:`pointer-events-none absolute right-1.5 size-3.5 text-muted-foreground`,"aria-hidden":!0})]})}):null,(0,Q.jsx)(X,{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)(ca,{value:String(c),onValueChange:e=>{let t=Number(e);Number.isFinite(t)&&l(t)},className:`z-30 w-14`,children:[(0,Q.jsx)(la,{"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)(ua,{})}),(0,Q.jsx)(da,{className:`min-w-16`,children:uu.map(e=>(0,Q.jsx)(fa,{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`&&z.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`&&z.data&&!z.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,R?z.isLoading&&!z.data?(0,Q.jsx)(hu,{}):z.isError?(0,Q.jsx)(mu,{children:(0,Q.jsx)($n,{role:`alert`,"data-slot":`browse-error`,children:(0,Q.jsxs)(fr,{children:[(0,Q.jsx)(er,{variant:`icon`,className:`bg-destructive/10 text-destructive`,children:(0,Q.jsx)(q,{icon:De,"aria-hidden":!0})}),(0,Q.jsx)(or,{children:`Couldn’t load rows`}),(0,Q.jsx)(lr,{children:z.error.message})]})})}):e.facet===`files`&&z.data?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,Q.jsx)(pc,{store:e,child:t,tenant:a,data:z.data,fetching:z.isFetching,onRefresh:()=>void z.refetch()})}):ue?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,Q.jsx)(Kl,{model:ue,facet:e.facet,storeRef:e.ref,childName:t.name,tenant:a,masked:z.data?.masked??!1,routedRole:z.data?.routedRole,limit:c,toolbarExtras:ge?_e:void 0,indexSearch:e.facet===`index`?{value:d,onChange:p,topK:g,onTopKChange:_}:void 0,insertOpen:M,onInsertOpenChange:P,onDeleteRows:oe||te?void 0:e=>y(e)})}):null:(0,Q.jsx)(mu,{children:(0,Q.jsx)($n,{role:`status`,"data-slot":`browse-gate`,children:(0,Q.jsxs)(fr,{children:[(0,Q.jsx)(er,{variant:`icon`,children:(0,Q.jsx)(q,{icon:Pe,"aria-hidden":!0})}),(0,Q.jsx)(or,{children:`Select a tenant`}),(0,Q.jsx)(lr,{children:`Tenancy is a compliance boundary, not a display filter — choose a tenant to browse its data.`})]})})}),te&&e.ref!==`sql:oke_console`?(0,Q.jsx)(Ja,{open:x,onOpenChange:S,storeRef:e.ref,presentNames:(ue?.rows??[]).map(e=>e.id)}):null,re&&e.ref!==`sql:oke_console`?(0,Q.jsx)(es,{open:O,onOpenChange:k,storeRef:e.ref,tables:Ii(e.children).tables.map(e=>e.name)}):null,ne&&e.ref!==`sql:oke_console`?(0,Q.jsx)(Ko,{open:E,onOpenChange:D,storeRef:e.ref}):null,ie&&e.ref!==`sql:oke_console`?(0,Q.jsx)(ps,{open:A,onOpenChange:j,storeRef:e.ref,tables:Ii(e.children).tables.map(e=>e.name)}):null,H&&e.ref!==`sql:oke_console`?(0,Q.jsx)(go,{open:C,onOpenChange:w,storeRef:e.ref,tables:Ii(e.children).tables.map(e=>e.name),manifest:n}):null,(0,Q.jsx)(ms,{open:v!==null,onOpenChange:e=>{e||y(null)},phrase:`DELETE`,title:`Delete ${v?.length??0} ${v?.length===1?`row`:`rows`}`,description:`Permanently delete ${v?.length??0} item(s) from ${e.ref}${e.facet===`sql`?`/${t.name}`:``}. This is not a flow execution.`,pending:B.isPending,error:B.isError?B.error.message:null,onConfirm:de})]})}function mu({children:e}){return(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center px-6`,children:e})}function hu(){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)(At,{className:`h-5 w-8`}),(0,Q.jsx)(At,{className:`h-5 w-16`}),(0,Q.jsx)(At,{className:`h-5 w-14`}),(0,Q.jsx)(At,{className:`ml-auto h-5 w-48`}),(0,Q.jsx)(At,{className:`h-5 w-6`}),(0,Q.jsx)(At,{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)(At,{className:`size-3.5`}),(0,Q.jsx)(At,{className:`h-3 w-20`}),(0,Q.jsx)(At,{className:`h-3 w-24`}),(0,Q.jsx)(At,{className:`h-3 w-12`}),(0,Q.jsx)(At,{className:`h-3 w-28`}),(0,Q.jsx)(At,{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)(At,{className:`size-3.5`}),(0,Q.jsx)(At,{className:`h-3 w-16`}),(0,Q.jsx)(At,{className:`h-3 w-20`}),(0,Q.jsx)(At,{className:`h-3 w-8`}),(0,Q.jsx)(At,{className:`h-3 w-24`}),(0,Q.jsx)(At,{className:`h-3 flex-1`})]},t))})]})}function gu({store:e,child:t,manifest:n,tenancyDeclared:r,tenants:i,tenant:a,onTenantChange:o,runs:s=[],leading:c}){let l=e.migrationDrift,u=Bi[e.facet],d=Ni(t)?0:di(t.piiColumns),[f,p]=(0,Z.useState)(!0);(0,Z.useEffect)(()=>{p(!0)},[t.effectRef]);let h=(0,Z.useMemo)(()=>new Set(e.children.map(e=>e.effectRef)),[e.children]),g=ri(s,h)??e.replicaLagMs,_=g==null?null:Vt(g),v=e.facet===`files`,y=!!(l||g!==null||e.contentAddressed||d>0);return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`resource-panel`,children:[(0,Q.jsx)(Wt,{dataSlot:`resource-header`,leading:c,icon:(0,Q.jsx)(q,{icon:v?Le:u.icon,className:`size-4`}),wellClassName:u.wellClass,title:Fi(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:v?`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:v?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[11px] leading-none text-muted-foreground`,children:Ai(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:ji(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)(gi,{value:t.effectRef,label:`Copy effect ref`})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[11px] leading-none text-muted-foreground`,children:e.ref}),(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)(gi,{value:t.effectRef,label:`Copy effect ref`})]})}),actions:y?(0,Q.jsxs)(`div`,{className:`flex h-full shrink-0 items-stretch`,"data-slot":`resource-status`,children:[g!==null&&_?(0,Q.jsxs)(vu,{chipClassName:Ht(_),icon:(0,Q.jsx)(q,{icon:qe,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:_r(g)}),(0,Q.jsx)(`span`,{className:`opacity-70`,children:`lag`})]}):null,e.contentAddressed?(0,Q.jsx)(vu,{children:`content-addressed`}):null,d>0?(0,Q.jsxs)(vu,{tone:f?`sky`:`amber`,icon:(0,Q.jsx)(q,{icon:m,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)(vu,{tone:l.drifted?`amber`:`emerald`,icon:(0,Q.jsx)(q,{icon:l.drifted?De:te,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:yu(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)(q,{icon:De,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)(pu,{store:e,child:t,manifest:n,tenancyDeclared:r,tenants:i,tenant:a,onTenantChange:o,piiMasked:f})]})}var _u={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 vu({tone:e=`neutral`,icon:t,title:n,children:r,role:i,"data-slot":o,"data-drifted":s,pressed:c,onClick:l,ariaLabel:d,chipClassName:f}){let p=a(se,`whitespace-nowrap`,f??_u[e],l&&`cursor-pointer outline-none focus-visible:ring-2 focus-visible:ring-ring/40`),m=l?(0,Q.jsxs)(`button`,{type:`button`,className:p,"aria-pressed":c,"aria-label":d,"data-slot":o,"data-drifted":s,onClick:l,children:[t,r]}):(0,Q.jsxs)(`span`,{className:p,role:i,"data-slot":o,"data-drifted":s,children:[t,r]});return n?(0,Q.jsxs)(T,{children:[(0,Q.jsx)(b,{render:e=>(0,Q.jsx)(`span`,{...e,className:`flex self-stretch`,children:m})}),(0,Q.jsx)(u,{side:`bottom`,className:`max-w-xs text-[11px]`,children:n})]}):m}function yu(e){return e.length>12?`${e.slice(0,12)}…`:e}function bu({stores:e,selectedEffectRef:t,onSelect:n,queryFacet:r=null,onOpenQuery:i,schemaActive:o=!1,onOpenSchema:s,performanceActive:c=!1,performanceFacet:l=null,onOpenPerformance:u}){let[d,f]=(0,Z.useState)(``),[p,m]=(0,Z.useState)({}),[h,g]=(0,Z.useState)($i),_=(0,Z.useMemo)(()=>Vi(e),[e]),v=(0,Z.useMemo)(()=>Vi(Hi(e,d)),[e,d]),y=(0,Z.useMemo)(()=>ta(v,h),[v,h]),b=(0,Z.useMemo)(()=>Ji(y),[y]),x=d.trim().length>0,S=b.length>0&&b.every(e=>qi(e,p)),C=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{if(!t)return;let n=Yi(e,t).find(e=>e.startsWith(`facet:`));n&&m(e=>e[n]===!1?{...e,[n]:!0}:e);let r=C.current!==null&&C.current!==t;if(C.current=t,!r)return;let i=Ui(e,t);i&&g(e=>{if(!e.has(i.store.facet))return e;let t=new Set(e);return t.delete(i.store.facet),ea(t),t})},[t,e]);let w=(e,t)=>{m(n=>n[e]===t?n:{...n,[e]:t})},T=(e,t)=>{g(n=>{if(n.has(e)===t)return n;let r=new Set(n);return t?r.add(e):r.delete(e),ea(r),r})};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:a(de,`border-b-0`),children:[(0,Q.jsx)(mr,{value:d,onChange:e=>f(e.target.value),placeholder:`Search stores…`,"aria-label":`Search stores`,"data-slot":`store-search`}),(0,Q.jsx)(xu,{bands:_,hiddenFacets:h,onHiddenChange:T,onShowAll:()=>{g(e=>{if(e.size===0)return e;let t=new Set;return ea(t),t})}}),(0,Q.jsx)(Hn,{allOpen:S,disabled:b.length===0,onToggle:()=>{let e=!S;m(t=>{let n={...t};for(let t of b)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:y.length===0?(0,Q.jsx)(`p`,{className:Ge,children:v.length===0?`No stores match.`:`All facets hidden.`}):(0,Q.jsx)(`div`,{className:`flex flex-col`,children:y.map(e=>{let a=Gi(e.facet);return(0,Q.jsx)(Su,{band:e,onHide:()=>T(e.facet,!0),open:qi(a,p),onOpenChange:e=>w(a,e),storeOpen:e=>x?p[e]!==!1:p[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`&&o,onOpenSchema:e.facet===`sql`?s:void 0,performanceActive:(e.facet===`sql`||e.facet===`kv`)&&c&&(l??`sql`)===(e.facet===`kv`?`kv`:`sql`),onOpenPerformance:u&&(e.facet===`sql`||e.facet===`kv`)?()=>u(e.facet===`kv`?`kv`:`sql`):void 0},e.facet)})})})]})}function xu({bands:e,hiddenFacets:t,onHiddenChange:n,onShowAll:r}){let i=e.filter(e=>t.has(e.facet)).length>0;return(0,Q.jsxs)(sn,{children:[(0,Q.jsx)(X,{label:`Show and hide facets`,className:`flex self-stretch`,children:(0,Q.jsx)(Gt,{render:t=>(0,Q.jsx)(`button`,{...t,type:`button`,"aria-label":`Show and hide facets`,"data-slot":`store-tree-visibility`,disabled:e.length===0,className:a(ue,i&&`text-foreground`),children:(0,Q.jsx)(q,{icon:i?W:pe,className:`size-3.5`,"aria-hidden":!0})})})}),(0,Q.jsxs)(tn,{align:`end`,className:`w-44`,children:[(0,Q.jsxs)(en,{children:[(0,Q.jsx)(un,{children:`Facets`}),e.map(e=>{let r=Bi[e.facet],i=!t.has(e.facet);return(0,Q.jsxs)(rn,{checked:i,"data-slot":`store-tree-visibility-facet`,"data-facet":e.facet,onCheckedChange:t=>n(e.facet,t===!1),children:[(0,Q.jsx)(q,{icon:r.icon,className:`size-3.5`,"aria-hidden":!0}),r.label]},e.facet)})]}),i?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(dn,{}),(0,Q.jsx)(Jt,{"data-slot":`store-tree-visibility-show-all`,onClick:r,children:`Show all`})]}):null]})]})}function Su({band:e,onHide:n,open:r,onOpenChange:i,storeOpen:o,onStoreOpenChange:s,selectedEffectRef:c,onSelect:l,queryActive:u,onOpenQuery:d,schemaActive:f,onOpenSchema:p,performanceActive:m,onOpenPerformance:h}){let g=Bi[e.facet],_=e.stores.reduce((e,t)=>t.store.facet===`sql`?e+Ii(t.children).tables.length:e+t.children.length,0),v=e.stores.filter(e=>!Wi(e.store)).map(e=>e.store.ref),y=v.length>0&&v.every(e=>o(e)),b=()=>{let e=!y;for(let t of v)s(t,e);e&&i(!0)},x=(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(q,{icon:g.icon,className:a(K,L(g.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:ye,children:e.label}),(0,Q.jsx)(`span`,{className:Me,children:_})]})]});return(0,Q.jsx)(`section`,{"data-slot":`store-facet-band`,"data-facet":e.facet,"aria-label":e.label,className:A,children:(0,Q.jsxs)(pr,{open:r,onOpenChange:i,children:[(0,Q.jsx)(dr,{nativeButton:!1,className:t,"data-slot":`store-facet-band-toggle`,render:t=>(0,Q.jsxs)(`div`,{...t,children:[(0,Q.jsx)(Au,{open:r}),x,(0,Q.jsxs)(`span`,{className:a(ie,(f||u||m)&&`opacity-100`),children:[p?(0,Q.jsx)(Du,{active:f,onOpen:p}):null,h?(0,Q.jsx)(Ou,{active:m,onOpen:h}):null,d?(0,Q.jsx)(Eu,{facet:e.facet===`kv`?`kv`:`sql`,active:u,onOpen:d}):null,(0,Q.jsx)(ku,{label:e.label,onHide:n}),(0,Q.jsx)(Hn,{allOpen:y,disabled:v.length===0,onToggle:b,collapseLabel:`Collapse all in ${e.label}`,expandLabel:`Expand all in ${e.label}`,dataSlot:`store-facet-expand-toggle`,disclose:!0,bare:!0})]})]})}),(0,Q.jsx)(cr,{children:(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:e.stores.map(e=>(0,Q.jsx)(Cu,{node:e,facetWellClass:g.wellClass,facetIcon:g.icon,open:o(e.store.ref),onOpenChange:t=>s(e.store.ref,t),tablesOpen:o(Ki(e.store.ref)),onTablesOpenChange:t=>s(Ki(e.store.ref),t),selectedEffectRef:c,onSelect:l},e.store.ref))})})]})})}function Cu({node:e,facetWellClass:t,facetIcon:n,open:r,onOpenChange:i,tablesOpen:o,onTablesOpenChange:s,selectedEffectRef:c,onSelect:l}){let u=e.children[0];return ki(e.store)&&u?(0,Q.jsx)(Nu,{store:e.store,child:u,selected:c===u.effectRef,onSelect:l}):Wi(e.store)&&u?(0,Q.jsx)(Pu,{child:u,wellClass:t,icon:n,selected:c===u.effectRef,onSelect:l,nest:`store`}):(0,Q.jsx)(`li`,{"data-slot":`store-group`,"data-ref":e.store.ref,children:(0,Q.jsxs)(pr,{open:r,onOpenChange:i,children:[(0,Q.jsx)(dr,{nativeButton:!1,className:a(He,`group/store pl-4`),"data-slot":`store-group-toggle`,render:t=>(0,Q.jsxs)(`div`,{...t,children:[(0,Q.jsx)(Au,{open:r}),(0,Q.jsx)(q,{icon:Le,className:a(K,`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:Me,children:e.store.facet===`sql`?Ii(e.children).tables.length:e.children.length}),e.store.facet===`files`?(0,Q.jsx)(Mu,{driverId:e.store.driverId}):null]})}),(0,Q.jsx)(cr,{children:(0,Q.jsx)(wu,{node:e,facetWellClass:t,facetIcon:n,tablesOpen:o,onTablesOpenChange:s,selectedEffectRef:c,onSelect:l})})]})})}function wu({node:e,facetWellClass:t,facetIcon:n,tablesOpen:r,onTablesOpenChange:i,selectedEffectRef:o,onSelect:s}){let c=Ii(e.children);return e.store.facet!==`sql`||c.catalog.length===0?(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:e.children.map(r=>(0,Q.jsx)(Pu,{child:r,wellClass:t,icon:e.store.facet===`sql`?Fe:e.store.facet===`files`?Le:n,hint:e.store.facet===`files`?`bucket`:void 0,selected:o===r.effectRef,onSelect:s},r.effectRef))}):(0,Q.jsxs)(`ul`,{className:`flex flex-col`,children:[(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(pr,{open:r,onOpenChange:i,children:[(0,Q.jsx)(dr,{nativeButton:!1,className:a(He,`group/tables group/store pl-6`),"data-slot":`store-tables-toggle`,render:e=>(0,Q.jsxs)(`div`,{...e,children:[(0,Q.jsx)(Au,{open:r}),(0,Q.jsx)(q,{icon:k,className:a(K,L(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:Me,children:c.tables.length})]})}),(0,Q.jsx)(cr,{children:(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:c.tables.map(e=>(0,Q.jsx)(Pu,{child:e,wellClass:t,icon:Fe,nest:`deep`,selected:o===e.effectRef,onSelect:s},e.effectRef))})})]})}),c.catalog.map(e=>(0,Q.jsx)(Pu,{child:e,wellClass:t,icon:Tu(e),selected:o===e.effectRef,onSelect:s},e.effectRef))]})}function Tu(e){let t=Mi(e);return t===`index`?tt:t===`function`?Se:t===`trigger`?he:t===`extension`?rt:t===`policy`?m:Le}function Eu({facet:e,active:t,onOpen:n}){let r=e===`sql`?`SQL console`:`KV console`;return(0,Q.jsxs)(T,{children:[(0,Q.jsx)(b,{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:a(`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)(q,{icon:re,className:`size-3.5`,"aria-hidden":!0})})}),(0,Q.jsx)(u,{side:`bottom`,className:`text-[11px]`,children:r})]})}function Du({active:e,onOpen:t}){return(0,Q.jsxs)(T,{children:[(0,Q.jsx)(b,{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:a(`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)(q,{icon:oe,className:`size-3.5`,"aria-hidden":!0})})}),(0,Q.jsx)(u,{side:`bottom`,className:`text-[11px]`,children:`Schema visualizer`})]})}function Ou({active:e,onOpen:t}){return(0,Q.jsxs)(T,{children:[(0,Q.jsx)(b,{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:a(`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)(q,{icon:l,className:`size-3.5`,"aria-hidden":!0})})}),(0,Q.jsx)(u,{side:`bottom`,className:`text-[11px]`,children:`Query performance`})]})}function ku({label:e,onHide:t}){let n=`Hide ${e}`;return(0,Q.jsxs)(T,{children:[(0,Q.jsx)(b,{render:e=>(0,Q.jsx)(`button`,{...e,type:`button`,"aria-label":n,"data-slot":`store-facet-visibility`,onClick:n=>{n.stopPropagation(),e.onClick?.(n),t()},className:a(`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`),children:(0,Q.jsx)(q,{icon:W,className:`size-3.5`,"aria-hidden":!0})})}),(0,Q.jsx)(u,{side:`bottom`,className:`text-[11px]`,children:n})]})}function Au({open:e}){return(0,Q.jsx)(q,{icon:C,className:a(Je,!e&&`-rotate-90`),"aria-hidden":!0})}function ju({enabled:e}){let t=e?`RLS enabled`:`RLS disabled`;return(0,Q.jsxs)(T,{children:[(0,Q.jsx)(b,{render:n=>(0,Q.jsx)(`span`,{...n,"data-slot":`store-table-rls`,"data-rls":e?`on`:`off`,"aria-label":t,className:a(K,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)(q,{icon:e?ze:y,className:`size-3.5`,"aria-hidden":!0})})}),(0,Q.jsx)(u,{side:`right`,children:t})]})}function Mu({driverId:e}){return(0,Q.jsxs)(T,{children:[(0,Q.jsx)(b,{render:t=>(0,Q.jsx)(`span`,{...t,className:`shrink-0 font-mono text-[10px] text-muted-foreground`,"data-slot":`files-driver`,children:Ai(e)})}),(0,Q.jsx)(u,{side:`right`,className:`text-[11px]`,children:ji(e)})]})}function Nu({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:a(_e,`group/child pl-4`,n&&`bg-muted/70 text-foreground`),children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:a(Xe,n?G:`bg-transparent`)}),(0,Q.jsx)(q,{icon:Le,className:a(K,L(Bi.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)(Mu,{driverId:e.driverId})]})})}function Pu({child:e,wellClass:t,icon:n,selected:r,onSelect:i,hint:o,nest:s=`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:a(_e,`group/child`,s===`store`?`pl-4`:s===`deep`?`pl-12`:`pl-8`,r&&`bg-muted/70 text-foreground`),children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:a(Xe,r?G:`bg-transparent`)}),(0,Q.jsx)(q,{icon:n,className:a(K,L(t)),"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:Fi(e)}),o?(0,Q.jsx)(`span`,{className:`shrink-0 text-[10px] tracking-[0.08em] text-muted-foreground/70 uppercase`,children:o}):null,Pi(e)?(0,Q.jsx)(ju,{enabled:e.rls===!0}):null]})})}var Fu=`sql:oke_console`;function Iu(e){return e?`SELECT *\nFROM "${e}"\nLIMIT 50;`:`SELECT 1;`}function Lu(e){return e?`// list · get · set · delete · ttl\nlist ${e}`:`// list · get · set · delete · ttl
30
- list`}function Ru(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 zu(e){return e.children[0]?.name}function Bu(e){return e===Fu}function Vu(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 Hu(){return ot({mutationFn:async e=>{let t=await v(e),n=Vu(t);if(n)throw n;if(!t.data)throw Error(`Empty advise result`);return t.data}})}var Uu=[`console.store.sql.locks`],Wu=1e4;function Gu(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 Ku(e){return R({queryKey:[...Uu,e],enabled:e!==null,refetchInterval:Wu,queryFn:async()=>{if(!e)throw Error(`Missing store ref`);let t=await Re(e),n=Gu(t);if(n)throw n;if(!t.data)throw Error(`Empty SQL locks`);return t.data}})}var qu=[`console.store.sql.stats`];function Ju(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 Yu(e){return R({queryKey:[...qu,e],enabled:e!==null,queryFn:async()=>{if(!e)throw Error(`Missing store ref`);let t=await _(e),n=Ju(t);if(n)throw n;if(!t.data)throw Error(`Empty SQL stats`);return t.data}})}function Xu(e){return e?e.installed?`on`:e.available?`enable`:`cta`:null}var Zu=[`console.store.kv.stats`];function Qu(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 $u(e){return R({queryKey:[...Zu,e],enabled:e!==null,queryFn:async()=>{if(!e)throw Error(`Missing store ref`);let t=await B(e),n=Qu(t);if(n)throw n;if(!t.data)throw Error(`Empty KV stats`);return t.data}})}function ed({stores:e,selectedEffectRef:t,tenant:n,leading:r}){let i=Ru(e,`kv`,t),[a,o]=(0,Z.useState)(!1),s=$u(i?{ref:i.ref,...n?{tenant:n}:{},...a?{revealPii:!0}:{}}:null),c=ad(s.error),u=od(s.error),d=(0,Z.useMemo)(()=>(s.data?.commands??[]).map(nd),[s.data?.commands]),f=(0,Z.useMemo)(()=>(s.data?.slowlog??[]).map(rd),[s.data?.slowlog]);if(!i)return(0,Q.jsx)(ui,{icon:l,title:`No KV store`,description:`KV performance reads INFO / COMMANDSTATS / SLOWLOG on a redis-backed namespace.`,leading:r});if(u===`KvStatsUnsupported`)return(0,Q.jsx)(ui,{leading:r,icon:l,title:`Engine telemetry unavailable`,description:c??`KV stats are not available on this driver (in-process memory has no INFO / SLOWLOG).`});let p=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)(Wt,{dataSlot:`store-kv-performance-header`,leading:r,icon:(0,Q.jsx)(q,{icon:l,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)(hi,{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: `,be,`. 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:Ce,children:[(0,Q.jsx)(td,{label:`Hit rate`,value:id(p?.hitRate??null),title:`keyspace_hits / (hits + misses)`}),(0,Q.jsx)(td,{label:`Ops / sec`,value:p?.opsPerSec==null?`—`:String(p.opsPerSec),title:`instantaneous_ops_per_sec`}),(0,Q.jsx)(td,{label:`Evicted`,value:p?.evictedKeys==null?`—`:String(p.evictedKeys),title:`evicted_keys`}),(0,Q.jsx)(td,{label:`Expired`,value:p?.expiredKeys==null?`—`:String(p.expiredKeys),title:`expired_keys`})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,Q.jsx)(Qr,{rows:d,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)(Qr,{rows:f,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 td({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 nd(e){return{command:e.command,calls:e.calls,usec:e.usec,usec_per_call:e.usecPerCall}}function rd(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 ad(e){return e?e instanceof Error?e.message:String(e):null}function od(e){return!e||typeof e!=`object`||!(`code`in e)?null:typeof e.code==`string`?e.code:null}function sd({stores:e,selectedEffectRef:t,tenant:n,facet:r=`sql`,leading:i}){if(r===`kv`)return(0,Q.jsx)(ed,{stores:e,selectedEffectRef:t,tenant:n,leading:i});let a=Ru(e,`sql`,t),[o,s]=(0,Z.useState)(!1),[c,u]=(0,Z.useState)(null),d=a?{ref:a.ref,...n?{tenant:n}:{}}:null,f=Yu(d),p=Ku(a?{...d,...o?{revealPii:!0}:{}}:null),m=Hu(),h=jo(),g=hd(f.error),_=gd(f.error),v=hd(p.error),y=(0,Z.useMemo)(()=>(f.data?.statements??[]).map(dd),[f.data?.statements]),b=(0,Z.useMemo)(()=>(p.data?.rows??[]).map(fd),[p.data?.rows]);if(!a)return(0,Q.jsx)(ui,{icon:l,title:`No SQL store`,description:`Query performance reads pg_stat_statements on a postgres-backed SQL store.`,leading:i});if(_===`PgStatStatementsNotPreloaded`)return(0,Q.jsx)(ui,{leading:i,icon:l,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:`,` `,_,`.`]})});if(_===`PgStatStatementsUnsupported`)return(0,Q.jsx)(ui,{leading:i,icon:l,title:`Engine telemetry unavailable`,description:g??`pg_stat_statements is not available on this driver (memory, pglite, or CockroachDB).`});let x=f.data?.advisor,S=Xu(x),C=f.data?.kpis,w=xa.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)(Wt,{dataSlot:`store-performance-header`,leading:i,icon:(0,Q.jsx)(q,{icon:l,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)(hi,{piiMasked:!o,disabled:p.isPending,onToggle:()=>s(e=>!e)}),(0,Q.jsx)(cd,{advisor:x,pending:h.isPending,onEnable:()=>{h.mutateAsync({ref:a.ref,sql:Ha(`index_advisor`,{cascade:!0}),allowWrite:!0,...n?{tenant:n}:{}}).then(()=>f.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: `,ke,`. 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:Ce,children:[(0,Q.jsx)(ud,{label:`Slow queries`,value:C?String(C.slowQueries):`—`,title:`Statements with mean exec ≥ 100ms`}),(0,Q.jsx)(ud,{label:`Cache hit rate`,value:pd(C?.cacheHitRate??null),title:`shared_blks_hit / (hit + read) across listed statements`}),(0,Q.jsx)(ud,{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)(Qr,{rows:y,error:_&&_!==`PgStatStatementsNotCreated`?g:null,pending:f.isPending,meta:f.data?`${f.data.rowCount} statements${f.data.truncated?` (capped)`:``}`:null,storeRef:a.ref})}),x?.installed&&(f.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`}),(f.data?.statements??[]).slice(0,6).map((e,t)=>(0,Q.jsxs)(F,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 rounded-none text-[11px]`,disabled:!e.query||m.isPending,onClick:()=>{u(e),m.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)(ld,{query:c.query,result:m.data??null,error:hd(m.error),pending:m.isPending}):null,(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 border-t border-border/60`,children:(0,Q.jsx)(Qr,{rows:b,error:v,pending:p.isPending&&!p.data,meta:p.data?`${p.data.rows.length} blocking pair${p.data.rows.length===1?``:`s`} · polling`:`locks`,storeRef:a.ref})})]})}function cd({advisor:e,pending:t,onEnable:n}){let r=Xu(e);return r===`on`?(0,Q.jsx)(`span`,{className:a(se,Ze),"data-slot":`index-advisor-on`,children:`Index Advisor on`}):r===`cta`||r!==`enable`?null:(0,Q.jsx)(F,{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 ld({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 `,md(t.totalCostBefore),` → `,md(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)(F,{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 ud({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 dd(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:pd(e.cacheHitRate)}}function fd(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 pd(e){return e==null?`—`:`${(e*100).toFixed(2)}%`}function md(e){return e==null?`—`:String(e)}function hd(e){return e?e instanceof Error?e.message:String(e):null}function gd(e){return!e||typeof e!=`object`||!(`code`in e)?null:typeof e.code==`string`?e.code:null}var _d=/^\s*(\/\/|#|--)/,vd=/^(list|get|set|delete|ttl)\b/i;function yd(e){let t=Sd(e);if(t.length===0)return{kind:`list`,prefix:``};let n=vd.exec(t)?.[1]?.toLowerCase();if(n===`set`)return Td(t);if(n===`list`)return Cd(t);if(n===`get`||n===`delete`||n===`ttl`)return wd(n,t);let r=xd(t)??t;return/\s/.test(r)?{kind:`error`,message:"Use `list`, `get`, `set`, `delete`, or `ttl`."}:{kind:`list`,prefix:r}}function bd(e){let t={};return e.keepValue||(t.value=e.value),e.ttl!==void 0&&(t.ttl=e.ttl),t}function xd(e){let t=e.split(`
31
- `);for(let e=t.length-1;e>=0;--e){let n=t[e]?.trim()??``;if(!(n.length===0||_d.test(n)))return n}return null}function Sd(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||_d.test(r)||vd.test(r)&&(n=e)}return n>=0?t.slice(n).join(`
33
- `).trim():xd(e)??``}function Cd(e){if(e.includes(`(`)){let t=Ed(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=Dd(t.args[0]??``,`list prefix`);return n.kind===`error`?n:{kind:`list`,prefix:n.value}}let t=/^list(?:\s+(\S.*))?$/i.exec(xd(e)??e);return t?{kind:`list`,prefix:t[1]?.trim()??``}:{kind:`error`,message:'Use `list [prefix]` or `list("prefix")`.'}}function wd(e,t){if(t.includes(`(`)){let n=Ed(t,e);if(n.kind===`error`)return n;if(n.args.length!==1)return{kind:`error`,message:`${e} requires a key.`};let r=Dd(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(xd(t)??t)?.[1]?.trim()??``;return n.length===0?{kind:`error`,message:`${e} requires a key.`}:{kind:e,key:n}}function Td(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=Ed(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=Od(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=Od(a);if(!e.ok)return{kind:`error`,message:`set value: ${e.error}`};s=e.value}let c;if(r[2]!==void 0){let e=Od(r[2]);if(!e.ok||typeof e.value!=`string`)return{kind:`error`,message:`TTL must be a duration string like "30m".`};let t=Sr(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 Ed(e,t){let n=e.indexOf(`(`);if(n<0)return{kind:`error`,message:`${t} requires parentheses.`};let r=Ad(e,n);if(r<0)return{kind:`error`,message:`Unclosed ${t}(…).`};let i=e.slice(r+1).trim();return i.length>0&&!_d.test(i)?{kind:`error`,message:`Unexpected input after ${t}(…).`}:{kind:`ok`,args:kd(e.slice(n+1,r))}}function Dd(e,t){let n=Od(e);return!n.ok||typeof n.value!=`string`?{kind:`error`,message:`${t} must be a string.`}:{kind:`ok`,value:n.value}}function Od(e){try{return{ok:!0,value:JSON.parse(e)}}catch(e){return{ok:!1,error:e instanceof Error?e.message:`invalid JSON`}}}function kd(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 Ad(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 jd=8,Md=24,Nd=24;function Pd(e){return/^Query \d+$/.test(e)}function Fd(e){let t=new Set(e.map(e=>e.title)),n=1;for(;t.has(`Query ${n}`);)n+=1;return`Query ${n}`}function Id(e,t){return e.length>=jd?e:[...e,{id:Qd(),title:Fd(e),text:t}]}function Ld(e,t,n){let r=e.filter(e=>e.id!==t);return r.length>0?r:[{id:Qd(),title:`Query 1`,text:n}]}function Rd(e,t,n){return e.map(e=>e.id===t?{...e,text:n}:e)}function zd(e,t,n){let r=n.trim().replace(/\s+/g,` `),i=r.length>0?r.slice(0,48):Fd(e.filter(e=>e.id!==t));return e.map(e=>e.id===t?{...e,title:i}:e)}function Bd(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,Nd)}function Vd(e,t){return[{...t,id:Qd()},...e].slice(0,Md)}function Hd(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 Ud(e){let t=Yd(e),n=af(nf(),t,$d);if(n)return n;let r=af(rf(),t,$d);return r&&of(nf(),t,r),r}function Wd(e,t){of(nf(),Yd(e),t)}function Gd(e){return af(rf(),Xd(e),ef)??[]}function Kd(e,t){of(rf(),Xd(e),t)}function qd(e){return af(nf(),Zd(e),tf)??[]}function Jd(e,t){of(nf(),Zd(e),t)}function Yd(e){return`oke_store_query_tabs_${e}`}function Xd(e){return`oke_store_query_history_${e}`}function Zd(e){return`oke_store_query_saved_${e}`}function Qd(){return`q_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function $d(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 ef(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 tf(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 nf(){try{return typeof localStorage>`u`?null:localStorage}catch{return null}}function rf(){try{return typeof sessionStorage>`u`?null:sessionStorage}catch{return null}}function af(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 of(e,t,n){if(e)try{e.setItem(t,JSON.stringify(n))}catch{}}var sf=/^\s*(\/\/|#|--)/,cf=/^(list|get|set|delete|ttl)\b/i;function lf(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||sf.test(e)){n.push(e),r+=1;continue}let i=r+1;if(cf.test(e))for(;i<t.length;){let e=t[i]?.trim()??``;if(cf.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||sf.test(e)){o.unshift(a.pop()?.trim()??``);continue}break}n.push(uf(a.join(`
36
- `))),n.push(...o),r=i}return n.join(`
37
- `).replace(/\n{3,}/g,`
38
-
39
- `).trim()}function uf(e){let t=yd(e);return t.kind===`error`?e.trim():df(t)}function df(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`:ff(e.value)];return e.ttl!==void 0&&e.ttl!==null&&t.push(JSON.stringify(e.ttl)),`set(${t.join(`, `)})`}}}function ff(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 pf(e,t,n,r){let i=e?.stores?.[t]?.tables?.[n];return i?.columns?mf(i.columns,r):[]}function mf(e,t){return Object.entries(e).map(([e,n])=>hf(e,n,t?.[e]))}function hf(e,t,n){let r=gf(t)?t:null,i=r?.type===`integer`?`integer`:r?.type===`text`?`string`:`unknown`,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,...o===void 0?{}:{description:o},...t.pii===!0?{pii:!0}:{},...t.sensitive===!0?{sensitive:!0}:{},...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}}}:{}}}function gf(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}var _f=248,vf=32,yf=22,bf=4;function xf(e){return vf+Math.max(e,1)*yf+bf}function Sf(e,t,n){return t.id===n.id?`self`:e.unique===!0||e.primaryKey===!0?`one-to-one`:Uf(t)?`many-to-many`:`many-to-one`}function Cf(e,t){let n=e===`one-to-one`?`One-to-one`:e===`many-to-many`?`Many-to-many`:e===`self`?`Self`:`Many-to-one`;return t.length>0?`${n} ${t}`:n}function wf(e,t){let n=[];for(let r of e)if(r.facet===`sql`)for(let e of r.children)Ni(e)||n.push({id:e.effectRef,name:e.name,storeName:r.name,storeRef:r.ref,columns:Af(r,e.name,e.columnDescriptions,e.piiColumns,t)});return Nf(n)}function Tf(e){let t=new Set(e.map(e=>e.storeRef)).size>1,n=Vf(e,zf(e));return{tables:e,nodes:Hf(e,n,t),edges:n}}function Ef(e,t){if(!t)return null;let n=new Set([t]);for(let r of e)r.source===t&&n.add(r.target),r.target===t&&n.add(r.source);return n.size>1?n:null}function Df(e,t,n,r=[],i=!0){let a=t.trim().toLowerCase(),o=i?Ef(r,n):null;return e.map(e=>{let t=a.length===0||e.data.table.name.toLowerCase().includes(a)||e.data.table.storeName.toLowerCase().includes(a),r=n!==null&&e.id===n,i=a.length>0&&!t,s=o!==null&&!o.has(e.id);return{...e,data:{...e.data,dimmed:i||s,selected:r}}})}function Of(e,t,n=!0,r=!0){let i=n?Ef(e,t):null;return e.map(e=>{let n=i!==null&&e.source!==t&&e.target!==t,a=i!==null&&!n;return{...e,animated:r&&a,style:{...e.style,opacity:n?.14:1,strokeWidth:a?2.25:n?1:1.5}}})}function kf(e){let t=[],n=null;for(let r of e){r.storeName!==n&&(t.push(`-- ${r.storeName}`),n=r.storeName);let e=r.columns.map(e=>{let t=[` ${Wf(e.name)}`,e.type];if(e.primaryKey?t.push(`PRIMARY KEY`):e.nullable===!1&&t.push(`NOT NULL`),e.unique&&!e.primaryKey&&t.push(`UNIQUE`),e.references?.table&&e.inferredRef!==!0){let n=e.references.column?`${Wf(e.references.table)} (${Wf(e.references.column)})`:Wf(e.references.table);t.push(`REFERENCES ${n}`)}return t.join(` `)}),i=e.length>0?`\n${e.join(`,
40
- `)}\n`:`
41
- `;t.push(`CREATE TABLE ${Wf(r.name)} (${i});`)}return t.join(`
42
-
43
- `)}function Af(e,t,n,r,i){let a=i?.stores?.[e.name]?.tables?.[t];if(a?.columns)return jf(a.columns,r);let o=fi(r);return[...new Set([...Object.keys(n),...r])].map(e=>({name:e,type:`unknown`,...o.has(e)?{pii:!0}:{}}))}function jf(e,t){let n=fi(t);return Object.entries(e).map(([e,t])=>{let r=Mf(t)?t:null,i=r?.type===`integer`?`integer`:r?.type===`text`?`text`:`unknown`,a=t.pii===!0||n.has(e),o=r?.references;return{name:e,type:i,...a?{pii:!0}:{},...r?.primaryKey===!0?{primaryKey:!0}:{},...r?.unique===!0?{unique:!0}:{},...r?.nullable===!1||r?.primaryKey===!0?{nullable:!1}:{nullable:!0},...o?.table?{references:{table:o.table,...o.column?{column:o.column}:{}}}:{}}})}function Mf(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 Nf(e){return e.map(t=>({...t,columns:t.columns.map(n=>{if(n.references?.table)return n;let r=Pf(t,n.name,e);return r?{...n,references:r,inferredRef:!0}:n})}))}function Pf(e,t,n){let r=n.filter(t=>t.storeRef===e.storeRef),i=e=>e.columns.find(e=>e.primaryKey)?.name??`id`;if(t===`parent_id`||t===`parentId`)return e.columns.some(e=>e.name===`parent_kind`||e.name===`parentKind`)?null:{table:e.name,column:i(e)};let a=Ff(t);if(!a)return null;let o=If(a,e,r);return o?{table:o.name,column:i(o)}:null}function Ff(e){return e===`id`||e===`Id`?null:e.endsWith(`_id`)&&e.length>3?e.slice(0,-3):e.endsWith(`Id`)&&e.length>2?e.slice(0,-2):null}function If(e,t,n){let r=Rf(e),i=[e,r,Lf(e),Lf(r)];for(let e of i){let r=n.find(t=>t.name===e);if(r)return r.id===t.id?null:r}let a=[`_${Lf(r)}`,`_${r}`,`_${Lf(e)}`,`_${e}`],o=n.filter(e=>e.id!==t.id&&a.some(t=>e.name.endsWith(t)));return o.length===1?o[0]??null:null}function Lf(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 Rf(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1_$2`).replace(/([A-Z])([A-Z][a-z])/g,`$1_$2`).toLowerCase()}function zf(e){let t=new Map;for(let n of e){let e=[n.name.toLowerCase(),n.id.toLowerCase()];for(let r of e){let e=t.get(r)??[];e.push(n),t.set(r,e)}}return t}function Bf(e,t,n){let r=n.get(t.toLowerCase())??[];return r.length===0?null:r.find(t=>t.storeRef===e.storeRef)??r[0]??null}function Vf(e,t){let n=[],r=new Set;for(let i of e)for(let e of i.columns){let a=e.references;if(!a?.table)continue;let o=Bf(i,a.table,t);if(!o)continue;let s=a.column??o.columns.find(e=>e.primaryKey)?.name,c=`${i.id}.${e.name}->${o.id}.${s??`*`}`;if(r.has(c))continue;r.add(c);let l=e.inferredRef===!0,u=Sf(e,i,o);n.push({id:c,source:i.id,target:o.id,sourceHandle:`out:${e.name}`,...s?{targetHandle:`in:${s}`}:{},type:`relation`,animated:!1,markerEnd:{type:pt.ArrowClosed,width:16,height:16,color:`#38BDF8`},style:{stroke:`#38BDF8`,strokeWidth:1.5,...l?{strokeDasharray:`5 4`}:{}},data:{kind:`references`,inferred:l,relation:u,column:e.name}})}return n}function Hf(e,t,n){let r=new xr.graphlib.Graph;r.setGraph({rankdir:`LR`,align:`UL`,nodesep:72,ranksep:160,edgesep:28,marginx:40,marginy:40}),r.setDefaultEdgeLabel(()=>({}));for(let t of e)r.setNode(t.id,{width:_f,height:xf(t.columns.length)});let i=new Set;for(let e of t){let t=`${e.source}->${e.target}`;i.has(t)||!r.hasNode(e.source)||!r.hasNode(e.target)||(i.add(t),r.setEdge(e.source,e.target))}return xr.layout(r),e.map(e=>{let t=r.node(e.id),i=xf(e.columns.length);return{id:e.id,type:`table`,position:{x:(t?.x??0)-_f/2,y:(t?.y??0)-i/2},data:{table:e,showStore:n},width:_f,height:i,style:{width:_f,height:i}}})}function Uf(e){return e.columns.filter(t=>t.references?.table&&t.references.table!==e.name).length<2?!1:e.columns.every(e=>e.primaryKey===!0||e.references!==void 0)}function Wf(e){return/^[A-Za-z_][A-Za-z0-9_]*$/.test(e)?e:`"${e.replaceAll(`"`,`""`)}"`}function Gf(e,t,n){if(e){let r=pf(n,e.name,t.name,t.columnDescriptions);if(r.length>0)return r}let r=fi(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 Kf(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,qf(r));return[...t.entries()].map(([e,t])=>({name:e,type:t}))}function qf(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 Jf(e,t){if(!e)return[];let n=new Map(e.facet===`sql`?wf([e],t).map(e=>[e.name,e]):[]);return e.children.filter(e=>!Ni(e)).map(r=>({name:r.name,columns:Gf(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 Yf({manifest:e,asGate:t,onChange:n}){let r=Ln(!0),i=Mn(),o=(0,Z.useMemo)(()=>Pn(Kn(e),r.data??null),[e,r.data]),s=(0,Z.useMemo)(()=>Wn(o),[o]),c=(0,Z.useMemo)(()=>Rn(i.data??[],o),[i.data,o]),l=o.gates.find(e=>e.kind===`public`)?.description??`Intentionally unauthenticated.`,u=Vn(t),d=t!==null,[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(`policy`),g=s.find(e=>e.id===t)??null,_=c.find(e=>e.id===f&&e.gate===t)??null,v=s.length>0||c.length>0,y=e=>{if(e===`operator`){p(null),n(null);return}if(e===`public`){p(null),n(`public`);return}if(u===`as`)return;let t=g?.id??s[0]?.id??c[0]?.gate??null;t!==null&&(c[0]&&t===c[0].gate&&s.length===0?(p(c[0].id),h(`user`)):h(`policy`),n(t))};return(0,Q.jsxs)(sn,{children:[(0,Q.jsx)(Gt,{render:e=>(0,Q.jsxs)(F,{...e,type:`button`,variant:`ghost`,size:`sm`,className:a(`h-full max-w-44 min-w-0 rounded-none px-2 text-[11px]`,d&&`text-sky-800 dark:text-sky-300`),"aria-label":d?`View data as Gate ${t}`:`View data as Operator (default)`,"data-slot":`store-query-gate`,children:[(0,Q.jsx)(q,{icon:tr.gate.icon,"data-icon":`inline-start`,className:`size-3.5`}),(0,Q.jsx)(`span`,{className:`truncate`,children:jn(t)})]})}),(0,Q.jsxs)(tn,{align:`start`,className:`w-80 overflow-hidden p-0`,children:[(0,Q.jsx)(kn,{children:`View as`}),(0,Q.jsxs)(Fn,{label:`View data as`,children:[(0,Q.jsx)(Bn,{mode:`operator`,title:`Operator`,caption:`Bypass`,selected:u===`operator`,onSelect:()=>y(`operator`)}),(0,Q.jsx)(Bn,{mode:`public`,title:`Public`,caption:`Anonymous`,selected:u===`public`,onSelect:()=>y(`public`)}),(0,Q.jsx)(Bn,{mode:`as`,title:`As`,caption:_?_.label:g?.label??`User / policy`,selected:u===`as`,disabled:!v,onSelect:()=>y(`as`)})]}),u===`operator`?(0,Q.jsxs)(Un,{title:`Operator`,badge:`Default`,children:[`Bypasses RLS. No `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`oke.gate`}),` is set.`]}):null,u===`public`?(0,Q.jsxs)(Un,{title:`Public`,children:[l,` Sets `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`oke.gate`}),` to`,` `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`public`}),`.`]}):null,u===`as`?(0,Q.jsx)(Gn,{tab:m,onTabChange:h,policies:s,users:c,asGate:t,asUserId:_?.id??null,onSelectPolicy:e=>{p(null),h(`policy`),n(e.id)},onSelectUser:e=>{p(e.id),h(`user`),n(e.gate)}}):null]})]})}function Xf({store:e,facet:t,manifest:n,onPickTable:r,onPickColumn:i,onCollapse:o,tenant:s=null,tenancyDeclared:c=!1}){let l=e?.children??[],u=t===`sql`,d=(0,Z.useMemo)(()=>Jf(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:a(Ce,`justify-between px-2`),children:[(0,Q.jsx)(`p`,{className:a(et,`min-w-0 truncate font-mono`),children:u?`Schema`:`Namespaces`}),o?(0,Q.jsx)(X,{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:o,className:ue,children:(0,Q.jsx)(q,{icon:g,className:`size-3.5`})})}):null]}),(0,Q.jsx)(`ul`,{className:`min-h-0 flex-1 overflow-y-auto`,children:l.length===0?(0,Q.jsx)(`li`,{className:`px-2 py-4 text-[11px] text-muted-foreground`,children:`No resources.`}):l.map(a=>(0,Q.jsx)(Zf,{store:e,child:a,facet:t,manifest:n,sqlColumns:d.find(e=>e.name===a.name)?.columns,onPickTable:r,onPickColumn:i,tenant:s,tenancyDeclared:c},a.effectRef))})]})}function Zf({store:e,child:t,facet:n,manifest:r,sqlColumns:i,onPickTable:o,onPickColumn:s,tenant:c,tenancyDeclared:l}){let u=n===`sql`,[d,f]=(0,Z.useState)(!0),p=i??Gf(e,t,r),m=!u||p.length>0;return(0,Q.jsxs)(`li`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center`,children:[m?(0,Q.jsx)(`button`,{type:`button`,"aria-expanded":d,"aria-label":`${d?`Collapse`:`Expand`} ${t.name}`,onClick:()=>f(e=>!e),className:Te,children:(0,Q.jsx)(q,{icon:C,className:a(`size-3 transition-transform`,!d&&`-rotate-90`)})}):(0,Q.jsx)(`span`,{className:`size-6`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>o(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:u?`SELECT * FROM "${t.name}"`:`list ${t.name}:`,children:t.name})]}),u&&d&&p.length>0?(0,Q.jsx)(`ul`,{className:`border-l border-border/60 ml-3`,children:p.map(e=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s(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)(pi,{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,!u&&d&&e?(0,Q.jsx)(Qf,{store:e,namespace:t.name,tenant:c,tenancyDeclared:l,onPickField:e=>s(t.name,e)}):null]})}function Qf({store:e,namespace:t,tenant:n,tenancyDeclared:r,onPickField:i}){let a=!r||n!==null&&n.length>0,o=mn({ref:e.ref,child:t,prefix:`${t}:`,limit:40,...n?{tenant:n}:{}},a),s=Kf((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 $f({facet:e,onExpand:t}){let n=e===`sql`?`Schema`:`Fields`;return(0,Q.jsx)(X,{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)(q,{icon:D,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 ep({facet:e,stores:t,selectedEffectRef:n,tenancyDeclared:r,tenants:i,tenant:s,onTenantChange:l,manifest:u=null,leading:d}){let f=Bi[e],p=(0,Z.useMemo)(()=>t.filter(t=>t.facet===e),[t,e]),[m,h]=(0,Z.useState)(()=>Ru(t,e,n)?.ref??p[0]?.ref??``),g=p.find(e=>e.ref===m)??Ru(p,e,null),_=rp(g,e,n),[v,y]=(0,Z.useState)(()=>Ud(e)??[{id:`q_1`,title:`Query 1`,text:_}]),[b,S]=(0,Z.useState)(()=>v[0]?.id??`q_1`),w=v.find(e=>e.id===b)??v[0],T=w?.text??_,[E,D]=(0,Z.useState)(null),[O,k]=(0,Z.useState)(null),[A,j]=(0,Z.useState)(null),[P,I]=(0,Z.useState)(null),[L,R]=(0,Z.useState)(!1),[z,B]=(0,Z.useState)(!1),[V,te]=(0,Z.useState)(!0),[H,ne]=(0,Z.useState)(null),[ie,oe]=(0,Z.useState)(!0),[se,ce]=(0,Z.useState)(()=>Gd(e)),[le,de]=(0,Z.useState)(()=>qd(e)),[fe,me]=(0,Z.useState)(!1),[he,_e]=(0,Z.useState)(null),[ye,be]=(0,Z.useState)(``),[xe,Se]=(0,Z.useState)({start:0,end:0}),[U,we]=(0,Z.useState)([]),[Te,Ee]=(0,Z.useState)(0),[Oe,G]=(0,Z.useState)(!1),ke=(0,Z.useRef)(null),Ae=(0,Z.useRef)(!1),je=(0,Z.useRef)(null),Me=jo(),Ne=o(),Pe=!r||s!==null&&s.length>0,Fe=g?Bu(g.ref):!1,K=e===`sql`,Ie=Qn(`Enter`),Le=Qn(`S`),Re=(0,Z.useMemo)(()=>Jf(g,u),[g,u]),ze=(0,Z.useMemo)(()=>K?kr(T):[],[K,T]),Be=(0,Z.useMemo)(()=>ze.map(e=>e.startLine),[ze]),Ve=xe.end!==xe.start,He=(0,Z.useMemo)(()=>K?Ar(T,xe.start,xe.end,`current`):[T],[xe.end,xe.start,K,T]),Ue=K&&He.some(e=>Dr(e));(0,Z.useEffect)(()=>{let r=Ru(t,e,n);r&&h(e=>p.some(t=>t.ref===e)?e:r.ref)},[t,e,n,p]),(0,Z.useEffect)(()=>{Wd(e,v)},[e,v]),(0,Z.useEffect)(()=>{Jd(e,le)},[e,le]),(0,Z.useEffect)(()=>()=>{je.current!==null&&window.clearTimeout(je.current)},[]);let We=e=>{w&&y(t=>Rd(t,w.id,e))},Ge=t=>{ce(n=>{let r=Vd(n,t);return Kd(e,r),r})},qe=e=>{let t=Math.max(0,Date.now()-e.started);we([]),Ee(0),D(e.nextRows),k(e.nextMeta?`${e.nextMeta} · ${t}ms`:`${t}ms`),j(e.sqlText),I(e.nextError),Ge({at:Date.now(),storeRef:g?.ref??``,text:e.sqlText,ok:e.nextError===null,rowCount:e.nextRows?.length??null,durationMs:t,...e.nextError?{error:e.nextError}:{}})},Je=(e,t)=>{let n=e[t];we(e),Ee(t),D(n?.rows??null),I(n?.error??null),k(n?.meta??null),j(n?.executed??e.map(e=>e.executed).join(`
44
- `)??null)},Ye=(e,t=!V,n=H)=>{if(!g)return;if(oe(!0),I(null),!Pe){I(`Select a tenant first.`);return}if(Fe){I(`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){I(`Nothing to run.`);return}let i=Date.now();G(!0),we([]),Ee(0),(async()=>{try{let e=[],a=!1;for(let i of r){let r=Pr(i);r&&(a=!0);try{let a=await Me.mutateAsync({ref:g.ref,sql:i,...r?{allowWrite:!0}:{},...t?{revealPii:!0}:{},...n?{asGate:n}:{},...s?{tenant:s}:{}}),o=np(a.rows),c=[o===null?`${a.rows.length} row${a.rows.length===1?``:`s`}`:`${o} change${o===1?``:`s`}`,`routed ${a.routedRole}`];a.masked?c.push(`PII masked`):t&&c.push(`PII visible`),a.asGate&&c.push(a.gateApplied?`as ${a.asGate}`:`as ${a.asGate} (not applied)`),e.push({label:Fr(i),rows:a.rows,error:null,meta:c.join(` · `),executed:i})}catch(t){e.push({label:Fr(i),rows:null,error:t instanceof Error?t.message:String(t),meta:null,executed:i});break}}a&&Ne.invalidateQueries({queryKey:Xn});let o=Math.max(0,Date.now()-i),c=e[e.length-1],l=r.join(`
45
- `);Je(e.map(e=>({...e,meta:e.meta?`${e.meta} · ${o}ms`:e.error?null:`${o}ms`})),Math.max(0,e.length-1)),Ge({at:Date.now(),storeRef:g.ref,text:l,ok:c?.error==null,rowCount:e.reduce((e,t)=>e+(t.rows?.length??0),0),durationMs:o,...c?.error?{error:c.error}:{}})}finally{G(!1)}})()},Xe=(e,t=!V,n=H)=>{if(!g)return;if(oe(!0),I(null),!Pe){I(`Select a tenant first.`);return}if(K){Ye([e],t,n);return}let r=Date.now(),i=yd(e);if(i.kind===`error`){I(i.message);return}R(!0);let a=s?{tenant:s}:{};(async()=>{try{if(i.kind===`delete`){let t=await M({ref:g.ref,keys:[i.key],...a});if(t.error){qe({sqlText:e,nextRows:null,nextMeta:null,nextError:tp(t.error),started:r});return}await Ne.invalidateQueries({queryKey:Xn});let n=t.data?.deleted??0;qe({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 nt({ref:g.ref,key:i.key,...a,patch:bd(i),commit:!0});if(t.error){qe({sqlText:e,nextRows:null,nextMeta:null,nextError:tp(t.error),started:r});return}await Ne.invalidateQueries({queryKey:Xn})}let t=i.kind===`list`?i.prefix:i.key,n=await ee({ref:g.ref,prefix:t,limit:i.kind===`list`?200:1,...a});if(n.error){qe({sqlText:e,nextRows:null,nextMeta:null,nextError:tp(n.error),started:r});return}let o=n.data?.keys??[],s=i.kind===`list`?o:o.filter(e=>e.key===i.key);if(i.kind===`ttl`){let t=s[0];qe({sqlText:e,nextRows:[{key:i.key,ttlMs:t?.ttlMs??null,ttl:Nr(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}]:[];qe({sqlText:e,nextRows:c,nextMeta:i.kind===`set`?`set ${i.key}`:`${c.length} key${c.length===1?``:`s`}`,nextError:null,started:r})}finally{R(!1)}})()},Ze=()=>{if(K){Ye(He);return}let e=Math.min(xe.start,xe.end),t=Math.max(xe.start,xe.end);Xe(t>e?T.slice(e,t):T)},Qe=()=>{Ye(Ar(T,xe.start,xe.end,`all`))},$e=e=>{Ye(He.map(t=>li(t,e)))},tt=e=>{let t=ze.find(t=>t.startLine===e);t&&Ye([t.text])},rt=t=>{let n=p.find(e=>e.ref===t);h(t),w&&y(t=>Rd(t,w.id,rp(n,e,null))),D(null),k(null),j(null),I(null),we([]),Ee(0)},at=e=>{We(K?Iu(e):Lu(`${e}:`))},ot=()=>{let t=Id(v,rp(g,e,null)),n=t[t.length-1];!n||t===v||(y(t),S(n.id))},st=e=>{Pd(e.title)||(de(t=>Bd(t,{id:e.id,title:e.title,text:e.text})),me(!0),je.current!==null&&window.clearTimeout(je.current),je.current=window.setTimeout(()=>me(!1),1200))},ct=(e,t)=>{let n=zd(v,e,t);if(y(n),_e(null),!Ae.current)return;Ae.current=!1;let r=n.find(t=>t.id===e);r&&st(r)},lt=()=>{Ae.current=!1,_e(null)},ut=e=>{S(e.id),_e(e.id),be(e.title)},dt=()=>{if(w){if(Pd(w.title)){Ae.current=!0,ut(w);return}st(w)}},ft=e=>{if(v.find(t=>t.id===e.id)){y(t=>Rd(zd(t,e.id,e.title),e.id,e.text)),S(e.id);return}if(v.length>=8){if(!w)return;y(t=>Rd(zd(t,w.id,e.title),w.id,e.text));return}let t=[...v,{id:e.id,title:e.title,text:e.text}];y(t),S(e.id)},pt=e=>{he===e&&lt();let t=Ld(v,e,_);y(t),b===e&&S(t[t.length-1]?.id??t[0]?.id??`q_1`)},mt=K?Me.isPending||Oe:L,ht=Zn(`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)(Wt,{dataSlot:`store-query-header`,className:`relative z-30`,leading:d,icon:(0,Q.jsx)(q,{icon:f.icon,className:`size-4`}),wellClassName:f.wellClass,title:K?`SQL Query`:`KV Query`,badge:(0,Q.jsx)(`span`,{className:`font-mono text-[10px] font-medium tracking-[0.08em] text-muted-foreground`,children:g?.ref??`No store`}),subtitle:(0,Q.jsxs)(`span`,{className:`truncate font-mono text-[11px] leading-none text-muted-foreground`,children:[K?`DML / DDL`:`list / get / set / delete / ttl`,Ve?` · selection${He.length>1?` (${He.length})`:``}`:K?ze.length>1?` · ${ze.length} statements`:` · current statement`:``]}),actions:(0,Q.jsxs)(Q.Fragment,{children:[p.length>1?(0,Q.jsxs)(`div`,{className:`flex h-full items-stretch`,"data-slot":`store-query-store`,children:[(0,Q.jsx)(`span`,{className:a(et,`flex items-center px-2`),children:`Store`}),(0,Q.jsxs)(ca,{value:g?.ref??``,onValueChange:rt,className:`z-40 inline-flex h-full min-w-[8rem]`,children:[(0,Q.jsx)(la,{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)(ua,{})}),(0,Q.jsx)(da,{children:p.map(e=>(0,Q.jsx)(fa,{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)(ca,{value:s??``,onValueChange:e=>l(e.length>0?e:null),className:`z-40 inline-flex h-full min-w-[8rem]`,children:[(0,Q.jsx)(la,{flat:!0,"aria-label":`Tenant`,className:`h-full w-auto px-2 font-mono text-[11px] hover:bg-muted/50`,children:(0,Q.jsx)(ua,{placeholder:`Select tenant…`})}),(0,Q.jsx)(da,{children:i.map(e=>(0,Q.jsx)(fa,{value:e,className:`font-mono text-[11px]`,children:e},e))})]})}):null]})}),(0,Q.jsxs)(`div`,{className:`${Ce} overflow-x-auto`,role:`tablist`,"aria-label":`Query tabs`,children:[v.map(e=>(0,Q.jsxs)(`div`,{className:a(`group/tab flex h-full items-center gap-0.5 border-b-2 px-1`,e.id===b?`border-foreground text-foreground`:`border-transparent text-muted-foreground`),children:[he===e.id?(0,Q.jsx)(`input`,{autoFocus:!0,value:ye,maxLength:48,"aria-label":`Rename query`,"data-slot":`store-query-tab-rename`,onFocus:e=>e.currentTarget.select(),onChange:e=>be(e.target.value),onBlur:()=>ct(e.id,ye),onKeyDown:t=>{t.key===`Enter`&&(t.preventDefault(),ct(e.id,ye)),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,ye.length+1)}ch`}}):(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":e.id===b,title:`Double-click to rename`,"data-slot":`store-query-tab`,onClick:()=>S(e.id),onDoubleClick:t=>{t.preventDefault(),ut(e)},className:`max-w-[12rem] truncate px-1.5 font-mono text-[11px]`,children:e.title}),le.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)(q,{icon:it,className:`size-2.5`})})]},e.id)),(0,Q.jsx)(X,{label:`New query`,className:`flex self-stretch`,children:(0,Q.jsx)(`button`,{type:`button`,"aria-label":`New query`,disabled:v.length>=8,onClick:ot,"data-slot":`store-query-tab-add`,className:ue,children:(0,Q.jsx)(q,{icon:N,className:`size-3.5`})})})]}),(0,Q.jsxs)(`div`,{className:Ce,children:[(0,Q.jsxs)(F,{type:`button`,variant:`ghost`,size:`sm`,className:`h-full rounded-none px-2 text-[11px]`,onClick:()=>We(K?Cr(T):lf(T)),"data-slot":`store-query-prettify`,children:[(0,Q.jsx)(q,{icon:re,"data-icon":`inline-start`,className:`size-3.5`}),`Prettify`]}),(0,Q.jsx)(X,{label:fe?`Saved`:`Save`,keys:Le,className:`flex self-stretch`,children:(0,Q.jsxs)(F,{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)(q,{icon:fe?ve:ge,"data-icon":`inline-start`,className:`size-3.5`}),fe?`Saved`:`Save`]})}),(0,Q.jsx)(ip,{entries:se,saved:le,onPick:e=>{We(e.text),ke.current?.focus()},onPickSaved:e=>{ft(e),ke.current?.focus()}}),(0,Q.jsxs)(F,{type:`button`,variant:`ghost`,size:`sm`,className:a(`h-full rounded-none px-2 text-[11px]`,z&&`text-foreground`),"aria-pressed":z,onClick:()=>B(e=>!e),"data-slot":`store-query-schema`,children:[(0,Q.jsx)(q,{icon:ae,"data-icon":`inline-start`,className:`size-3.5`}),K?`Schema`:`Keys`]}),K?(0,Q.jsx)(X,{label:V?`PII hidden. Click to include cleartext (audited).`:`PII included. Click to remask.`,className:`flex self-stretch`,children:(0,Q.jsxs)(F,{type:`button`,variant:`ghost`,size:`sm`,className:a(`h-full rounded-none px-2 text-[11px]`,!V&&`text-amber-800 dark:text-amber-300`),"aria-pressed":!V,"aria-label":V?`Include PII: disabled`:`Include PII: enabled`,onClick:()=>{let e=!V;te(e),A&&!Pr(A)&&Xe(A,!e)},"data-slot":`store-query-pii`,children:[(0,Q.jsx)(q,{icon:V?W:pe,"data-icon":`inline-start`,className:`size-3.5`}),`PII`]})}):null,K?(0,Q.jsx)(Yf,{manifest:u,asGate:H,onChange:e=>{ne(e),A&&!Pr(A)&&Xe(A,!V,e)}}):null,Ue?(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)(q,{icon:De,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)(X,{label:Ve?`Run selection`:`Run`,keys:Ie,className:`flex self-stretch`,children:(0,Q.jsxs)(F,{type:`button`,size:`sm`,className:`h-full gap-1.5 rounded-none`,disabled:!g||mt,onClick:Ze,"data-slot":`store-query-run`,children:[mt?(0,Q.jsx)(q,{icon:c,className:`size-3.5 animate-spin`}):(0,Q.jsx)(q,{icon:x,className:`size-3.5`}),Ve?`Run selection`:`Run`,(0,Q.jsx)(Ke,{keys:Ie,className:`hidden sm:inline-flex`})]})}),K?(0,Q.jsxs)(sn,{children:[(0,Q.jsx)(Gt,{render:e=>(0,Q.jsx)(F,{...e,type:`button`,size:`sm`,className:`h-full rounded-none border-l border-primary-foreground/20 px-1.5`,disabled:!g||mt,"aria-label":`More run options`,"data-slot":`store-query-run-menu`,children:(0,Q.jsx)(q,{icon:C,className:`size-3.5`})})}),(0,Q.jsxs)(tn,{align:`end`,className:`w-56`,children:[(0,Q.jsxs)(en,{children:[(0,Q.jsxs)(Jt,{onClick:Ze,children:[`Run current`,(0,Q.jsx)(qt,{children:(0,Q.jsx)(Ke,{keys:Ie})})]}),(0,Q.jsxs)(Jt,{onClick:Qe,disabled:ze.length<2,children:[`Run all`,(0,Q.jsx)(qt,{children:(0,Q.jsx)(Ke,{keys:ht})})]})]}),(0,Q.jsx)(dn,{}),(0,Q.jsxs)(en,{children:[(0,Q.jsx)(Jt,{onClick:()=>$e(!1),children:`EXPLAIN`}),(0,Q.jsx)(Jt,{onClick:()=>$e(!0),children:`EXPLAIN ANALYZE`})]})]})]}):null]})]}),(0,Q.jsxs)(ir,{orientation:`vertical`,className:`min-h-0 flex-1`,children:[(0,Q.jsx)(sr,{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)(jr,{value:T,onChange:We,language:K?`sql`:`kv`,onRun:Ze,onRunAll:K?Qe:void 0,onRunLine:K?tt:void 0,runLines:Be,onCursorChange:(e,t)=>Se({start:e,end:t}),editorRef:ke,label:K?`SQL query`:`KV command`,tables:Re,facet:e}),z?(0,Q.jsx)(Xf,{store:g,facet:e,manifest:u,tenant:s,tenancyDeclared:r,onPickTable:at,onPickColumn:(e,t)=>{ke.current?.insert(K?`"${t}"`:t)},onCollapse:()=>B(!1)}):(0,Q.jsx)($f,{facet:e,onExpand:()=>B(!0)})]})}),ie?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(ur,{withHandle:!0,className:`justify-end pr-8`}),(0,Q.jsx)(sr,{defaultSize:`28%`,minSize:`20%`,className:`min-h-0 overflow-hidden`,children:(0,Q.jsx)(Qr,{rows:E,error:P,pending:mt,meta:O,executed:A,executedLanguage:K?`sql`:`kv`,storeRef:g?.ref,sets:U,activeSet:Te,onSelectSet:e=>Je(U,e),onToggleCollapse:()=>oe(!1)})})]}):null]}),ie?null:(0,Q.jsx)(Qr,{rows:E,error:P,pending:mt,meta:O,executed:A,executedLanguage:K?`sql`:`kv`,storeRef:g?.ref,sets:U,activeSet:Te,onSelectSet:e=>Je(U,e),collapsed:!0,onToggleCollapse:()=>oe(!0)})]})}function tp(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 np(e){if(e.length!==1)return null;let t=e[0]?.changes;return typeof t==`number`&&Number.isFinite(t)?t:null}function rp(e,t,n){if(!e)return t===`sql`?Iu():Lu();let r=(n?e.children.find(e=>e.effectRef===n)?.name:void 0)??zu(e);return t===`sql`?Iu(r):Lu(r?`${r}:`:void 0)}function ip({entries:e,saved:t,onPick:n,onPickSaved:r}){return(0,Q.jsxs)(sn,{children:[(0,Q.jsx)(Gt,{render:e=>(0,Q.jsxs)(F,{...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)(q,{icon:z,"data-icon":`inline-start`,className:`size-3.5`}),`History`]})}),(0,Q.jsxs)(tn,{align:`start`,className:`w-80`,children:[(0,Q.jsxs)(en,{children:[(0,Q.jsx)(un,{className:`font-mono text-[10px] tracking-[0.12em] uppercase`,children:`Saved`}),(0,Q.jsx)(dn,{}),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)(Jt,{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:Hd(e.text)})]},e.id))]}),(0,Q.jsx)(dn,{}),(0,Q.jsxs)(en,{children:[(0,Q.jsx)(un,{className:`font-mono text-[10px] tracking-[0.12em] uppercase`,children:`Recent runs`}),(0,Q.jsx)(dn,{}),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)(Jt,{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:Hd(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 ap=`#38BDF8`,op=[`#38BDF8`,`#34D399`,`#FBBF24`,`#A78BFA`,`#FB7185`,`#22D3EE`,`#F472B6`,`#4ADE80`,`#F59E0B`,`#818CF8`];function sp(e){let t=new Set(e.map(e=>e.name)),n=new Map;for(let r of e)n.set(r.name,fp(r,t));return n}function cp(e){let t=sp(e),n=[...new Set(t.values())].sort(),r=new Map;for(let[e,t]of n.entries())r.set(t,op[e]??_p(t));let i=new Map;for(let n of e){let e=t.get(n.name)??gp(n.name);i.set(n.id,{cluster:e,hex:r.get(e)??`#38BDF8`})}return i}function lp(e,t){let n=t?cp(e.tables):new Map(e.tables.map(e=>[e.id,{cluster:`schema`,hex:ap}])),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=>up(e,n.get(e.id),r)),edges:e.edges.map(e=>dp(e,n.get(e.target)))}}function up(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 dp(e,t){let n=t?.hex??`#38BDF8`,r=e.data?.inferred===!0;return{...e,markerEnd:{type:pt.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 fp(e,t){let n=pp(e.name,t);if(n)return n;if(mp(e.name,t))return gp(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 pp(e,t)??gp(e)}return gp(e.name)}function pp(e,t){let n=e.split(`_`)[0];if(!n||n===e)return null;for(let r of[n,`${n}s`,hp(n)])if(t.has(r)&&r!==e)return gp(r);return null}function mp(e,t){let n=gp(e);for(let r of t)if(r!==e&&pp(r,t)===n)return!0;return!1}function hp(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 gp(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 _p(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 vp={"many-to-one":`Many-to-one`,"one-to-one":`One-to-one`,"many-to-many":`Many-to-many`,self:`Self`};function yp({kind:e,className:t,hex:n}){return(0,Q.jsx)(`svg`,{viewBox:`0 0 24 24`,className:a(`size-3.5 shrink-0`,!n&&`text-muted-foreground`,t),style:n?{color:n}:void 0,"aria-label":vp[e],fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,Q.jsx)(bp,{kind:e})})}function bp({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 xp({id:e,sourceX:t,sourceY:n,targetX:r,targetY:i,sourcePosition:a,targetPosition:o,style:s,markerEnd:c,data:l}){let[d,f,p]=gt({sourceX:t,sourceY:n,sourcePosition:a,targetX:r,targetY:i,targetPosition:o}),m=l?.relation??`many-to-one`,h=l?.column??``,g=`${l?.inferred===!0?`Inferred`:`Declared`} ${Cf(m,h)}`;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_t,{id:e,path:d,markerEnd:c,style:s}),(0,Q.jsx)(mt,{children:(0,Q.jsx)(`div`,{className:`nodrag nopan pointer-events-auto absolute`,style:{transform:`translate(-50%, -50%) translate(${f}px,${p}px)`,opacity:typeof s?.opacity==`number`?s.opacity:1},children:(0,Q.jsxs)(T,{children:[(0,Q.jsx)(b,{render:e=>(0,Q.jsx)(`span`,{...e,"aria-label":g,className:`flex items-center justify-center rounded-sm border border-border/60 bg-background/90 p-0.5 shadow-sm`,children:(0,Q.jsx)(yp,{kind:m,hex:l?.hex})})}),(0,Q.jsx)(u,{side:`top`,className:`text-[11px]`,children:g})]})})})]})}var Sp={relation:xp};function Cp({data:e}){let{table:t,showStore:n,dimmed:r,selected:i,color:o,refHex:s}=e,c=o?.hex??`#38BDF8`;return(0,Q.jsxs)(`div`,{"data-slot":`store-schema-table`,"data-table":t.name,"data-cluster":o?.cluster,className:a(`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?c:`color-mix(in oklab, ${c} 42%, var(--border))`,boxShadow:i?`0 0 0 2px color-mix(in oklab, ${c} 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, ${c} 22%, var(--card))`,borderColor:`color-mix(in oklab, ${c} 28%, var(--border))`},children:[(0,Q.jsx)(`span`,{className:`size-2 shrink-0 rounded-full`,style:{background:c},"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate font-semibold text-foreground`,children:t.name}),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)(wp,{column:e,tableName:t.name,junction:Tp(t.columns),tableHex:c,refHex:s?.[e.name]},e.name))})]})}function wp({column:e,tableName:t,junction:n,tableHex:r,refHex:i}){let o=i??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)(ut,{type:`target`,position:yt.Left,id:`in:${e.name}`,className:`!size-1.5 !border-0`,style:{background:r}}),(0,Q.jsx)(`span`,{className:a(`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)(pi,{primaryKey:e.primaryKey,foreignKey:e.references!==void 0,unique:e.unique,inferred:e.inferredRef,hex:o}),(0,Q.jsx)(`span`,{className:a(`min-w-0 truncate font-mono text-[10px]`,!i&&`text-foreground`),style:i?{color:i}:void 0,title:Dp(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:Dp(e,t,n),children:[(0,Q.jsx)(yp,{kind:Ep(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:a(`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)(ut,{type:`source`,position:yt.Right,id:`out:${e.name}`,className:`!size-1.5 !border-0`,style:{background:o}})]})}function Tp(e){return e.filter(e=>e.references?.table).length<2?!1:e.every(e=>e.primaryKey===!0||e.references!==void 0)}function Ep(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 Dp(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`:Cf(Ep(e,t,n),e.name);return`${e.inferredRef?`Inferred`:`Declared`} ${i} → ${r}`}var Op={table:Cp};function kp(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)(xt,{children:(0,Q.jsx)(Ap,{...e})})})}function Ap({stores:e,manifest:t,selectedEffectRef:n,onSelectTable:r,leading:i}){let{fitView:o}=ft(),{theme:s}=Ut(),c=It(),[l,u]=(0,Z.useState)(``),[d,f]=(0,Z.useState)(0),[p,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(!0),[_,v]=(0,Z.useState)(!0),y=s===`system`?window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`:s,b=(0,Z.useMemo)(()=>wf(e,t),[e,t]),x=(0,Z.useMemo)(()=>lp(Tf(b),h),[b,h]),[S,C,w]=Ct([...x.nodes]),[T,E,D]=ht([...x.edges]);(0,Z.useEffect)(()=>{C(Df(x.nodes,l,n,x.edges,_)),E(Of(x.edges,n,_,c!==!0))},[x,_,d,l,c,n,E,C]),(0,Z.useEffect)(()=>{let e=window.setTimeout(()=>{o({padding:.18,duration:240})},40);return()=>window.clearTimeout(e)},[o,d,b.length]);let O=(0,Z.useCallback)(async()=>{let e=kf(b);if(e.length!==0)try{await navigator.clipboard.writeText(e),m(!0),window.setTimeout(()=>m(!1),1400)}catch{m(!1)}},[b]);return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,Q.jsxs)(`div`,{className:de,"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:a(et,`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)(mr,{value:l,onChange:e=>u(e.target.value),placeholder:`Find table…`,"aria-label":`Find table`,"data-slot":`store-schema-find`}),(0,Q.jsxs)(`span`,{className:a(Me,`flex items-center px-2`),children:[b.length,` `,b.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)($t,{active:h,"aria-pressed":h,onClick:()=>g(e=>!e),className:`h-full`,"data-slot":`store-schema-colorize`,children:[(0,Q.jsx)(q,{icon:ne,className:`size-3`,"aria-hidden":!0}),`Colorize`]}),(0,Q.jsxs)($t,{active:p,disabled:b.length===0,onClick:()=>void O(),className:`h-full disabled:pointer-events-none disabled:opacity-40`,"data-slot":`store-schema-copy-sql`,children:[(0,Q.jsx)(q,{icon:p?ve:Be,className:`size-3`,"aria-hidden":!0}),p?`Copied`:`Copy as SQL`]}),(0,Q.jsx)($t,{active:!1,disabled:b.length===0,onClick:()=>f(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:[b.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)(dt,{nodes:S,edges:T,nodeTypes:Op,edgeTypes:Sp,onNodesChange:w,onEdgesChange:D,colorMode:y,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)=>{v(!0),r(t.id)},onPaneClick:()=>v(!1),"data-slot":`store-schema-canvas`,children:[(0,Q.jsx)(St,{gap:24,size:1,color:`color-mix(in oklab, var(--foreground) 14%, transparent)`}),(0,Q.jsx)(bt,{showInteractive:!1}),(0,Q.jsx)(vt,{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)(mi,{kind:`pk`}),`primary`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(mi,{kind:`fk`}),`foreign`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(mi,{kind:`unique`}),`unique`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(yp,{kind:`many-to-one`}),`many`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(yp,{kind:`one-to-one`}),`one`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(yp,{kind:`many-to-many`}),`join`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(yp,{kind:`self`}),`self`]}),(0,Q.jsx)(`span`,{children:`dashed = inferred`}),(0,Q.jsx)(`span`,{children:`filled = not null`})]})})]})]})}function jp(){let e=Or(),t=gr(),n=br();hr(!0);let{selectedResource:r,selectedTenant:i,queryFacet:a,schemaView:o,performanceView:s,performanceFacet:c,setSelectedResource:l,setSelectedTenant:u,setQueryFacet:d,setSchemaView:f,setPerformanceView:p}=kt(),m=nr(),h=(0,Q.jsx)(rr,{open:m.open,onToggle:m.toggle,noun:`store`,controlsId:`store-tree`,dataSlot:`store-tree-toggle`}),g=e.data?.stores??[],_=r??Xi(g),v=(0,Z.useMemo)(()=>_?Ui(g,_):null,[g,_]);return(0,Q.jsx)(`div`,{className:me,"data-slot":`store-page`,children:(0,Q.jsxs)(ir,{orientation:`horizontal`,className:`min-h-0 flex-1`,children:[(0,Q.jsx)(sr,{panelRef:m.panelRef,collapsible:!0,collapsedSize:0,defaultSize:Ae.start.defaultSize,minSize:Ae.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)(bu,{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)(ur,{withHandle:!0}):null,(0,Q.jsx)(sr,{defaultSize:Ae.end.defaultSize,minSize:Ae.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)(kp,{stores:g,manifest:t.data??null,selectedEffectRef:_,onSelectTable:e=>l(e,{keepView:!0}),leading:h}):s?(0,Q.jsx)(sd,{stores:g,selectedEffectRef:_,tenant:i,facet:c??`sql`,leading:h}):a?(0,Q.jsx)(ep,{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)(gu,{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)(ui,{leading:h,icon:tr.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{jp as StorePage};