okengine 0.15.2 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/site/content/docs/elements/flow.mdx +6 -0
- package/site/content/docs/elements/gate.mdx +55 -0
- package/site/content/docs/elements/store.mdx +13 -15
- package/site/content/docs/elements/vault.mdx +3 -0
- package/site/content/docs/reference/client.mdx +3 -0
- package/site/content/docs/reference/fx.mdx +29 -18
- package/site/content/docs/reference/security.md +1 -1
- package/src/auth/api-key-sql.test.ts +47 -0
- package/src/auth/api-key-sql.ts +254 -0
- package/src/auth/api-keys.ts +273 -14
- package/src/auth/auth.test.ts +56 -0
- package/src/auth/config.ts +5 -5
- package/src/auth/index.ts +25 -1
- package/src/auth/schema.ts +8 -0
- package/src/cli/attach-host-console.test.ts +37 -0
- package/src/cli/attach-host-console.ts +6 -0
- package/src/compiler/effects-infer.ts +17 -2
- package/src/console/server/access.test.ts +116 -8
- package/src/console/server/access.ts +70 -23
- package/src/console/server/app.ts +1 -0
- package/src/console/server/dev-identities.test.ts +127 -0
- package/src/console/server/dev-identities.ts +229 -0
- package/src/console/server/flows-invoke.test.ts +21 -4
- package/src/console/server/flows.ts +113 -58
- package/src/console/server/gates.test.ts +24 -0
- package/src/console/server/gates.ts +8 -21
- package/src/console/server/index.ts +1 -0
- package/src/console/server/live.test.ts +26 -1
- package/src/console/server/live.ts +4 -2
- package/src/console/server/operator-db.ts +2 -0
- package/src/console/server/state.ts +29 -55
- package/src/console/ui-next/dist/assets/access-page-CAGHrA9H.js +4 -0
- package/src/console/ui-next/dist/assets/{agent-disclosure-C0X1fbWF.js → agent-disclosure-BP0Y0Sux.js} +1 -1
- package/src/console/ui-next/dist/assets/cache-glyph-B5X-NM0-.js +1 -0
- package/src/console/ui-next/dist/assets/call-pii-button-ChAUiLo9.js +1 -0
- package/src/console/ui-next/dist/assets/collapsible-DGnOM2ph.js +1 -0
- package/src/console/ui-next/dist/assets/copy-inline-button-DBHhgHKP.js +1 -0
- package/src/console/ui-next/dist/assets/detail-header-DhHM1iaZ.js +1 -0
- package/src/console/ui-next/dist/assets/dropdown-menu-_NjTEo5_.js +1 -0
- package/src/console/ui-next/dist/assets/element-icons-BVXtRyd3.js +1 -0
- package/src/console/ui-next/dist/assets/explorer-empty-2uIhBu0_.js +1 -0
- package/src/console/ui-next/dist/assets/flows-page-B-OUtiAu.js +1 -0
- package/src/console/ui-next/dist/assets/{highlighted-json-CS_O8L-r.js → highlighted-json-Awq7gYdu.js} +1 -1
- package/src/console/ui-next/dist/assets/http-method-_UHM2ODJ.js +1 -0
- package/src/console/ui-next/dist/assets/index-CGoZkILK.js +66 -0
- package/src/console/ui-next/dist/assets/index-Ck88Jmv8.css +2 -0
- package/src/console/ui-next/dist/assets/link-BX6Vqztd.js +1 -0
- package/src/console/ui-next/dist/assets/observability-page-BDyXalNR.js +4 -0
- package/src/console/ui-next/dist/assets/replica-lag-DKRrbvdo.js +18 -0
- package/src/console/ui-next/dist/assets/request-meta-DV0ywz7t.js +1 -0
- package/src/console/ui-next/dist/assets/shortcut-JQIZlWfm.js +1 -0
- package/src/console/ui-next/dist/assets/shortcut-keys-DKxNTe_m.js +1 -0
- package/src/console/ui-next/dist/assets/skeleton-D-czQJT6.js +1 -0
- package/src/console/ui-next/dist/assets/store-page-Xh8Kn3rx.js +41 -0
- package/src/console/ui-next/dist/assets/trace-detail-sheet-B09O8rA6.js +2 -0
- package/src/console/ui-next/dist/assets/tree-expand-toggle-DkOXA12R.js +54 -0
- package/src/console/ui-next/dist/assets/units-page-Dpk40kOQ.js +1 -0
- package/src/console/ui-next/dist/assets/{use-vault-list-BLbZhzyF.js → use-vault-list-uk4WVboC.js} +1 -1
- package/src/console/ui-next/dist/assets/useMutation-B8EO02Ej.js +1 -0
- package/src/console/ui-next/dist/assets/useRender-BE2A9BWC.js +1 -0
- package/src/console/ui-next/dist/assets/vault-page-B1dB9Ft0.js +2 -0
- package/src/console/ui-next/dist/index.html +11 -9
- package/src/console/ui-next/index.html +3 -3
- package/src/console/ui-next/src/client.ts +167 -0
- package/src/console/ui-next/src/components/shell/app-sidebar.tsx +2 -0
- package/src/console/ui-next/src/components/shell/command-items.test.ts +1 -0
- package/src/console/ui-next/src/components/shell/command-items.ts +8 -0
- package/src/console/ui-next/src/components/shell/shell-layout.tsx +2 -1
- package/src/console/ui-next/src/components/ui/sheet-form.tsx +8 -3
- package/src/console/ui-next/src/features/access/access-page.tsx +347 -0
- package/src/console/ui-next/src/features/access/data/use-access.ts +23 -0
- package/src/console/ui-next/src/features/access/detail/access-detail.tsx +552 -0
- package/src/console/ui-next/src/features/access/explorer/access-list.tsx +125 -0
- package/src/console/ui-next/src/features/access/lib/format-when.test.ts +139 -0
- package/src/console/ui-next/src/features/access/lib/format-when.ts +296 -0
- package/src/console/ui-next/src/features/access/lib/scope-groups.test.ts +34 -0
- package/src/console/ui-next/src/features/access/lib/scope-groups.ts +40 -0
- package/src/console/ui-next/src/features/access/sheets/access-allow-fields.tsx +236 -0
- package/src/console/ui-next/src/features/access/sheets/access-create-sheet.tsx +316 -0
- package/src/console/ui-next/src/features/access/sheets/access-edit-sheet.tsx +240 -0
- package/src/console/ui-next/src/features/access/sheets/access-expiry-fields.tsx +66 -0
- package/src/console/ui-next/src/features/access/sheets/access-refresh-sheet.tsx +104 -0
- package/src/console/ui-next/src/features/access/sheets/access-scope-field.tsx +115 -0
- package/src/console/ui-next/src/features/access/sheets/access-secret-sheet.tsx +89 -0
- package/src/console/ui-next/src/features/access/sheets/access-sheet-search.tsx +49 -0
- package/src/console/ui-next/src/features/access/state/access-selection.ts +84 -0
- package/src/console/ui-next/src/features/auth/auth-redirect.test.ts +5 -0
- package/src/console/ui-next/src/features/auth/auth-redirect.ts +18 -2
- package/src/console/ui-next/src/features/not-found/not-found-page.tsx +1 -1
- package/src/console/ui-next/src/lib/document-meta.test.ts +1 -0
- package/src/console/ui-next/src/lib/document-meta.ts +2 -1
- package/src/console/ui-next/src/lib/last-module-search.test.ts +1 -0
- package/src/console/ui-next/src/lib/last-module-search.ts +2 -1
- package/src/console/ui-next/src/lib/shortcut.test.ts +2 -0
- package/src/console/ui-next/src/lib/shortcut.ts +3 -0
- package/src/console/ui-next/src/router.tsx +10 -1
- package/src/console/ui-next/ui-next-seed-app-schema.ts +88 -37
- package/src/console/ui-next/ui-next-seed-store.ts +43 -15
- package/src/console/xss.gate.test.ts +1 -0
- package/src/elements/gate/declare.ts +2 -0
- package/src/elements/store/cache.ts +1 -1
- package/src/elements/store/runtime.ts +14 -0
- package/src/elements/store/schema-decl.ts +99 -41
- package/src/elements/store/sql-select.types.test.ts +71 -0
- package/src/elements/store/sql-session.ts +54 -32
- package/src/elements/store.ts +3 -0
- package/src/index.ts +1 -0
- package/src/kernel/api-key-host-persist.test.ts +143 -0
- package/src/kernel/app.ts +14 -2
- package/src/kernel/auth-resolve.ts +10 -5
- package/src/kernel/boot.test.ts +4 -4
- package/src/kernel/fx-auth-keys.test.ts +88 -0
- package/src/kernel/fx-auth-keys.ts +198 -0
- package/src/kernel/fx.test.ts +17 -1
- package/src/kernel/fx.ts +36 -18
- package/src/kernel/pipeline-api-key.test.ts +192 -7
- package/src/kernel/pipeline.ts +4 -2
- package/src/manifest/types.ts +9 -3
- package/src/release/build-lib.ts +1 -0
- package/src/console/ui-next/dist/assets/cache-glyph-F1FI122b.js +0 -1
- package/src/console/ui-next/dist/assets/call-pii-button-DEDCl_j3.js +0 -1
- package/src/console/ui-next/dist/assets/collapsible-LPqGvfoz.js +0 -1
- package/src/console/ui-next/dist/assets/confirm-sheet-3ptDzXbz.js +0 -1
- package/src/console/ui-next/dist/assets/explorer-empty-BvYrygyO.js +0 -1
- package/src/console/ui-next/dist/assets/flows-page-Dluo1Bd7.js +0 -1
- package/src/console/ui-next/dist/assets/http-method--sWDdXSB.js +0 -1
- package/src/console/ui-next/dist/assets/index-Ca3HZMVq.js +0 -66
- package/src/console/ui-next/dist/assets/index-UtTDRQpS.css +0 -2
- package/src/console/ui-next/dist/assets/link-COeyggt-.js +0 -1
- package/src/console/ui-next/dist/assets/observability-page-HK9-BO8z.js +0 -4
- package/src/console/ui-next/dist/assets/replica-lag-DBIFFf7d.js +0 -18
- package/src/console/ui-next/dist/assets/sheet-form-Dnwa5oOR.js +0 -1
- package/src/console/ui-next/dist/assets/shortcut-Cgzuv4k1.js +0 -1
- package/src/console/ui-next/dist/assets/shortcut-keys-CoqwEIi0.js +0 -1
- package/src/console/ui-next/dist/assets/skeleton-BHcfDYcb.js +0 -1
- package/src/console/ui-next/dist/assets/store-page-BSohH3wM.js +0 -41
- package/src/console/ui-next/dist/assets/trace-detail-sheet-CFIGRnnA.js +0 -2
- package/src/console/ui-next/dist/assets/tree-expand-toggle-BgLl34w7.js +0 -54
- package/src/console/ui-next/dist/assets/units-page-B0cFE76A.js +0 -1
- package/src/console/ui-next/dist/assets/vault-page-B1SbYe10.js +0 -2
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$i as t,$n as n,$r as r,Ai as i,Ar as a,Ba as o,Bi as s,Br as c,Ci as l,Cr as u,D as d,Di as f,Dr as p,Eo as m,F as h,Fi as g,Fr as _,Ga as v,Gr as y,Ha as b,Hi as x,Hr as S,I as C,Ii as w,Ir as T,Ja as E,Ji as D,Jr as O,Ka as k,Li as A,Lr as j,Nr as M,Nt as N,Oo as P,Pi as F,Qn as ee,Qr as I,R as L,Ri as R,Rr as te,S as z,Sr as B,Ti as V,Tr as H,Ui as ne,Va as re,Vi as U,Wa as ie,Wr as ae,Ya as oe,Zi as se,_i as ce,a as le,ai as ue,ar as de,bi as fe,c as pe,ci as me,cr as W,dr as he,ei as ge,er as _e,fa as ve,fi as ye,fr as be,gi as xe,gr as Se,ha as Ce,hr as we,i as Te,ia as Ee,ir as De,l as Oe,la as ke,lr as G,ma as Ae,mi as je,na as Me,nr as Ne,o as K,oa as q,oi as Pe,or as Fe,pa as Ie,qa as Le,qi as Re,ri as ze,rr as Be,s as Ve,sa as He,si as Ue,sr as We,t as Ge,ta as Ke,tr as qe,u as Je,ua as Ye,ur as Xe,vi as Ze,vr as Qe,wr as J,x as $e,xr as et,yr as tt,za as nt,zi as rt,zr as it}from"./shortcut-keys-CoqwEIi0.js";import{t as at,x as ot}from"./link-COeyggt-.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{n as wt,t as Tt}from"./skeleton-BHcfDYcb.js";import{B as Et,G as Dt,H as Ot,R as kt,U as At,V as jt,W as Mt,_ as Nt,i as Pt,k as Ft,n as It,t as Lt,z as Rt}from"./react-D8E3mtu1.js";import{a as zt,i as Bt,n as Vt,r as Ht}from"./duration-tone-sC3lGABz.js";import{r as Ut}from"./preload-helper-oH4irX4C.js";import{C as Wt,M as Gt,S as Kt,_ as qt,a as Jt,b as Yt,c as Xt,d as Zt,f as Qt,g as $t,h as en,i as tn,k as nn,m as rn,n as an,o as on,p as sn,r as cn,s as Y,t as X,u as ln,v as un,x as dn,y as fn}from"./sheet-form-Dnwa5oOR.js";import{$ as pn,A as mn,B as hn,C as gn,D as _n,E as vn,F as yn,G as bn,H as xn,I as Sn,J as Cn,K as wn,L as Tn,M as En,N as Dn,O as On,P as kn,Q as An,R as jn,S as Mn,T as Nn,U as Pn,V as Fn,W as In,X as Ln,Y as Rn,Z as zn,_ as Bn,a as Vn,at as Hn,b as Un,c as Wn,ct as Gn,et as Kn,f as qn,g as Jn,h as Yn,i as Xn,it as Zn,j as Qn,k as $n,l as er,m as tr,n as nr,nt as rr,o as ir,ot as ar,q as or,r as sr,rt as cr,s as lr,st as ur,t as dr,tt as fr,u as pr,v as mr,w as hr,x as gr,y as _r,z as vr}from"./tree-expand-toggle-BgLl34w7.js";import{a as yr,i as br}from"./shortcut-Cgzuv4k1.js";import{_ as xr,a as Sr,c as Cr,d as wr,f as Tr,g as Er,h as Dr,i as Or,l as kr,m as Ar,n as jr,o as Mr,p as Nr,r as Pr,s as Fr,t as Ir,u as Lr}from"./collapsible-LPqGvfoz.js";import{a as Rr,c as zr,i as Br,n as Vr,r as Hr,s as Ur,t as Wr}from"./highlighted-json-CS_O8L-r.js";import{t as Gr}from"./agent-disclosure-C0X1fbWF.js";import{A as Kr,B as qr,C as Jr,D as Yr,E as Xr,F as Zr,H as Qr,I as $r,L as ei,M as ti,N as ni,O as ri,P as ii,R as ai,S as oi,T as si,V as ci,_ as li,a as ui,b as di,c as fi,d as pi,f as mi,g as hi,h as gi,i as _i,j as vi,k as yi,l as bi,m as xi,n as Si,o as Ci,p as wi,r as Ti,s as Ei,t as Di,u as Oi,v as ki,w as Ai,x as ji,y as Mi,z as Ni}from"./replica-lag-DBIFFf7d.js";import{t as Pi}from"./explorer-empty-BvYrygyO.js";import{a as Fi,i as Ii,o as Li,s as Ri,t as zi}from"./call-pii-button-DEDCl_j3.js";import{n as Bi,t as Vi}from"./confirm-sheet-3ptDzXbz.js";var Hi=e=>!e.isLayoutDirty&&e.willUpdate(!1);function Ui(){let e=new Set,t=new WeakMap,n=()=>e.forEach(Hi);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),Wi=(0,Z.createContext)(null);function Gi(){let e=(0,Z.useRef)(!1);return kt(()=>(e.current=!0,()=>{e.current=!1}),[]),e}function Ki(){let e=Gi(),[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(),qi=e=>e===!0,Ji=e=>qi(e===!0)||e===`id`,Yi=({children:e,id:t,inherit:n=!0})=>{let r=(0,Z.useContext)(Et),i=(0,Z.useContext)(Wi),[a,o]=Ki(),s=(0,Z.useRef)(null),c=r.id||i;s.current===null&&(Ji(n)&&c&&(t=t?c+`-`+t:c),s.current={id:t,group:qi(n)&&r.group||Ui()});let l=(0,Z.useMemo)(()=>({...s.current,forceRender:a}),[o]);return(0,Q.jsx)(Et.Provider,{value:l,children:e})};function Xi({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 Zi=e(st(),1);function Qi({className:e,orientation:t=`horizontal`,...n}){return(0,Q.jsx)(Gt,{"data-slot":`separator`,orientation:t,className:J(`shrink-0 bg-border data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch`,e),...n})}function $i(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 ea(e){return e===`memory`||e===`fs`||e===`s3`?e:`files`}function ta(e){switch(e){case`memory`:return`This process`;case`fs`:return`Local disk`;case`s3`:return`Object store`;default:return`Files driver`}}var na=[`sql`,`kv`,`files`,`index`];function ra(e){return na.includes(e)}var ia={sql:`SQL`,kv:`KV`,files:`Files`,index:`Index`},aa={sql:{icon:r,label:ia.sql,wellClass:`border-emerald-500/35 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`},kv:{icon:fe,label:ia.kv,wellClass:`border-amber-500/35 bg-amber-500/10 text-amber-700 dark:text-amber-400`},files:{icon:ze,label:ia.files,wellClass:`border-sky-500/35 bg-sky-500/10 text-sky-600 dark:text-sky-400`},index:{icon:x,label:ia.index,wellClass:`border-violet-500/35 bg-violet-500/10 text-violet-700 dark:text-violet-400`}};function oa(e){return na.map(t=>({facet:t,label:ia[t],stores:e.filter(e=>e.facet===t).map(e=>({store:e,children:e.children}))})).filter(e=>e.stores.length>0)}function sa(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)||ar(t).toLowerCase().includes(n)||t.effectRef.toLowerCase().includes(n));(e||i.length>0)&&r.push({...t,children:e?t.children:i})}return r}function ca(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 la(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 ua(e,t){return e===t?null:t}function da(e){return`facet:${e}`}function fa(e){return`${e}/tables`}function pa(e,t){let n=t[e];return n===void 0?e.startsWith(`facet:`):n}function ma(e){let t=[];for(let n of e){t.push(da(n.facet));for(let e of n.stores)la(e.store)||(t.push(e.store.ref),e.store.facet===`sql`&&t.push(fa(e.store.ref)))}return t}function ha(e,t){let n=ca(e,t);if(!n)return[];let r=[da(n.store.facet)];return la(n.store)?r:(r.push(n.store.ref),n.store.facet===`sql`&&!Hn(n.child)&&r.push(fa(n.store.ref)),r)}function ga(e){for(let t of na)for(let n of e){if(n.facet!==t)continue;let e=n.children.find(e=>!Hn(e));if(e)return e.effectRef}return null}var _a=`oke_store_hidden_facets`;function va(e){return Array.isArray(e)?new Set(e.filter(e=>typeof e==`string`&&ra(e))):new Set}function ya(){try{if(typeof localStorage>`u`)return new Set;let e=localStorage.getItem(_a);return e?va(JSON.parse(e)):new Set}catch{return new Set}}function ba(e){try{if(typeof localStorage>`u`)return;localStorage.setItem(_a,JSON.stringify([...e]))}catch{}}function xa(e,t){return e.filter(e=>!t.has(e.facet))}var Sa={duration:0},Ca={type:`spring`,duration:.4,bounce:.3},wa={hidden:{},show:{transition:{staggerChildren:.035,delayChildren:.05}}},Ta={hidden:{opacity:0,y:-6,filter:`blur(3px)`},show:{opacity:1,y:0,filter:`blur(0px)`}},Ea=(0,Z.createContext)(null);function Da(e){let t=(0,Z.useContext)(Ea);if(!t)throw Error(`${e} must be used within <Select>`);return t}function Oa({value:e,defaultValue:t,onValueChange:n,disabled:r=!1,className:i,children:a}){let o=It()??!1,s=(0,Z.useId)(),c=(0,Z.useRef)(null),[l,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(t),[p,m]=(0,Z.useState)(()=>new Map),[h,g]=(0,Z.useState)(`bottom`),_=e!==void 0,v=_?e:d,y=(0,Z.useCallback)(e=>{_||f(e),n?.(e),u(!1)},[_,n]),b=(0,Z.useCallback)((e,t)=>{m(n=>n.get(e)===t?n:new Map(n).set(e,t))},[]),x=(0,Z.useCallback)(e=>{m(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]);(0,Z.useEffect)(()=>{if(!l)return;let e=e=>{e.key===`Escape`&&u(!1)},t=e=>{c.current&&!c.current.contains(e.target)&&u(!1)};return window.addEventListener(`keydown`,e),window.addEventListener(`pointerdown`,t),()=>{window.removeEventListener(`keydown`,e),window.removeEventListener(`pointerdown`,t)}},[l]);let S=(0,Z.useMemo)(()=>({value:v,open:l,setOpen:u,select:y,register:b,unregister:x,labelFor:e=>e===void 0?void 0:p.get(e),reduce:o,triggerId:`${s}-trigger`,listId:`${s}-list`,disabled:r,placement:h,setPlacement:g}),[v,l,y,b,x,p,o,s,r,h]);return(0,Q.jsx)(Ea.Provider,{value:S,children:(0,Q.jsx)(`div`,{ref:c,className:J(`relative`,i),"data-slot":`motion-select`,children:a})})}function ka({className:e,children:t,"aria-label":n,flat:r=!1}){let i=Da(`SelectTrigger`),a=i.placement===`top`,o=i.open?[0,0,12]:[12,0,12],s=i.reduce?{duration:0}:i.open?{duration:.6,times:[0,.4,1],ease:jt}:{duration:.42,times:[0,.5,1],ease:jt};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:a?o:12,borderTopRightRadius:a?o:12,borderBottomLeftRadius:a?12:o,borderBottomRightRadius:a?12:o},transition:{borderTopLeftRadius:a?s:Sa,borderTopRightRadius:a?s:Sa,borderBottomLeftRadius:a?Sa:s,borderBottomRightRadius:a?Sa:s},className:J(`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}:Ca,className:`text-muted-foreground`,children:(0,Q.jsx)(H,{icon:M,className:`size-3.5`})})]})}function Aa({placeholder:e,className:t}){let n=Da(`SelectValue`),r=n.labelFor(n.value);return(0,Q.jsx)(`span`,{className:J(r?`text-foreground`:`text-muted-foreground`,t),children:r??e??`Select`})}function ja({className:e,children:t}){let n=Da(`SelectContent`),r=(0,Z.useRef)(null),[i,a]=(0,Z.useState)(0),o=n.open,{setPlacement:s}=n;(0,Z.useLayoutEffect)(()=>{let e=r.current;if(!e)return;let t=()=>a(e.offsetHeight);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()}),(0,Z.useLayoutEffect)(()=>{if(!o)return;let e=document.getElementById(n.triggerId),t=r.current;if(!e||!t)return;let i=e.getBoundingClientRect(),a=t.offsetHeight,c=window.innerHeight-i.bottom,l=i.top;s(c<a+16&&l>c?`top`:`bottom`)},[o,n.triggerId,s]);let c=n.placement===`top`,l=o?8:0,u=o?12:0,d=o?{type:`spring`,duration:.6,bounce:.5,delay:.12}:{type:`spring`,duration:.3,bounce:.1},f=o?{duration:.3,ease:jt,delay:.14}:{duration:.16,ease:jt};return(0,Q.jsx)(Lt.div,{id:n.listId,role:`listbox`,"aria-labelledby":n.triggerId,"aria-hidden":!o,inert:!o,initial:!1,animate:n.reduce?{opacity:+!!o,height:o?i:0}:{opacity:+!!o,height:o?i:0,marginTop:c?0:l,marginBottom:c?l:0,borderTopLeftRadius:c?12:u,borderTopRightRadius:c?12:u,borderBottomLeftRadius:c?u:12,borderBottomRightRadius:c?u:12},transition:n.reduce?{duration:.12}:{opacity:o?{duration:.18}:{duration:.16,delay:.12},height:o?{type:`spring`,duration:.42,bounce:.14}:{duration:.26,ease:jt,delay:.14},marginTop:c?Sa:d,marginBottom:c?d:Sa,borderTopLeftRadius:c?Sa:f,borderTopRightRadius:c?Sa:f,borderBottomLeftRadius:c?f:Sa,borderBottomRightRadius:c?f:Sa},style:{transformOrigin:c?`bottom`:`top`,overflow:`hidden`,pointerEvents:o?`auto`:`none`},className:J(`absolute right-0 left-0 z-20 rounded-xl border border-border bg-background shadow-lg`,c?`bottom-full`:`top-full`,e),children:(0,Q.jsx)(Lt.div,{ref:r,variants:n.reduce?void 0:wa,initial:!1,animate:o?`show`:`hidden`,className:`p-1`,children:t})})}function Ma({value:e,disabled:t=!1,className:n,children:r}){let i=Da(`SelectItem`),a=i.value===e,o=typeof r==`string`?r:e,s=i.register,c=i.unregister;return(0,Z.useLayoutEffect)(()=>(s(e,o),()=>c(e)),[s,c,e,o]),(0,Q.jsx)(Lt.li,{variants:i.reduce?void 0:Ta,children:(0,Q.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":a,disabled:t,onClick:()=>i.select(e),className:J(`flex w-full items-center justify-between gap-2 rounded-lg px-2.5 py-1.5 text-left text-sm outline-none transition-colors`,a?`bg-muted text-foreground`:`text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:bg-muted`,`disabled:pointer-events-none disabled:opacity-50`,n),children:[r,a?(0,Q.jsx)(H,{icon:Ke,className:`size-3.5 shrink-0`,"aria-hidden":!0}):null]})})}function Na(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 Pa(){let e=P();return ot({mutationFn:async e=>{let t=await o(e),n=Na(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:fr}),e.invalidateQueries({queryKey:ci})])}})}function Fa(){let e=P();return ot({mutationFn:async e=>{let t=await nt(e),n=Na(t);if(n)throw n;if(!t.data)throw Error(`Empty store delete`);return t.data},onSuccess:async()=>{await Promise.all([e.invalidateQueries({queryKey:fr}),e.invalidateQueries({queryKey:ci})])}})}var Ia={type:`spring`,stiffness:800,damping:80,mass:4};function La({checked:e,onCheckedChange:t,disabled:n,label:r,ariaLabel:i,className:a,size:o=`default`}){let s=(0,Z.useId)(),c=(0,Z.useRef)(null),l=It(),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(!1),m=o===`sm`;(0,Z.useEffect)(()=>{!c.current||l||n&&u&&Bt(c.current,{x:[0,-2,2,-1,0]},{delay:.2,duration:.6})},[n,u,l]);let h=!n&&f&&u&&!l;return(0,Q.jsx)(Xi,{transition:l?{duration:0}:Ia,children:(0,Q.jsxs)(`span`,{className:J(`inline-flex items-center gap-2`,a),children:[(0,Q.jsx)(Lt.button,{id:s,type:`button`,role:`switch`,"aria-checked":e,"aria-label":i,disabled:n,onClick:()=>{n||t(!e)},onPointerDown:()=>{d(!0),p(!0)},onPointerUp:()=>d(!1),onPointerLeave:()=>d(!1),initial:!1,"data-state":e?`checked`:`unchecked`,className:J(`group peer inline-flex shrink-0 cursor-pointer items-center rounded-full outline-none transition-colors duration-200`,`focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background`,`disabled:cursor-not-allowed disabled:opacity-60`,m?`h-4 w-7 px-0.5`:`h-7 w-12 px-1`,e?`justify-end bg-primary`:`justify-start bg-muted-foreground/60`),children:(0,Q.jsx)(Lt.div,{ref:c,layout:!0,animate:{scale:h?.9:1},className:J(`pointer-events-none block rounded-full bg-background shadow-md`,m?`h-3 w-3`:`h-5 w-5`),children:(0,Q.jsx)(`div`,{className:J(m?`size-3`:`size-5`,h&&(e?`ml-1`:`mr-1`)),"aria-hidden":!0})})}),r?(0,Q.jsx)(`label`,{htmlFor:s,className:`text-sm`,children:r}):null]})})}function Ra({open:e,extraCount:t=0,onOpenChange:n,controls:r}){return(0,Q.jsxs)(Qt,{active:e||t>0,extraCount:t,"aria-expanded":e,"aria-controls":r,onClick:()=>n(!e),children:[(0,Q.jsx)(H,{icon:me,className:`size-3`,"aria-hidden":!0}),`Advanced`]})}function za({templates:e,selectedId:t,onSelect:n}){let r=e.find(e=>e.id===t)??null;return(0,Q.jsx)(Jt,{label:`Templates`,hint:r?.detail??`Pick a starter, or fill the fields.`,children:e.map(e=>(0,Q.jsx)(tn,{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 Va=[$(`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,...Va];function Ha(e){return/^[0-9]+(\.[0-9]+)*$/.test(e)}var Ua={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 Ga(e){return Ua[e]||e.replace(/^pg_/,``).split(/[_-]+/).filter(e=>e.length>0).map(e=>Wa[e]??e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}var Ka=`https://www.postgresql.org/docs/current`,qa={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`},Ja={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 Ya(e){let t=Ja[e];if(t)return t;let n=qa[e];return n?`${Ka}/${n}.html`:null}var Xa={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 Za(e){return`"${e.replaceAll(`"`,``)}"`}var Qa=Ga,$a=[`timescaledb`,`pg_cron`,`postgis`],eo={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 to(e){return eo[e]}function no(e){let t=new Map(e.map(e=>[e.name,e]));return $a.flatMap(e=>{let n=t.get(e);return n?[n]:[]})}var ro=[`time`,`jobs`,`geo`,`search`,`graph`,`scale`,`security`,`http`,`fdw`,`lang`,`analytics`];function io(e){return[e.name,Qa(e.name),e.comment,e.category,Xa[e.category],...e.tags??[],...e.requires??[]].join(` `).toLowerCase()}function ao(e,t){let n=t.trim().toLowerCase().split(/\s+/).filter(e=>e.length>0);return n.length===0?e:e.filter(e=>{let t=io(e);return n.every(e=>t.includes(e))})}function oo(e){return ro.flatMap(t=>{let n=e.filter(e=>e.category===t);return n.length===0?[]:[{category:t,label:Xa[t],items:n}]})}var so={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 co(e,t){let n=[`CREATE EXTENSION IF NOT EXISTS ${Za(e)}`],r=[],i=t?.schema?.trim()??``;i!==``&&lo(i)&&r.push(`SCHEMA ${Cn(i)}`);let a=t?.version?.trim()??``;return a!==``&&Ha(a)&&r.push(`VERSION '${a}'`),t?.cascade===!0&&r.push(`CASCADE`),r.length>0&&n.push(`WITH ${r.join(` `)}`),`${n.join(` `)};`}function lo(e){let t=e.trim();return wn(t)&&t.toLowerCase()!==`pg_catalog`}function uo(e){return+!!e.schema?.trim()+ +!!e.version?.trim()+ +(e.cascade===!0)}function fo(e,t,n){let r=[...e.requires??[],e.name].map(e=>({name:e,title:Qa(e),already:t.has(e)})),i=r.filter(e=>!e.already),a=i.length>0?i.map(t=>co(t.name,t.name===e.name?n:void 0)).join(`
|
|
2
|
-
`):`-- ${e.name} is already installed`,o=so[e.name];return{items:r,sql:a,...o?{note:o}:{}}}var po={timescaledb:ae,pg_cron:it,postgis:i},mo=[{value:`all`,label:`All`},...ro.map(e=>({value:e,label:Xa[e]}))];function ho({open:e,onOpenChange:t,storeRef:n,presentNames:r}){let i=Pa(),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(`all`),[l,u]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(null),[g,_]=(0,Z.useState)(`extensions`),[v,y]=(0,Z.useState)(!1),[b,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=ao(Va,a);return s===`all`?e:e.filter(e=>e.category===s)},[a,s]),k=s===`all`&&a.trim()===``,A=(0,Z.useMemo)(()=>k?no(Va):[],[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)(()=>oo(j),[j]),N=(0,Z.useMemo)(()=>({...b.trim()===``?{}:{schema:b.trim()},...C.trim()===``?{}:{version:C.trim()},...T?{cascade:!0}:{}}),[b,C,T]),P=(0,Z.useMemo)(()=>m?fo(m,D,N):null,[m,D,N]),F=e=>{D.has(e.name)||(u(null),_(`extensions`),y(!1),S(``),w(``),E(!1),h(e))},ee=async()=>{if(!m||!P)return;let e=P.items.filter(e=>!e.already).map(e=>e.name);if(e.length===0){h(null);return}u(null),p(m.name);try{for(let t of e)await i.mutateAsync({ref:n,child:`extensions`,id:t,patch:{enabled:!0,...t===m.name?N:{}},commit:!0});h(null)}catch(e){u(e instanceof Error?e.message:String(e))}finally{p(null)}};return(0,Q.jsx)(Te,{open:e,onOpenChange:e=>{e||(o(``),c(`all`),u(null),p(null),h(null),_(`extensions`),y(!1),S(``),w(``),E(!1)),t(e)},children:(0,Q.jsx)(K,{side:`right`,showOverlay:!1,className:`gap-0 p-0 data-[side=right]:sm:max-w-3xl`,"data-slot":`extension-library-sheet`,children:m&&P?(0,Q.jsx)(go,{ext:m,plan:P,tab:g,advancedOpen:v,extraCount:uo(N),schema:b,version:C,cascade:T,error:l,pending:f!==null,onTab:_,onAdvanced:y,onSchema:S,onVersion:w,onCascade:E,onBack:()=>{h(null),u(null)},onConfirm:()=>void ee()}):(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)(Je,{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`,a.trim()?` matching “${a.trim()}”`:``]})]}),(0,Q.jsxs)(Ve,{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)(H,{icon:x,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)(d,{value:a,onChange:e=>o(e.target.value),placeholder:`Search packs…`,"aria-label":`Search library`,flat:!0,className:J(an,`font-mono`),autoFocus:!0})]}),(0,Q.jsxs)(Rn,{items:mo,value:s,onValueChange:e=>{e==null||Array.isArray(e)||c(e===`all`?`all`:e)},children:[(0,Q.jsx)(pn,{"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)(Kn,{children:e=>{let t=String(e??`all`),n=t===`all`?`All`:Xa[t];return(0,Q.jsxs)(`span`,{children:[`Category · `,n]})}})}),(0,Q.jsx)(Ln,{align:`end`,alignItemWithTrigger:!1,className:`min-w-44`,children:(0,Q.jsx)(zn,{children:mo.map(e=>(0,Q.jsx)(An,{value:e.value,className:`text-[11px]`,children:e.label},e.value))})})]})]}),l?(0,Q.jsx)(`p`,{className:`border-b border-border/50 px-4 py-2 text-[11px] text-destructive`,role:`alert`,children:l}):null,(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children: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)(yo,{children:`Popular`}),(0,Q.jsx)(`ul`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-3`,children:A.map(e=>(0,Q.jsx)(bo,{ext:e,installed:D.has(e.name),pending:f===e.name,disabled:f!==null,onAdd:()=>F(e)},e.name))})]}):null,M.map(e=>(0,Q.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(yo,{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)(xo,{ext:e,installed:D.has(e.name),pending:f===e.name,disabled:f!==null,onAdd:()=>F(e)},e.name))})]},e.category))]})})]})]})})})}function go({ext:e,plan:t,tab:n,advancedOpen:r,extraCount:i,schema:a,version:o,cascade:c,error:l,pending:u,onTab:f,onAdvanced:p,onSchema:m,onVersion:h,onCascade:g,onBack:v,onConfirm:y}){let b=Qa(e.name),x=e.name===`timescaledb`||e.name===`pg_cron`||e.name===`postgis`?po[e.name]:s;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:v,className:`flex w-fit items-center gap-1 text-[11px] text-muted-foreground hover:text-foreground`,children:[(0,Q.jsx)(H,{icon:_,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)(H,{icon:x,className:`size-4`,"aria-hidden":!0})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(Je,{className:`text-sm`,children:[`Install `,b]}),(0,Q.jsx)(Ve,{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)(_o,{active:n===`extensions`,onClick:()=>f(`extensions`),children:`Extensions`}),(0,Q.jsx)(_o,{active:n===`sql`,onClick:()=>f(`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)(Co,{}):(0,Q.jsx)(Or,{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)(Ra,{open:r,extraCount:i,onOpenChange:p,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)(d,{value:a,onChange:e=>m(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)(d,{value:o,onChange:e=>h(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)(La,{size:`sm`,checked:c,onCheckedChange:g,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)(pe,{children:[(0,Q.jsx)(Xt,{split:!0,onClick:v,children:`Cancel`}),(0,Q.jsx)(Xt,{variant:`default`,disabled:u,"data-slot":`extension-library-install`,"data-name":e.name,onClick:y,children:u?`Installing…`:`Install pack`})]})]})}function _o({active:e,onClick:t,children:n}){return(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":e,onClick:t,className:J(`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 vo({name:e,title:t,className:n}){let r=Ya(e);return r?(0,Q.jsxs)(`a`,{href:r,target:`_blank`,rel:`noreferrer`,className:J(`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)(H,{icon:V,className:`size-3 shrink-0 text-muted-foreground/50 group-hover/ext-link:text-muted-foreground`,"aria-hidden":!0})]}):(0,Q.jsx)(`p`,{className:J(`font-medium tracking-tight text-foreground`,n),children:t})}function yo({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 bo({ext:e,installed:t,pending:n,disabled:r,onAdd:i}){let a=e.name,o=Qa(e.name),s=to(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)(H,{icon:po[a],className:`size-4 text-foreground`,"aria-hidden":!0})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(vo,{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)(So,{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:Xa[e.category]}),s?(0,Q.jsxs)(`p`,{className:`truncate text-[10px] text-muted-foreground/80`,children:[`Built by `,s]}):null]}),(0,Q.jsx)(wo,{installed:t,pending:n,disabled:r,name:e.name,onAdd:i})]})]})}function xo({ext:e,installed:t,pending:n,disabled:r,onAdd:i}){let a=to(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)(vo,{name:e.name,title:Qa(e.name),className:`text-[13px]`}),(0,Q.jsx)(`p`,{className:`font-mono text-[11px] text-muted-foreground`,children:e.name}),(0,Q.jsx)(So,{tags:e.tags})]}),t?(0,Q.jsx)(Co,{}):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:Xa[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)(wo,{installed:!1,pending:n,disabled:r,name:e.name,onAdd:i})]})]})}function So({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 Co(){return(0,Q.jsx)(Or,{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 wo({installed:e,pending:t,disabled:n,name:r,onAdd:i}){return e?(0,Q.jsx)(Co,{}):(0,Q.jsx)(z,{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 To=`github-light`,Eo=`github-dark`;function Do(e){return Vr.includes(e)}var Oo=new Map;function ko(e,t){return`${t}\u0000${e}`}function Ao(){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 jo(e,t){let n=ko(e,t),r=Oo.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`||!Do(t)){a({key:n,code:e,language:t,lines:[]});return}let r=Oo.get(n);if(r){a({key:n,code:e,language:t,lines:r});return}let i=!1;return Hr().then(n=>n.codeToTokensWithThemes(e,{lang:t,themes:{light:To,dark:Eo}})).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})));Oo.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 Mo({code:e,tokens:t,className:n}){let r=Ao();return(0,Q.jsx)(`code`,{className:J(`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 No({code:e,language:t=`bash`,className:n}){let r=jo(e,t),i=0,a=e.split(`
|
|
3
|
-
`).map(e=>{let t={content:e,offset:i};return i+=e.length+1,t});return(0,Q.jsx)(`pre`,{className:J(`m-0 overflow-x-auto whitespace-pre font-mono text-xs leading-5 text-foreground/85`,n),children:a.map((e,t)=>(0,Q.jsxs)(Z.Fragment,{children:[(0,Q.jsx)(Mo,{code:e.content,tokens:r?.[t]}),t<a.length-1?`
|
|
4
|
-
`:null]},`${e.offset}-${e.content}`))})}var Po=[`INSERT`,`UPDATE`,`DELETE`],Fo=[{id:`read`,label:`Read`,icon:ke},{id:`write`,label:`Write`,icon:A},{id:`both`,label:`Both`,icon:ne}];function Io({open:e,onOpenChange:t,storeRef:n,tables:r,manifest:i=null}){let a=Pa(),o=bn(e),[s,u]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(`sql`),[m,h]=(0,Z.useState)(r[0]??``),[g,_]=(0,Z.useState)(``),[v,y]=(0,Z.useState)(`SELECT`),[b,x]=(0,Z.useState)(`PERMISSIVE`),[S,C]=(0,Z.useState)(`true`),[w,T]=(0,Z.useState)(`true`),[E,D]=(0,Z.useState)(!0),[O,k]=(0,Z.useState)(null),[A,j]=(0,Z.useState)(!1),[M,N]=(0,Z.useState)(``),[P,F]=(0,Z.useState)(null),[ee,I]=(0,Z.useState)(!1),[L,R]=(0,Z.useState)(``),[te,z]=(0,Z.useState)([]),[B,V]=(0,Z.useState)(()=>On(`read`)),re=$n(v),U=Dn(v),ie=(0,Z.useMemo)(()=>Sn(i,n,m),[i,n,m]),ae=(0,Z.useMemo)(()=>ie.map(e=>e.sqlName),[ie]),oe=Qn(ae),se=g!==``&&ae.includes(g)?g:oe??``,ce=P!==null&&jn(Mn.find(e=>e.id===P)??{})||U.using&&_n(S)||U.withCheck&&_n(w),ue=ae.length>0&&ce,de=(U.using&&vn(S)||U.withCheck&&vn(w))&&se===``,fe=(0,Z.useMemo)(()=>Yn(mr(i),o.data??null),[i,o.data]),me=(0,Z.useMemo)(()=>({gates:te,actions:B,roles:[]}),[te,B]),W=(0,Z.useMemo)(()=>{try{let e=or({name:s||`policy_name`,table:m||`table`,command:v,behavior:b,roles:`public`,using:U.using?S:``,withCheck:U.withCheck?w:``});return{sql:kn(e,E),code:En(e)}}catch{return null}},[s,m,v,b,U,S,w,E]),he=(e,t)=>t===``?e:hr(e,t),ge=e=>{let t=jn(e)?se:``;F(e.id),u(e.name),y(e.command),x(e.behavior??`PERMISSIVE`),V(t=>Un(t,e.command)),C(he(e.using??`true`,t)),T(he(e.withCheck??`true`,t)),t!==``&&_(t)},_e=e=>{let t=Tn(i,n,e),r=(g!==``&&t.includes(g)?g:null)??Qn(t)??``;h(e),_(r);let a=se||`owner`;C(e=>yn(e,a,r)),T(e=>yn(e,a,r))},ve=e=>{let t=se||`owner`;_(e),C(n=>yn(n,t,e)),T(n=>yn(n,t,e))},ye=e=>{let t=Nn(e,v);y(t),V(On(e)),z([])},be=e=>{y(e),V(t=>Un(t,e))},xe=e=>{z(t=>{let n=t.includes(e)?t.filter(t=>t!==e):[...t,e],r=mn(n);return C(r),T(r),n})},Se=async()=>{if(k(null),de){k(`Pick a column on ${m} that stores the user id.`);return}try{let e=or({name:s,table:m,command:v,behavior:b,roles:`public`,using:U.using?S:``,withCheck:U.withCheck?w:``});await a.mutateAsync({ref:n,child:`policies`,id:`${e.table}:${e.name}`,patch:{create:!0,name:e.name,table:e.table,command:e.command,behavior:e.behavior,roles:e.roles.join(`, `),...e.using===void 0?{}:{using:e.using},...e.withCheck===void 0?{}:{withCheck:e.withCheck},enableRls:E},commit:!0}),t(!1)}catch(e){k(e instanceof Error?e.message:String(e))}};return(0,Q.jsx)(Te,{open:e,onOpenChange:e=>{e||I(!1),t(e)},children:(0,Q.jsxs)(K,{side:`right`,showCloseButton:!1,className:`flex-col gap-0 overflow-hidden rounded-none bg-popover p-0 shadow-lg sm:flex-row sm:items-stretch data-[side=right]:w-auto data-[side=right]:max-w-[calc(100vw-1.5rem)] data-[side=right]:sm:max-w-none`,"data-slot":`rls-policy-sheet`,children:[(0,Q.jsxs)(`div`,{className:`relative flex min-h-0 w-full flex-1 flex-col sm:w-[28rem] sm:flex-none`,"data-slot":`rls-policy-form-sheet`,children:[(0,Q.jsxs)(Oe,{className:`flex-row items-stretch gap-0 border-b border-border/60 p-0`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start gap-3 p-4`,children:[(0,Q.jsx)(`div`,{className:`flex size-9 items-center justify-center rounded-full border border-border/50 bg-muted/20`,children:(0,Q.jsx)(H,{icon:ne,className:`size-4`,"aria-hidden":!0})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(Je,{className:`text-sm`,children:`Create policy`}),(0,Q.jsx)(Ve,{className:`text-[11px]`,children:"Review the `CREATE POLICY` SQL before it runs"})]})]}),(0,Q.jsx)(`span`,{className:`w-px shrink-0 self-stretch bg-border/60`,"aria-hidden":!0}),(0,Q.jsxs)(le,{className:J(Fe,`min-w-11`),"data-slot":`rls-policy-form-close`,"aria-label":`Close`,children:[(0,Q.jsx)(H,{icon:c,className:`size-4`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]}),(0,Q.jsxs)(Dr,{orientation:`vertical`,className:`min-h-0 flex-1`,children:[(0,Q.jsx)(Ar,{defaultSize:`68%`,minSize:`28%`,className:`min-h-0`,children:(0,Q.jsxs)(`div`,{className:`h-full min-h-0 overflow-y-auto`,"data-slot":`rls-policy-form-scroll`,children:[(0,Q.jsxs)(`div`,{className:`border-b border-border/50`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-4 pt-2.5`,children:[(0,Q.jsx)(`p`,{className:`text-[10px] font-semibold tracking-[0.12em] text-muted-foreground uppercase`,children:`Policy name`}),(0,Q.jsxs)(Qt,{active:ee,"aria-expanded":ee,"aria-controls":ee?`rls-policy-templates-sheet`:void 0,onClick:()=>I(e=>!e),children:[(0,Q.jsx)(H,{icon:l,className:`size-3`,"aria-hidden":!0}),`Templates`]})]}),(0,Q.jsx)(d,{value:s,onChange:e=>u(e.target.value),placeholder:`read_all`,"aria-label":`Policy name`,flat:!0,className:J(X,`font-mono`)})]}),(0,Q.jsxs)(ln,{children:[(0,Q.jsx)(Y,{label:`Table`,split:`start`,children:(0,Q.jsxs)(Oa,{value:m,onValueChange:_e,children:[(0,Q.jsx)(ka,{flat:!0,className:J(X,`font-mono`),children:(0,Q.jsx)(Aa,{placeholder:`Select a table`})}),(0,Q.jsx)(ja,{children:r.map(e=>(0,Q.jsx)(Ma,{value:e,className:`font-mono text-[12px]`,children:e},e))})]})}),(0,Q.jsx)(Y,{label:`Behavior`,split:`end`,children:(0,Q.jsxs)(Oa,{value:b,onValueChange:e=>x(e),children:[(0,Q.jsx)(ka,{flat:!0,className:X,children:(0,Q.jsx)(Aa,{})}),(0,Q.jsxs)(ja,{children:[(0,Q.jsx)(Ma,{value:`PERMISSIVE`,children:`Permissive`}),(0,Q.jsx)(Ma,{value:`RESTRICTIVE`,children:`Restrictive`})]})]})})]}),(0,Q.jsx)(cn,{label:`Gate`,hint:`Who this policy pairs with`}),(0,Q.jsx)(zo,{advanced:A,onAdvancedChange:j,mode:re,onModeChange:ye,catalog:fe,query:L,onQueryChange:R,selection:me,onToggleGate:xe}),A||re===`write`?(0,Q.jsx)(Yo,{commands:A?gr:Po,value:v,onChange:be}):null,(0,Q.jsx)(cn,{label:`Rows`,hint:U.using&&U.withCheck?`Existing rows and new rows`:U.withCheck?`New rows`:`Existing rows`}),ue?(0,Q.jsx)(Y,{label:`Column`,hint:`compared to oke.user()`,children:(0,Q.jsxs)(Oa,{value:se,onValueChange:ve,children:[(0,Q.jsx)(ka,{flat:!0,className:J(X,`font-mono`),"data-slot":`rls-identity-column`,children:(0,Q.jsx)(Aa,{placeholder:`Select a column`})}),(0,Q.jsx)(ja,{children:ie.map(e=>(0,Q.jsx)(Ma,{value:e.sqlName,children:(0,Q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(Li,{primaryKey:e.primaryKey,foreignKey:e.foreignKey,unique:e.unique,inferred:e.inferred}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[12px]`,children:e.sqlName})]})},e.sqlName))})]})}):null,U.using?(0,Q.jsx)(Y,{label:`USING`,children:(0,Q.jsx)(d,{value:S,onChange:e=>C(e.target.value),placeholder:`true`,flat:!0,className:J(X,`font-mono`)})}):null,U.withCheck?(0,Q.jsx)(Y,{label:`WITH CHECK`,children:(0,Q.jsx)(d,{value:w,onChange:e=>T(e.target.value),placeholder:`true`,flat:!0,className:J(X,`font-mono`)})}):null]})}),(0,Q.jsx)(Nr,{withHandle:!0,"data-slot":`rls-policy-sql-handle`}),(0,Q.jsx)(Ar,{defaultSize:`32%`,minSize:`16%`,className:`min-h-0`,children:(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-muted/15`,"data-slot":`rls-policy-sql-dock`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 py-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,className:J(`text-[10px] font-semibold tracking-[0.12em] uppercase`,f===`sql`?`text-foreground`:`text-muted-foreground`),onClick:()=>p(`sql`),children:`SQL`}),(0,Q.jsx)(`button`,{type:`button`,className:J(`text-[10px] font-semibold tracking-[0.12em] uppercase`,f===`code`?`text-foreground`:`text-muted-foreground`),onClick:()=>p(`code`),children:`Code`})]}),(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:`Enable RLS`}),(0,Q.jsx)(La,{size:`sm`,checked:E,onCheckedChange:D,ariaLabel:`Enable RLS on this table`})]})]}),W?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 pb-3`,children:(0,Q.jsx)(No,{code:f===`sql`?W.sql:W.code,language:f===`sql`?`sql`:`typescript`,className:`overflow-visible whitespace-pre-wrap break-words text-[11px] leading-relaxed`})}):(0,Q.jsx)(`p`,{className:`min-h-0 flex-1 px-4 pb-3 text-[11px] text-muted-foreground`,children:`Fill name, table, and an expression.`}),de?(0,Q.jsxs)(on,{slot:`rls-owner-missing`,children:[`Pick a column on `,m,` — this table has no owner / owner_email / creator_email guess.`]}):null,O?(0,Q.jsx)(on,{children:O}):null]})})]}),(0,Q.jsxs)(pe,{children:[(0,Q.jsx)(Xt,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(Xt,{variant:`default`,disabled:a.isPending||!W||de,onClick:()=>void Se(),children:a.isPending?`Creating…`:`Create policy`})]})]}),ee?(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)(Ro,{query:M,onQueryChange:N,selectedId:P,onSelect:ge,onClose:()=>I(!1)})}):null]})})}var Lo={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 Ro({query:e,onQueryChange:t,selectedId:n,onSelect:r,onClose:i}){let a=gn(Mn,e);return(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,"data-slot":`rls-policy-templates`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-stretch border-b border-border/60`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`p`,{className:`px-3 pt-2.5 text-[10px] font-semibold tracking-[0.12em] text-muted-foreground uppercase`,children:`Templates`}),(0,Q.jsxs)(`label`,{className:`relative block`,children:[(0,Q.jsx)(H,{icon:x,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)(d,{value:e,onChange:e=>t(e.target.value),placeholder:`Search templates`,"aria-label":`Search templates`,flat:!0,className:J(an,`font-mono`)})]})]}),(0,Q.jsx)(`span`,{className:`w-px shrink-0 self-stretch bg-border/60`,"aria-hidden":!0}),(0,Q.jsx)(`button`,{type:`button`,className:J(Fe,`min-w-11`),onClick:i,"aria-label":`Close templates`,"data-slot":`rls-policy-templates-close`,children:(0,Q.jsx)(H,{icon:c,className:`size-4`,"aria-hidden":!0})})]}),(0,Q.jsx)(`ul`,{className:`min-h-0 flex-1 overflow-y-auto p-2`,children:a.length===0?(0,Q.jsx)(`li`,{className:`px-2 py-3 text-[10px] text-muted-foreground`,children:`No matching templates.`}):a.map(e=>{let t=e.id===n;return(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:()=>r(e),className:J(`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:J(`rounded px-1.5 py-px font-mono text-[9px] font-semibold tracking-wide`,Lo[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)(H,{icon:Ke,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 zo({advanced:e,onAdvancedChange:t,mode:n,onModeChange:r,catalog:i,query:a,onQueryChange:o,selection:s,onToggleGate:c}){let l=_r(s);return(0,Q.jsxs)(`div`,{className:J(!e&&`border-b border-border/50`),children:[(0,Q.jsx)(Bo,{mode:n,onChange:r,advanced:e,extraCount:l,onAdvancedChange:t}),e?(0,Q.jsx)(Uo,{catalog:i,query:a,onQueryChange:o,selection:s,onToggleGate:c}):null]})}function Bo({mode:e,onChange:t,advanced:n,extraCount:r,onAdvancedChange:i}){let a=(0,Z.useId)(),o=It();return(0,Q.jsx)(Yi,{id:a,children:(0,Q.jsxs)(`div`,{role:`group`,"aria-label":`Gate`,className:J(`flex w-full items-center`,n&&`border-b border-border/50`),children:[Fo.map(r=>{let a=!n&&e===r.id;return(0,Q.jsxs)(Vo,{active:a,reduceMotion:o,onClick:()=>{i(!1),t(r.id)},children:[(0,Q.jsx)(H,{icon:r.icon,className:`size-3.5`,"aria-hidden":!0}),r.label]},r.id)}),(0,Q.jsxs)(Vo,{active:n,reduceMotion:o,"aria-expanded":n,"aria-controls":`rls-gate-advanced`,onClick:()=>i(!n),children:[(0,Q.jsx)(H,{icon:me,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 Vo({active:e,reduceMotion:t,onClick:n,children:r,...i}){return(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":e,onClick:n,className:J(`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 Ho={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 Uo({catalog:e,query:t,onQueryChange:n,selection:r,onToggleGate:i}){let a=tr(e,t),o=Jn(a),s=Bn(a),l=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)(H,{icon:x,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)(d,{value:t,onChange:e=>n(e.target.value),placeholder:`Search policy or scope`,"aria-label":`Search policy or scope`,flat:!0,className:J(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)(H,{icon:c,className:`size-2.5`,"aria-hidden":!0})]},e))}):null,(0,Q.jsxs)(Wo,{empty:l?`No matches.`:`No policy or scope gates declared.`,hasRows:o.length+s.length>0,children:[o.length>0?(0,Q.jsx)(Go,{label:`Policy`,hint:`gate.policy`}):null,o.map(e=>(0,Q.jsx)(Ko,{icon:qo(e.variant),label:e.name,detail:Jo(e),selected:r.gates.includes(e.name),onSelect:()=>i(e.name),pressed:!0},e.name)),s.length>0?(0,Q.jsx)(Go,{label:`Scope`,hint:`gate.scope`}):null,s.map(e=>(0,Q.jsx)(Ko,{icon:qo(e.variant),label:e.name,detail:Jo(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 Go({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 Ko({icon:e,label:t,detail:n,selected:r,onSelect:i,pressed:a=!1}){return(0,Q.jsx)(`li`,{className:`border-b border-border/50 last:border-b-0`,children:(0,Q.jsxs)(`button`,{type:`button`,role:a?`checkbox`:`radio`,"aria-checked":r,"aria-pressed":a?r:void 0,onClick:i,className:J(`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:J(`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)(H,{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)(H,{icon:Ke,className:`mt-0.5 size-3.5 shrink-0`,"aria-hidden":!0}):null]})})}function qo(e){return e===`public`?He:e===`scope`?fe:ne}function Jo(e){return e.description?e.description:e.variant===`public`?`Intentionally unauthenticated`:e.variant===`scope`?`auth.scopes.has("${e.name}")`:`ABAC policy`}function Yo({commands:e,value:t,onChange:n}){return(0,Q.jsx)(Jt,{label:`FOR`,hint:Ho[t],children:e.map(e=>(0,Q.jsx)(tn,{active:t===e,onClick:()=>n(e),children:e},e))})}function Xo(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 Zo(){return ot({mutationFn:async e=>{let t=await k(e),n=Xo(t);if(n)throw n;if(!t.data)throw Error(`Empty SQL result`);return t.data}})}function Qo({value:e,onChange:t,label:n,className:r,onSubmit:i}){let a=(0,Z.useRef)(null),o=(0,Z.useRef)(null),s=e.endsWith(`
|
|
5
|
-
`)?e:`${e}\n`;return(0,Q.jsxs)(`div`,{className:J(`relative min-h-56 bg-muted/15`,r),children:[(0,Q.jsx)(`div`,{ref:a,className:`pointer-events-none absolute inset-0 overflow-hidden`,children:(0,Q.jsx)(ni,{code:s,language:`sql`,className:`overflow-visible whitespace-pre-wrap break-words px-4 py-3 text-[11px] leading-5`})}),(0,Q.jsx)(`textarea`,{ref:o,value:e,onChange:e=>t(e.target.value),onScroll:()=>{let e=o.current,t=a.current;!e||!t||(t.scrollTop=e.scrollTop,t.scrollLeft=e.scrollLeft)},onKeyDown:e=>{i&&(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),i())},spellCheck:!1,autoCorrect:`off`,autoCapitalize:`off`,"aria-label":n,"data-slot":`sql-style-editor`,className:`absolute inset-0 h-full w-full resize-none overflow-auto bg-transparent px-4 py-3 font-mono text-[11px] leading-5 break-words whitespace-pre-wrap text-transparent caret-foreground outline-none`})]})}var $o=[{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 es(e){let t=e.orReplace===!0?`OR REPLACE `:``,n=rs(e.args)?e.args.trim():``,r=rs(e.returns)?e.returns.trim():``,i=[`CREATE ${t}FUNCTION ${os(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!==``&&rs(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:is(e.language)),i.push(`$$;`),i.join(`
|
|
10
|
-
`)}es({name:`function_name`,args:``,returns:`void`,language:`plpgsql`,body:`BEGIN
|
|
11
|
-
-- Write your function logic here
|
|
12
|
-
END;`});function ts(e){return/^\s*CREATE\s+(OR\s+REPLACE\s+)?FUNCTION\b/i.test(e)}function ns(e){return/AS\s+\$\$\n?([\s\S]*?)\n?\$\$;?\s*$/i.exec(e)?.[1]??null}function rs(e){let t=e.trim();return t.length<=2e3&&!/;/.test(t)&&!/--/.test(t)&&!/\/\*/.test(t)}function is(e){return e===`sql`?` SELECT NULL;`:`BEGIN
|
|
13
|
-
-- Write your function logic here
|
|
14
|
-
END;`}function as(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 os(e){let t=e.trim().replace(/\(\s*\)$/,``);return(t.length>0?t:`function_name`).split(`.`).map(e=>Cn(e)).join(`.`)}var ss=[`plpgsql`,`sql`],cs=[`VOLATILE`,`STABLE`,`IMMUTABLE`],ls=[`INVOKER`,`DEFINER`],us=[`UNSAFE`,`RESTRICTED`,`SAFE`];function ds(){return`BEGIN
|
|
15
|
-
-- Write your function logic here
|
|
16
|
-
END;`}function fs({open:e,onOpenChange:t,storeRef:n}){let r=P(),{mutate:i,isPending:a,reset:o}=Zo(),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(`void`),[m,h]=(0,Z.useState)(`plpgsql`),[g,_]=(0,Z.useState)(`VOLATILE`),[v,y]=(0,Z.useState)(!1),[b,x]=(0,Z.useState)(!1),[S,C]=(0,Z.useState)(`INVOKER`),[w,T]=(0,Z.useState)(!1),[E,D]=(0,Z.useState)(!1),[O,k]=(0,Z.useState)(`UNSAFE`),[A,j]=(0,Z.useState)(``),[M,N]=(0,Z.useState)(``),[F,ee]=(0,Z.useState)(``),[I,L]=(0,Z.useState)(``),[R,te]=(0,Z.useState)(null),[z,B]=(0,Z.useState)(null),V=(e,t=I)=>{let n=e.name??s,r=e.args??l,i=e.returns??f,a=e.language??m,o=e.volatility??g,c=e.orReplace??v,u=e.security??S,d=e.strict??w,p=e.leakproof??E,h=e.parallel??O,_=e.searchPath??A,y=Number(e.cost??M),b=Number(e.rows??F);L(es({name:n.trim()||`function_name`,args:r,returns:i,language:a,volatility:o,body:e.body??ns(t)??ds(),orReplace:c,security:u,strict:d,leakproof:p,parallel:h,..._.trim()===``?{}:{searchPath:_},...Number.isFinite(y)&&y>0?{cost:y}:{},...Number.isFinite(b)&&b>0?{rows:b}:{}}))};(0,Z.useEffect)(()=>{e&&(c(``),u(``),p(`void`),h(`plpgsql`),_(`VOLATILE`),y(!1),x(!1),C(`INVOKER`),T(!1),D(!1),k(`UNSAFE`),j(``),N(``),ee(``),B(null),te(null),L(es({name:`function_name`,args:``,returns:`void`,language:`plpgsql`,body:ds()})),o())},[e,o]);let ne=e=>{B(e.id);let t=s.trim()===``?e.id.replaceAll(`-`,`_`):s;p(e.returns),h(e.language),_(e.volatility??`VOLATILE`),u(e.args??``),s.trim()===``&&c(t),V({name:t,args:e.args??``,returns:e.returns,language:e.language,volatility:e.volatility??`VOLATILE`,body:e.body},I)},re=()=>{if(!ts(I)){te(`This sheet runs CREATE FUNCTION only`);return}te(null),i({ref:n,sql:I,allowWrite:!0},{onSuccess:()=>{r.invalidateQueries({queryKey:fr}),t(!1)},onError:e=>te(e instanceof Error?e.message:String(e))})};return(0,Q.jsx)(Te,{open:e,onOpenChange:t,children:(0,Q.jsxs)(K,{side:`right`,className:`flex w-full flex-col gap-0 overflow-hidden data-[side=right]:sm:max-w-xl`,"data-slot":`sql-function-sheet`,onKeyDown:e=>{!(e.metaKey||e.ctrlKey)||e.key!==`Enter`||(e.preventDefault(),a||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)(H,{icon:xe,className:`size-4`,"aria-hidden":!0})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(Je,{className:`text-sm`,children:`New function`}),(0,Q.jsx)(Ve,{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)(za,{templates:$o,selectedId:z,onSelect:ne}),(0,Q.jsx)(Y,{label:`Function name`,children:(0,Q.jsx)(d,{value:s,onChange:e=>{let t=e.target.value;c(t),V({name:t})},placeholder:`function_name`,flat:!0,className:J(X,`font-mono`)})}),(0,Q.jsxs)(ln,{children:[(0,Q.jsx)(Y,{label:`Arguments`,split:`start`,children:(0,Q.jsx)(d,{value:l,onChange:e=>{let t=e.target.value;u(t),V({args:t})},placeholder:`optional — id text`,flat:!0,className:J(X,`font-mono`)})}),(0,Q.jsx)(Y,{label:`Returns`,split:`end`,children:(0,Q.jsx)(d,{value:f,onChange:e=>{let t=e.target.value;p(t),V({returns:t})},placeholder:`void`,flat:!0,className:J(X,`font-mono`)})})]}),(0,Q.jsx)(Jt,{label:`Language`,children:ss.map(e=>(0,Q.jsx)(tn,{active:m===e,onClick:()=>{h(e),V({language:e})},children:e},e))}),(0,Q.jsx)(Jt,{label:`Volatility`,children:cs.map(e=>(0,Q.jsx)(tn,{active:g===e,onClick:()=>{_(e),V({volatility:e})},children:e},e))}),(0,Q.jsx)(Zt,{label:`Replace if it already exists`,children:(0,Q.jsx)(La,{size:`sm`,checked:v,onCheckedChange:e=>{y(e),V({orReplace:e})},ariaLabel:`Replace if it already exists`})}),(0,Q.jsx)(cn,{label:`Options`,children:(0,Q.jsx)(Ra,{open:b,extraCount:as({security:S,strict:w,leakproof:E,parallel:O,searchPath:A,cost:Number(M),rows:Number(F)}),onOpenChange:x,controls:`sql-function-advanced`})}),b?(0,Q.jsxs)(`div`,{id:`sql-function-advanced`,children:[(0,Q.jsx)(Jt,{label:`Security`,children:ls.map(e=>(0,Q.jsx)(tn,{active:S===e,onClick:()=>{C(e),V({security:e})},children:e},e))}),(0,Q.jsx)(Jt,{label:`Parallel`,children:us.map(e=>(0,Q.jsx)(tn,{active:O===e,onClick:()=>{k(e),V({parallel:e})},children:e},e))}),(0,Q.jsxs)(ln,{children:[(0,Q.jsx)(Zt,{label:`STRICT`,className:`border-r border-b-0`,children:(0,Q.jsx)(La,{size:`sm`,checked:w,onCheckedChange:e=>{T(e),V({strict:e})},ariaLabel:`STRICT`})}),(0,Q.jsx)(Zt,{label:`LEAKPROOF`,className:`border-b-0`,children:(0,Q.jsx)(La,{size:`sm`,checked:E,onCheckedChange:e=>{D(e),V({leakproof:e})},ariaLabel:`LEAKPROOF`})})]}),(0,Q.jsx)(Y,{label:`SET search_path`,children:(0,Q.jsx)(d,{value:A,onChange:e=>{let t=e.target.value;j(t),V({searchPath:t})},placeholder:`public, pg_temp`,flat:!0,className:J(X,`font-mono`)})}),(0,Q.jsxs)(ln,{children:[(0,Q.jsx)(Y,{label:`COST`,split:`start`,children:(0,Q.jsx)(d,{value:M,onChange:e=>{let t=e.target.value;N(t),V({cost:t})},placeholder:`optional`,inputMode:`decimal`,flat:!0,className:J(X,`font-mono`)})}),(0,Q.jsx)(Y,{label:`ROWS`,split:`end`,children:(0,Q.jsx)(d,{value:F,onChange:e=>{let t=e.target.value;ee(t),V({rows:t})},placeholder:`optional`,inputMode:`decimal`,flat:!0,className:J(X,`font-mono`)})})]})]}):null]}),(0,Q.jsxs)(`div`,{className:`shrink-0 border-t border-border/50`,"data-slot":`sql-function-sql-dock`,children:[(0,Q.jsx)(cn,{label:`SQL`,hint:`Editable before it runs`}),(0,Q.jsx)(Qo,{value:I,onChange:L,onSubmit:a?void 0:re,label:`CREATE FUNCTION SQL`,className:`min-h-36 max-h-48`}),R?(0,Q.jsx)(on,{slot:`sql-function-error`,children:R}):null]}),(0,Q.jsxs)(pe,{children:[(0,Q.jsx)(Xt,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(Xt,{variant:`default`,disabled:a||!ts(I),onClick:re,"data-slot":`sql-function-submit`,children:a?`Creating…`:`Create function`})]})]})})}var ps=[{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 ms(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}${Cn(e.name)}`,` ON ${Cn(e.table)}${i}`,` (${vs(e.columns)})`],o=e.include?.trim()??``;o!==``&&_s(o)&&a.push(` INCLUDE (${vs(o)})`),e.nullsNotDistinct===!0&&a.push(` NULLS NOT DISTINCT`);let s=e.with?.trim()??``;s!==``&&_s(s)&&a.push(` WITH (${s})`);let c=e.where?.trim()??``;return c!==``&&_s(c)&&a.push(` WHERE ${c}`),`${a.join(`
|
|
17
|
-
`)};`}function hs(e){return+(e.concurrently===!0)+ +!!e.include?.trim()+ +(e.nullsNotDistinct===!0)+ +!!e.with?.trim()}ms({name:`index_name`,table:`table_name`,columns:`column_name`});function gs(e){return/^\s*CREATE\s+(UNIQUE\s+)?INDEX\b/i.test(e)}function _s(e){let t=e.trim();return t.length>0&&t.length<=2e3&&!/;/.test(t)&&!/--/.test(t)&&!/\/\*/.test(t)}function vs(e){if(!_s(e))return Cn(`column_name`);let t=e.split(`,`).map(e=>e.trim()).filter(e=>e.length>0);return t.length===0?Cn(`column_name`):t.map(e=>wn(e)?Cn(e):e).join(`, `)}var ys=[`btree`,`hash`,`gin`,`gist`,`brin`];function bs({open:e,onOpenChange:t,storeRef:n,tables:r}){let i=P(),{mutate:a,isPending:o,reset:s}=Zo(),[c,l]=(0,Z.useState)(``),[u,f]=(0,Z.useState)(r[0]??``),[p,m]=(0,Z.useState)(`column_name`),[h,g]=(0,Z.useState)(`btree`),[_,v]=(0,Z.useState)(!1),[y,b]=(0,Z.useState)(!1),[x,S]=(0,Z.useState)(``),[C,w]=(0,Z.useState)(!1),[T,E]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(``),[k,A]=(0,Z.useState)(!1),[j,M]=(0,Z.useState)(``),[N,F]=(0,Z.useState)(``),[ee,I]=(0,Z.useState)(null),[L,R]=(0,Z.useState)(null),te=(0,Z.useMemo)(()=>ms({name:c.trim()||`index_name`,table:u.trim()||`table_name`,columns:p,method:h,unique:_,ifNotExists:y,concurrently:T,nullsNotDistinct:k,...x.trim()===``?{}:{where:x},...D.trim()===``?{}:{include:D},...j.trim()===``?{}:{with:j}}),[c,u,p,h,_,y,x,T,D,k,j]);(0,Z.useEffect)(()=>{if(!e)return;let t=r[0]??``;l(``),f(t),m(`column_name`),g(`btree`),v(!1),b(!1),S(``),w(!1),E(!1),O(``),A(!1),M(``),R(null),I(null),F(ms({name:`index_name`,table:t||`table_name`,columns:`column_name`})),s()},[e,r,s]),(0,Z.useEffect)(()=>{F(te)},[te]);let z=e=>{R(e.id),m(e.columns),g(e.method??`btree`),v(e.unique===!0),S(e.where??``),c.trim()===``&&l(e.id.replaceAll(`-`,`_`))},B=()=>{if(!gs(N)){I(`This sheet runs CREATE INDEX only`);return}I(null),a({ref:n,sql:N,allowWrite:!0},{onSuccess:()=>{i.invalidateQueries({queryKey:fr}),t(!1)},onError:e=>I(e instanceof Error?e.message:String(e))})};return(0,Q.jsx)(Te,{open:e,onOpenChange:t,children:(0,Q.jsxs)(K,{side:`right`,className:`flex w-full flex-col gap-0 overflow-hidden data-[side=right]:sm:max-w-xl`,"data-slot":`sql-index-sheet`,onKeyDown:e=>{!(e.metaKey||e.ctrlKey)||e.key!==`Enter`||(e.preventDefault(),o||B())},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)(H,{icon:fe,className:`size-4`,"aria-hidden":!0})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(Je,{className:`text-sm`,children:`Create index`}),(0,Q.jsx)(Ve,{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)(za,{templates:ps,selectedId:L,onSelect:z}),(0,Q.jsxs)(ln,{children:[(0,Q.jsx)(Y,{label:`Index name`,split:`start`,children:(0,Q.jsx)(d,{value:c,onChange:e=>l(e.target.value),placeholder:`index_name`,flat:!0,className:J(X,`font-mono`)})}),(0,Q.jsx)(Y,{label:`Table`,split:`end`,children:(0,Q.jsxs)(Oa,{value:u,onValueChange:f,children:[(0,Q.jsx)(ka,{flat:!0,className:J(X,`font-mono`),children:(0,Q.jsx)(Aa,{placeholder:`Select a table`})}),(0,Q.jsx)(ja,{children:r.map(e=>(0,Q.jsx)(Ma,{value:e,className:`font-mono text-[12px]`,children:e},e))})]})})]}),(0,Q.jsx)(Y,{label:`Columns`,children:(0,Q.jsx)(d,{value:p,onChange:e=>m(e.target.value),placeholder:`column_name`,flat:!0,className:J(X,`font-mono`)})}),(0,Q.jsx)(Jt,{label:`Method`,children:ys.map(e=>(0,Q.jsx)(tn,{active:h===e,onClick:()=>g(e),children:e},e))}),(0,Q.jsx)(Y,{label:`WHERE`,children:(0,Q.jsx)(d,{value:x,onChange:e=>S(e.target.value),placeholder:`optional`,flat:!0,className:J(X,`font-mono`)})}),(0,Q.jsxs)(ln,{children:[(0,Q.jsx)(Zt,{label:`Unique`,className:`border-r border-b-0`,children:(0,Q.jsx)(La,{size:`sm`,checked:_,onCheckedChange:v,ariaLabel:`Unique`})}),(0,Q.jsx)(Zt,{label:`Skip if it exists`,className:`border-b-0`,children:(0,Q.jsx)(La,{size:`sm`,checked:y,onCheckedChange:b,ariaLabel:`Skip if it already exists`})})]}),(0,Q.jsx)(cn,{label:`Options`,children:(0,Q.jsx)(Ra,{open:C,extraCount:hs({concurrently:T,include:D,nullsNotDistinct:k,with:j}),onOpenChange:w,controls:`sql-index-advanced`})}),C?(0,Q.jsxs)(`div`,{id:`sql-index-advanced`,children:[(0,Q.jsx)(Zt,{label:`Concurrently`,children:(0,Q.jsx)(La,{size:`sm`,checked:T,onCheckedChange:E,ariaLabel:`Create index concurrently`})}),(0,Q.jsx)(Y,{label:`INCLUDE`,children:(0,Q.jsx)(d,{value:D,onChange:e=>O(e.target.value),placeholder:`covering columns`,flat:!0,className:J(X,`font-mono`)})}),(0,Q.jsx)(Zt,{label:`NULLS NOT DISTINCT`,children:(0,Q.jsx)(La,{size:`sm`,checked:k,onCheckedChange:A,ariaLabel:`NULLS NOT DISTINCT`})}),(0,Q.jsx)(Y,{label:`WITH`,children:(0,Q.jsx)(d,{value:j,onChange:e=>M(e.target.value),placeholder:`fillfactor = 70`,flat:!0,className:J(X,`font-mono`)})})]}):null]}),(0,Q.jsxs)(`div`,{className:`shrink-0 border-t border-border/50`,"data-slot":`sql-index-sql-dock`,children:[(0,Q.jsx)(cn,{label:`SQL`,hint:`Editable before it runs`}),(0,Q.jsx)(Qo,{value:N,onChange:F,onSubmit:o?void 0:B,label:`CREATE INDEX SQL`,className:`min-h-36 max-h-48`}),ee?(0,Q.jsx)(on,{slot:`sql-index-error`,children:ee}):null]}),(0,Q.jsxs)(pe,{children:[(0,Q.jsx)(Xt,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(Xt,{variant:`default`,disabled:o||!gs(N),onClick:B,"data-slot":`sql-index-submit`,children:o?`Creating…`:`Create index`})]})]})})}var xs=[{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 Ss(e){let t=Es(e.events,e.updateOf),n=[`CREATE ${e.orReplace===!0?`OR REPLACE `:``}${e.constraint===!0?`CONSTRAINT `:``}TRIGGER ${Cn(e.name)}`,` ${e.timing} ${t}`,` ON ${Cn(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=Ds(e.referencingOld,e.referencingNew);r!==``&&n.push(` ${r}`),n.push(` FOR EACH ${e.level}`);let i=e.when?.trim()??``;i!==``&&ws(i)&&n.push(` WHEN (${i})`);let a=e.functionArgs!==void 0&&ws(e.functionArgs.trim())?e.functionArgs.trim():``;return n.push(` EXECUTE FUNCTION ${Os(e.functionName)}(${a});`),n.join(`
|
|
18
|
-
`)}Ss({name:`trigger_name`,table:`table_name`,timing:`AFTER`,events:[`INSERT`,`UPDATE`,`DELETE`],level:`ROW`,functionName:`function_name`});function Cs(e){return/^\s*CREATE\s+(OR\s+REPLACE\s+)?(CONSTRAINT\s+)?TRIGGER\b/i.test(e)}function ws(e){let t=e.trim();return t.length>0&&t.length<=2e3&&!/;/.test(t)&&!/--/.test(t)&&!/\/\*/.test(t)}function Ts(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 Es(e,t){let n=e.length>0?e:[`INSERT`],r=t?.trim()??``;return n.map(e=>e===`UPDATE`&&r!==``&&ws(r)?`UPDATE OF ${r}`:e).join(` OR `)}function Ds(e,t){let n=[],r=e?.trim()??``,i=t?.trim()??``;return r!==``&&ws(r)&&n.push(`OLD TABLE AS ${Cn(r)}`),i!==``&&ws(i)&&n.push(`NEW TABLE AS ${Cn(i)}`),n.length>0?`REFERENCING ${n.join(` `)}`:``}function Os(e){let t=e.trim().replace(/\(\s*\)$/,``);return(t.length>0?t:`function_name`).split(`.`).map(e=>Cn(e)).join(`.`)}var ks=[`BEFORE`,`AFTER`,`INSTEAD OF`],As=[`INSERT`,`UPDATE`,`DELETE`],js=[`ROW`,`STATEMENT`],Ms=[{id:`immediate`,label:`IMMEDIATE`},{id:`deferred`,label:`DEFERRED`}];function Ns({open:e,onOpenChange:t,storeRef:n,tables:r}){let i=P(),{mutate:a,isPending:o,reset:s}=Zo(),[c,l]=(0,Z.useState)(``),[u,f]=(0,Z.useState)(r[0]??``),[p,m]=(0,Z.useState)(`AFTER`),[h,g]=(0,Z.useState)([`INSERT`]),[_,v]=(0,Z.useState)(`ROW`),[y,b]=(0,Z.useState)(``),[x,S]=(0,Z.useState)(``),[C,w]=(0,Z.useState)(!1),[T,E]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(!1),[k,A]=(0,Z.useState)(null),[j,M]=(0,Z.useState)(``),[N,F]=(0,Z.useState)(``),[ee,I]=(0,Z.useState)(``),[L,R]=(0,Z.useState)(``),[te,z]=(0,Z.useState)(``),[B,V]=(0,Z.useState)(null),[ne,re]=(0,Z.useState)(null),U=(0,Z.useMemo)(()=>Ss({name:c.trim()||`trigger_name`,table:u.trim()||`table_name`,timing:p,events:h,level:_,functionName:y.trim()||`function_name`,orReplace:C,constraint:D,...x.trim()===``?{}:{when:x},...k===null?{}:{defer:k},...j.trim()===``?{}:{updateOf:j},...N.trim()===``?{}:{referencingOld:N},...ee.trim()===``?{}:{referencingNew:ee},...L.trim()===``?{}:{functionArgs:L}}),[c,u,p,h,_,y,x,C,D,k,j,N,ee,L]);(0,Z.useEffect)(()=>{if(!e)return;let t=r[0]??``;l(``),f(t),m(`AFTER`),g([`INSERT`]),v(`ROW`),b(``),S(``),w(!1),E(!1),O(!1),A(null),M(``),F(``),I(``),R(``),re(null),V(null),z(Ss({name:`trigger_name`,table:t||`table_name`,timing:`AFTER`,events:[`INSERT`],level:`ROW`,functionName:`function_name`})),s()},[e,r,s]),(0,Z.useEffect)(()=>{z(U)},[U]);let ie=e=>{re(e.id),m(e.timing),g(e.events),v(e.level),c.trim()===``&&l(e.id.replaceAll(`-`,`_`))},ae=e=>{if(h.includes(e)){if(h.length===1)return;g(h.filter(t=>t!==e));return}let t=[...h,e];g(t),e===`TRUNCATE`&&v(`STATEMENT`)},oe=()=>{if(!Cs(te)){V(`This sheet runs CREATE TRIGGER only`);return}V(null),a({ref:n,sql:te,allowWrite:!0},{onSuccess:()=>{i.invalidateQueries({queryKey:fr}),t(!1)},onError:e=>V(e instanceof Error?e.message:String(e))})};return(0,Q.jsx)(Te,{open:e,onOpenChange:t,children:(0,Q.jsxs)(K,{side:`right`,className:`flex w-full flex-col gap-0 overflow-hidden data-[side=right]:sm:max-w-xl`,"data-slot":`sql-trigger-sheet`,onKeyDown:e=>{!(e.metaKey||e.ctrlKey)||e.key!==`Enter`||(e.preventDefault(),o||oe())},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)(H,{icon:ve,className:`size-4`,"aria-hidden":!0})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(Je,{className:`text-sm`,children:`New trigger`}),(0,Q.jsx)(Ve,{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)(za,{templates:xs,selectedId:ne,onSelect:ie}),(0,Q.jsxs)(ln,{children:[(0,Q.jsx)(Y,{label:`Trigger name`,split:`start`,children:(0,Q.jsx)(d,{value:c,onChange:e=>l(e.target.value),placeholder:`trigger_name`,flat:!0,className:J(X,`font-mono`)})}),(0,Q.jsx)(Y,{label:`Table`,split:`end`,children:(0,Q.jsxs)(Oa,{value:u,onValueChange:f,children:[(0,Q.jsx)(ka,{flat:!0,className:J(X,`font-mono`),children:(0,Q.jsx)(Aa,{placeholder:`Select a table`})}),(0,Q.jsx)(ja,{children:r.map(e=>(0,Q.jsx)(Ma,{value:e,className:`font-mono text-[12px]`,children:e},e))})]})})]}),(0,Q.jsx)(Jt,{label:`Timing`,children:ks.map(e=>(0,Q.jsx)(tn,{active:p===e,onClick:()=>m(e),children:e},e))}),(0,Q.jsx)(Jt,{label:`Events`,children:As.map(e=>(0,Q.jsx)(tn,{active:h.includes(e),onClick:()=>ae(e),children:e},e))}),(0,Q.jsx)(Jt,{label:`For each`,children:js.map(e=>(0,Q.jsx)(tn,{active:_===e,onClick:()=>v(e),children:e},e))}),(0,Q.jsxs)(ln,{children:[(0,Q.jsx)(Y,{label:`Function`,split:`start`,children:(0,Q.jsx)(d,{value:y,onChange:e=>b(e.target.value),placeholder:`function_name`,flat:!0,className:J(X,`font-mono`)})}),(0,Q.jsx)(Y,{label:`WHEN`,split:`end`,children:(0,Q.jsx)(d,{value:x,onChange:e=>S(e.target.value),placeholder:`optional`,flat:!0,className:J(X,`font-mono`)})})]}),(0,Q.jsx)(Zt,{label:`Replace if it already exists`,children:(0,Q.jsx)(La,{size:`sm`,checked:C,onCheckedChange:w,ariaLabel:`Replace if it already exists`})}),(0,Q.jsx)(cn,{label:`Options`,children:(0,Q.jsx)(Ra,{open:T,extraCount:Ts({constraint:D,...k===null?{}:{defer:k},updateOf:j,referencingOld:N,referencingNew:ee,functionArgs:L,events:h}),onOpenChange:E,controls:`sql-trigger-advanced`})}),T?(0,Q.jsxs)(`div`,{id:`sql-trigger-advanced`,children:[(0,Q.jsx)(Jt,{label:`Also fire on`,children:(0,Q.jsx)(tn,{active:h.includes(`TRUNCATE`),onClick:()=>ae(`TRUNCATE`),children:`TRUNCATE`})}),h.includes(`UPDATE`)?(0,Q.jsx)(Y,{label:`UPDATE OF`,children:(0,Q.jsx)(d,{value:j,onChange:e=>M(e.target.value),placeholder:`column_name`,flat:!0,className:J(X,`font-mono`)})}):null,(0,Q.jsx)(Y,{label:`Function args`,children:(0,Q.jsx)(d,{value:L,onChange:e=>R(e.target.value),placeholder:`optional`,flat:!0,className:J(X,`font-mono`)})}),(0,Q.jsx)(Zt,{label:`CONSTRAINT`,children:(0,Q.jsx)(La,{size:`sm`,checked:D,onCheckedChange:e=>{O(e),e||A(null)},ariaLabel:`CONSTRAINT trigger`})}),D?(0,Q.jsx)(Jt,{label:`Defer`,children:Ms.map(e=>(0,Q.jsx)(tn,{active:k===e.id,onClick:()=>A(k===e.id?null:e.id),children:e.label},e.id))}):null,(0,Q.jsxs)(ln,{children:[(0,Q.jsx)(Y,{label:`OLD TABLE AS`,split:`start`,children:(0,Q.jsx)(d,{value:N,onChange:e=>F(e.target.value),placeholder:`optional`,flat:!0,className:J(X,`font-mono`)})}),(0,Q.jsx)(Y,{label:`NEW TABLE AS`,split:`end`,children:(0,Q.jsx)(d,{value:ee,onChange:e=>I(e.target.value),placeholder:`optional`,flat:!0,className:J(X,`font-mono`)})})]})]}):null]}),(0,Q.jsxs)(`div`,{className:`shrink-0 border-t border-border/50`,"data-slot":`sql-trigger-sql-dock`,children:[(0,Q.jsx)(cn,{label:`SQL`,hint:`Editable before it runs`}),(0,Q.jsx)(Qo,{value:te,onChange:z,onSubmit:o?void 0:oe,label:`CREATE TRIGGER SQL`,className:`min-h-36 max-h-48`}),B?(0,Q.jsx)(on,{slot:`sql-trigger-error`,children:B}):null]}),(0,Q.jsxs)(pe,{children:[(0,Q.jsx)(Xt,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(Xt,{variant:`default`,disabled:o||!Cs(te),onClick:oe,"data-slot":`sql-trigger-submit`,children:o?`Creating…`:`Create trigger`})]})]})})}function Ps({open:e,onOpenChange:t,phrase:n,title:r,description:i,willNotFire:a,pending:o=!1,error:s,onConfirm:c}){return(0,Q.jsx)(Vi,{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 Fs=`M5 13l4 4L19 7`,Is=`M6 12h12`;function Ls({checked:e,onCheckedChange:t,disabled:n,indeterminate:r,label:i,className:a,id:o,"aria-label":s,"aria-describedby":c}){let l=(0,Z.useId)(),u=o??l,d=It(),f=e||r,p=r?Is:Fs;return(0,Q.jsxs)(`label`,{htmlFor:u,className:J(`inline-flex items-center gap-3`,n?`cursor-not-allowed`:`cursor-pointer`,a),children:[(0,Q.jsx)(Lt.button,{id:u,type:`button`,role:`checkbox`,"aria-checked":r?`mixed`:e,"aria-label":s,"aria-describedby":c,disabled:n,onClick:()=>{n||t(!e)},whileTap:d||n?void 0:{scale:.94},transition:{duration:.12,ease:jt},"data-state":e?`checked`:r?`indeterminate`:`unchecked`,className:J(`relative inline-flex size-4 shrink-0 items-center justify-center overflow-hidden rounded-sm border-2 outline-none transition-colors duration-200`,`focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background`,`disabled:cursor-not-allowed disabled:opacity-60`,f?`border-foreground bg-foreground text-background`:`border-muted-foreground/40 bg-background hover:border-muted-foreground`),children:(0,Q.jsx)(zt,{initial:!1,children:f?(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:d?{opacity:1}:{opacity:0,scale:.5},animate:d?{opacity:1}:{opacity:1,scale:1},exit:d?{opacity:0}:{opacity:0,scale:.5},transition:d?{duration:0}:{duration:.16,ease:jt},"aria-hidden":!0,children:[(0,Q.jsx)(`title`,{children:r?`Partially selected`:`Selected`}),(0,Q.jsx)(Lt.path,{d:p,initial:d?{pathLength:1}:{pathLength:0},animate:{pathLength:1},transition:d?{duration:0}:{duration:r?.2:.3,ease:jt,delay:.04}})]},r?`indeterminate`:`checked`):null})}),i?(0,Q.jsx)(`span`,{children:i}):null]})}function Rs({className:e,...t}){return(0,Q.jsx)(`nav`,{"aria-label":`breadcrumb`,"data-slot":`breadcrumb`,className:J(e),...t})}function zs({className:e,...t}){return(0,Q.jsx)(`ol`,{"data-slot":`breadcrumb-list`,className:J(`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:J(`inline-flex items-center gap-1`,e),...t})}function Vs({className:e,render:t,...n}){return $e({defaultTagName:`a`,props:N({className:J(`transition-colors hover:text-foreground`,e)},n),render:t,state:{slot:`breadcrumb-link`}})}function Hs({className:e,...t}){return(0,Q.jsx)(`span`,{"data-slot":`breadcrumb-page`,role:`link`,"aria-disabled":`true`,"aria-current":`page`,className:J(`font-normal text-foreground`,e),...t})}function Us({children:e,className:t,...n}){return(0,Q.jsx)(`li`,{"data-slot":`breadcrumb-separator`,role:`presentation`,"aria-hidden":`true`,className:J(`[&>svg]:size-3.5`,t),...n,children:e??(0,Q.jsx)(H,{icon:j,className:`cn-rtl-flip`})})}function Ws(e){return e.length===0||e.startsWith(`/`)||e.includes(`..`)?!1:/^[\x20-\x7E]+$/.test(e)}function Gs(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 Ks(e){let t=e.replace(/^\/+|\/+$/g,``).split(`/`).filter(e=>e.length>0);return t.length===0?``:`${t.map(e=>Ws(e)?e:Gs(e,`folder`)).join(`/`)}/`}function qs(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 Js(){let e=new Uint8Array(4);return crypto.getRandomValues(e),[...e].map(e=>e.toString(16).padStart(2,`0`)).join(``)}function Ys(e,t=``,n=Js()){let r=qs(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`${Ks(t)}${Gs(s)}-${n}${r}`}var Xs=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`avif`,`bmp`,`ico`]),Zs=new Set([`txt`,`md`,`csv`,`tsv`,`log`,`json`,`xml`,`yml`,`yaml`,`toml`,`ini`,`cfg`,`conf`]),Qs=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(`.`)),$s=new Set([`mp4`,`webm`,`mov`,`m4v`,`ogv`]),ec=new Set([`mp3`,`wav`,`ogg`,`m4a`,`aac`,`flac`,`opus`,`oga`]),tc=new Set([`zip`,`tar`,`gz`,`tgz`,`7z`]);function nc(e){let t=e.replace(/\/+$/,``),n=t.lastIndexOf(`/`);return n===-1?t:t.slice(n+1)}function rc(e){let t=nc(e),n=t.lastIndexOf(`.`);return n<=0||n===t.length-1?``:t.slice(n+1).toLowerCase()}function ic(e){let t=rc(e);return t===`pdf`?`pdf`:t===`patch`||t===`diff`?`patch`:Xs.has(t)?`image`:$s.has(t)?`video`:ec.has(t)?`audio`:tc.has(t)?`archive`:Qs.has(t)?`code`:Zs.has(t)?`text`:`binary`}function ac(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 oc(e){return e===`text`||e===`code`||e===`patch`}function sc(e,t){return e===`pdf`?`application/pdf`:t}function cc(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 lc(e,t){if(rc(t)!==`json`)return e;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function uc(e){let t=e.replace(/^\/+/,``).replace(/\/+$/,``);return t.length===0?``:`${t}/`}function dc(e){let t=uc(e);if(t.length===0)return``;let n=t.slice(0,-1),r=n.lastIndexOf(`/`);return r===-1?``:`${n.slice(0,r+1)}`}function fc(e){let t=uc(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 pc(e,t){let n=fc(e),r=n[0];return r&&r.name===t?n.slice(1):n}function mc(e,t){let n=uc(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 hc(e,t){let n=t.trim().toLowerCase();return n.length===0?[]:e.filter(e=>{let t=(e.originalName??nc(e.key)).toLowerCase();return e.key.toLowerCase().includes(n)||t.includes(n)}).map(e=>({kind:`file`,name:e.originalName??nc(e.key),key:e.key,sizeBytes:e.sizeBytes??0,warnings:e.warnings??[]})).sort((e,t)=>e.key.localeCompare(t.key))}function gc(e,t){let n=uc(t);return n.length===0?e.map(e=>e.key):e.filter(e=>e.key.startsWith(n)).map(e=>e.key)}var _c={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 vc({kind:e,className:t,well:n=!0}){let r=e===`folder`?je:e===`image`?y:e===`pdf`?ue:e===`video`?R:e===`audio`?w:ze;return(0,Q.jsx)(`span`,{className:J(`inline-flex shrink-0 items-center justify-center`,n&&`size-7 rounded-md border`,n?_c[e]:u(_c[e]),t),"aria-hidden":!0,children:(0,Q.jsx)(H,{icon:r,className:`size-3.5`})})}function yc(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 bc(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 xc(e,t){return e===`utf8`?new TextEncoder().encode(t):bc(t)}function Sc(e,t,n){let r=new Blob([Cc(t)],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=e,a.click(),URL.revokeObjectURL(i)}function Cc(e){let t=new Uint8Array(e.byteLength);return t.set(e),t.buffer}var wc=[`console.store.object`];function Tc(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 Ec(e,t){return m({queryKey:[...wc,e],enabled:t&&e!==null,queryFn:async()=>{if(!e)throw Error(`Missing file get input`);let t=await re(e),n=Tc(t);if(n)throw n;if(!t.data)throw Error(`Empty store object`);return t.data}})}function Dc(){let e=P();return ot({mutationFn:async e=>{let t=await o({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=Tc(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:fr}),e.invalidateQueries({queryKey:wc}),e.invalidateQueries({queryKey:ci})])}})}function Oc({open:e,onOpenChange:t,storeRef:n,tenant:r,objectKey:i,sizeBytes:o,originalName:s,warnings:c=[],onDelete:l}){let u=Ec((0,Z.useMemo)(()=>i?{ref:n,key:i,...r?{tenant:r}:{}}:null,[n,i,r]),e&&i!==null),d=i?ic(i):null,f=i?nc(i):null,p=(0,Z.useMemo)(()=>u.data?xc(u.data.encoding,u.data.body):null,[u.data]),m=d?cc(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([Cc(p)],{type:sc(m,u.data.contentType)});return URL.createObjectURL(e)},[u.data,p,m]);if((0,Z.useEffect)(()=>()=>{h&&URL.revokeObjectURL(h)},[h]),!i||!d||!f)return(0,Q.jsx)(Q.Fragment,{});let g=u.data&&oc(d)&&u.data.encoding===`utf8`?u.data.body:null;return(0,Q.jsx)(Te,{open:e,onOpenChange:t,children:(0,Q.jsxs)(K,{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)(vc,{kind:d}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(Je,{className:`truncate text-sm`,children:u.data?.originalName??s??f}),(0,Q.jsxs)(Ve,{className:`font-mono text-[11px]`,children:[ac(d),(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`mx-1 text-border`,children:`·`}),Yr(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)(Tt,{className:`h-28 w-full`}),(0,Q.jsx)(Tt,{className:`h-3 w-2/3`}),(0,Q.jsx)(Tt,{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)(kc,{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)(jc,{label:`Original name`,value:u.data?.originalName??s??``}):null,(0,Q.jsx)(jc,{label:`Key`,mono:!0,value:i}),(0,Q.jsx)(jc,{label:`Type`,value:u.data?.contentType??`—`}),(0,Q.jsx)(jc,{label:`Size`,value:Yr(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)(H,{icon:a,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)(z,{type:`button`,variant:`outline`,size:`sm`,disabled:!p||u.data?.truncated,onClick:()=>{!p||!u.data||Sc(f,p,u.data.contentType)},children:[(0,Q.jsx)(H,{icon:ue,className:`size-3.5`,"aria-hidden":!0}),`Download`]}),(0,Q.jsx)(z,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`Copy key`,onClick:()=>void navigator.clipboard.writeText(i),children:(0,Q.jsx)(H,{icon:O})})]}),l?(0,Q.jsxs)(z,{type:`button`,variant:`destructive`,size:`sm`,onClick:l,"data-slot":`file-preview-delete`,children:[(0,Q.jsx)(H,{icon:ge,className:`size-3.5`,"aria-hidden":!0}),`Delete`]}):null]})]})})}function kc({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:[ac(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=rc(t);return e===`csv`||e===`tsv`?(0,Q.jsx)(Ac,{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:[lc(r,t),a?`
|
|
19
|
-
… truncated`:``]})}return(0,Q.jsxs)(`p`,{className:`px-4 py-6 text-center text-[11px] text-muted-foreground`,children:[ac(e),` — download to open`,a?` (preview truncated)`:``,`.`]})}function Ac({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 jc({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:J(`break-all text-foreground/80`,n&&`font-mono text-[10px]`),children:t})]})}function Mc(){let e=new Uint8Array(4);return crypto.getRandomValues(e),[...e].map(e=>e.toString(16).padStart(2,`0`)).join(``)}function Nc({open:e,onOpenChange:t,storeRef:n,tenant:r,prefix:i,existingKeys:a,pendingFiles:o=[]}){let{mutate:s,isPending:c,reset:l}=Dc(),[u,f]=(0,Z.useState)(``),[p,m]=(0,Z.useState)(``),[h,g]=(0,Z.useState)(``),[_,v]=(0,Z.useState)(null),[y,b]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{if(!e)return;let t=o[0]??null;v(t);let n=t?nc(t.name):``,r=Mc();m(r),f(n),g(n?Ys(n,i,r):``),b(null),l()},[e,i,o,l]);let x=async()=>{let e=u.trim();if(!_){b(`Choose a file to upload`);return}if(e.length===0){b(`Original name is required`);return}let o=h.trim().length>0?h.trim():Ys(e,i);if(a.includes(o)){b(`That key is already in this bucket`);return}let c=new Uint8Array(await _.arrayBuffer());b(null),s({ref:n,key:o,...r?{tenant:r}:{},body:yc(c),encoding:`base64`,originalName:e},{onSuccess:()=>t(!1),onError:e=>b(e instanceof Error?e.message:String(e))})};return(0,Q.jsx)(Te,{open:e,onOpenChange:t,children:(0,Q.jsxs)(K,{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)(Je,{className:`text-sm`,children:`Upload object`}),(0,Q.jsx)(Ve,{className:`font-mono text-[11px]`,children:n})]}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:[(0,Q.jsx)(Y,{label:`Original name`,hint:`Shown in the browser. Unicode is fine.`,children:(0,Q.jsx)(d,{value:u,onChange:e=>{let t=e.target.value;f(t);let n=p.length>0?p:Mc();p.length===0&&m(n),g(t.trim().length>0?Ys(t.trim(),i,n):``)},"aria-label":`Original name`,flat:!0,className:X,autoFocus:!0})}),(0,Q.jsx)(Y,{label:`Object key`,hint:`URL-safe. Generated from the original name.`,children:(0,Q.jsx)(d,{value:h,readOnly:!0,"aria-label":`Object key`,flat:!0,className:J(X,`font-mono text-muted-foreground`)})}),(0,Q.jsx)(Y,{label:`File`,hint:_?`${nc(_.name)} · ${_.size} B`:void 0,children:(0,Q.jsx)(d,{type:`file`,"aria-label":`File`,flat:!0,className:J(X,`pt-1.5`),onChange:e=>{let t=e.target.files?.[0]??null;if(v(t),!t)return;let n=nc(t.name),r=p.length>0?p:Mc();p.length===0&&m(r),f(n),g(Ys(n,i,r))}})}),y?(0,Q.jsx)(on,{slot:`file-upload-error`,children:y}):null]}),(0,Q.jsxs)(pe,{children:[(0,Q.jsx)(Xt,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(Xt,{variant:`default`,disabled:c,onClick:()=>void x(),"data-slot":`file-upload-submit`,children:c?`Uploading…`:`Upload`})]})]})})}function Pc({store:e,child:t,tenant:n,data:r,fetching:i=!1,onRefresh:a}){let[o,s]=(0,Z.useState)(``),[c,u]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(`list`),[m,h]=(0,Z.useState)(null),[g,v]=(0,Z.useState)(new Set),[y,b]=(0,Z.useState)(!1),[S,C]=(0,Z.useState)([]),[w,E]=(0,Z.useState)(null),[D,O]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{s(``),u(``),h(null),v(new Set)},[t.effectRef]);let k=r.keys??[],A=c.trim().length>0,j=(0,Z.useMemo)(()=>A?{folders:[],files:hc(k,c)}:mc(k,o),[k,o,c,A]),M=(0,Z.useMemo)(()=>[...j.folders,...j.files],[j]),N=pc(o,t.name),P=j.files.find(e=>e.key===m)??null,F=Fa(),ee=(e,t)=>{v(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},I=e=>{if(e.kind===`folder`){s(e.prefix),h(null),v(new Set);return}h(e.key)},L=()=>{if(g.size===0&&m)return[m];let e=[];for(let t of g)t.endsWith(`/`)?e.push(...gc(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)(xr,{label:`Up one folder`,children:(0,Q.jsx)(z,{type:`button`,variant:`ghost`,size:`icon-xs`,disabled:o.length===0||A,"aria-label":`Parent folder`,onClick:()=>{s(dc(o)),h(null)},children:(0,Q.jsx)(H,{icon:_,className:`size-3.5`})})}),(0,Q.jsx)(Rs,{className:`min-w-0 flex-1`,children:(0,Q.jsxs)(zs,{className:`flex-nowrap gap-1 text-[11px]`,children:[(0,Q.jsx)(Bs,{children:o.length===0||A?(0,Q.jsx)(Hs,{className:`font-mono text-[11px]`,children:t.name}):(0,Q.jsx)(Vs,{href:`#`,className:`font-mono text-[11px]`,onClick:e=>{e.preventDefault(),s(``),h(null)},children:t.name})}),N.map((e,t)=>(0,Q.jsxs)(`span`,{className:`contents`,children:[(0,Q.jsx)(Us,{className:`mx-0`}),(0,Q.jsx)(Bs,{children:t===N.length-1?(0,Q.jsx)(Hs,{className:`font-mono text-[11px]`,children:e.name}):(0,Q.jsx)(Vs,{href:`#`,className:`font-mono text-[11px]`,onClick:t=>{t.preventDefault(),s(e.prefix),h(null)},children:e.name})})]},e.prefix))]})}),(0,Q.jsxs)(`div`,{className:`relative w-44`,children:[(0,Q.jsx)(H,{icon:x,className:`pointer-events-none absolute top-1/2 left-2 size-3 -translate-y-1/2 text-muted-foreground`}),(0,Q.jsx)(d,{value:c,onChange:e=>u(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)(xr,{label:f===`list`?`Grid view`:`List view`,children:(0,Q.jsx)(z,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":f===`list`?`Grid view`:`List view`,onClick:()=>p(e=>e===`list`?`grid`:`list`),children:(0,Q.jsx)(H,{icon:f===`list`?ke:l,className:`size-3.5`})})}),(0,Q.jsx)(xr,{label:`Upload into this folder`,children:(0,Q.jsxs)(z,{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([]),b(!0)},children:[(0,Q.jsx)(H,{icon:Pe,className:`size-3.5`}),`Upload`]})}),(0,Q.jsx)(xr,{label:L().length>0?`Delete ${L().length} object${L().length===1?``:`s`}`:`Select objects to delete`,children:(0,Q.jsxs)(z,{type:`button`,variant:`destructive`,size:L().length>0?`xs`:`icon-xs`,disabled:L().length===0,onClick:()=>E(L()),"aria-label":`Delete selected`,"data-slot":`file-delete`,children:[(0,Q.jsx)(H,{icon:ge,className:`size-3.5`}),L().length>0?L().length:null]})}),(0,Q.jsx)(xr,{label:`Reload from the store`,children:(0,Q.jsx)(z,{type:`button`,variant:`ghost`,size:`icon-xs`,disabled:i,"aria-label":`Refresh`,"data-slot":`browse-refresh`,onClick:a,children:(0,Q.jsx)(H,{icon:T,className:i?`size-3.5 animate-spin`:`size-3.5`})})})]}),(0,Q.jsxs)(`div`,{className:J(`flex min-h-0 flex-1 flex-col`,D&&`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),b(!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)(Sr,{role:`status`,"data-slot":`files-empty`,children:(0,Q.jsxs)(Fr,{children:[(0,Q.jsx)(Cr,{variant:`icon`,children:(0,Q.jsx)(H,{icon:je})}),(0,Q.jsx)(kr,{children:A?`No matching objects`:`This folder is empty`}),(0,Q.jsx)(Mr,{children:A?`Try another name or clear the filter.`:`Drop files here or upload into this prefix.`})]})})}):f===`grid`?(0,Q.jsx)(Ic,{entries:M,selectedKey:m,checked:g,onOpen:I,onToggle:ee}):(0,Q.jsx)(Fc,{entries:M,selectedKey:m,checked:g,searching:A,onOpen:I,onToggle:ee}),(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`,i?` · refreshing`:``]}),(0,Q.jsx)(`span`,{children:`Drop to upload · click a folder to open · click a file to inspect`})]})]}),(0,Q.jsx)(Oc,{open:m!==null,onOpenChange:e=>{e||h(null)},storeRef:e.ref,tenant:n,objectKey:m,sizeBytes:P?.sizeBytes,originalName:P?.name,warnings:P?.warnings,onDelete:m?()=>{E([m])}:void 0}),(0,Q.jsx)(Nc,{open:y,onOpenChange:b,storeRef:e.ref,tenant:n,prefix:o,existingKeys:k.map(e=>e.key),pendingFiles:S}),(0,Q.jsx)(Ps,{open:w!==null,onOpenChange:e=>{e||E(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:F.isPending,error:F.isError?F.error.message:null,onConfirm:t=>{w&&F.mutate({ref:e.ref,...n?{tenant:n}:{},keys:w,confirmation:t.confirmation,reason:t.reason},{onSuccess:()=>{E(null),v(new Set),h(null),a()}})}})]})}function Fc({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:J(`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)(Ls,{checked:n.has(s),onCheckedChange:e=>o(s,e),"aria-label":`Select ${e.name}`})}),(0,Q.jsx)(vc,{kind:e.kind===`folder`?`folder`:ic(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)(H,{icon:a,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`:ac(ic(e.name))}),(0,Q.jsx)(`span`,{className:`w-16 text-right font-mono text-[11px] tabular-nums text-muted-foreground`,children:Yr(e.sizeBytes)})]},s)})]})}function Ic({entries:e,selectedKey:t,checked:n,onOpen:r,onToggle:i}){return(0,Q.jsx)(`div`,{className:`grid min-h-0 flex-1 auto-rows-min grid-cols-[repeat(auto-fill,minmax(7.5rem,1fr))] content-start gap-2 overflow-auto p-3`,role:`list`,"aria-label":`Objects`,children:e.map(e=>{let a=e.kind===`folder`?e.prefix:e.key,o=e.kind===`file`&&e.key===t;return(0,Q.jsxs)(`button`,{type:`button`,role:`listitem`,"data-slot":e.kind===`folder`?`file-folder`:`file-object`,className:J(`relative flex flex-col items-center gap-2 rounded-lg border px-2 py-3 text-center`,o?`border-sky-500/40 bg-sky-500/10`:`border-border/50 hover:border-border hover:bg-muted/40`),onClick:()=>r(e),onDoubleClick:()=>r(e),children:[(0,Q.jsx)(`span`,{className:`absolute top-1.5 left-1.5`,onClick:e=>e.stopPropagation(),children:(0,Q.jsx)(Ls,{checked:n.has(a),onCheckedChange:e=>i(a,e),"aria-label":`Select ${e.name}`})}),(0,Q.jsx)(vc,{kind:e.kind===`folder`?`folder`:ic(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`:Yr(e.sizeBytes)})]},a)})})}function Lc(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 Rc(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 zc(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}var Bc=(e,t)=>Math.abs(e-t)<1.01,Vc=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},Hc,Uc=()=>{if(Hc!==void 0)return Hc;if(typeof navigator>`u`)return Hc=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return Hc=!0;let e=navigator.maxTouchPoints;return Hc=navigator.platform===`MacIntel`&&e!==void 0&&e>0},Wc=e=>{let{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},Gc=e=>e,Kc=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},qc=(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(Wc(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(Wc(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(r):r()});return a.observe(n,{box:`border-box`}),()=>{a.unobserve(n)}},Jc={passive:!0},Yc=typeof window>`u`||`onscrollend`in window,Xc=(e,t,n)=>{let r=e.scrollElement;if(!r)return;let i=e.targetWindow;if(!i)return;let a=e.options.useScrollendEvent&&Yc,o=0,s=a?null:Vc(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,Jc),a&&r.addEventListener(`scrollend`,u,Jc),()=>{r.removeEventListener(`scroll`,l),a&&r.removeEventListener(`scrollend`,u)}},Zc=(e,t)=>Xc(e,t,t=>{let{horizontal:n,isRtl:r}=e.options;return n?t.scrollLeft*(r&&-1||1):t.scrollTop}),Qc=(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`]},$c=(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})},el=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:Gc,rangeExtractor:Kc,onChange:()=>{},measureElement:Qc,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=Rc(()=>(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,!(!Uc()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};e.addEventListener(`touchstart`,t,Jc),e.addEventListener(`touchend`,n,Jc),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&&(Uc()&&(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=Rc(()=>[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=Rc(()=>[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=Lc(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=Rc(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,r)=>e.length===0||t===0?(this.range=null,null):(this.range=rl(e,t,n,r,r===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Rc(()=>{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=Rc(()=>[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 zc(t[tl(0,t.length-1,r?e=>n[e*2]:e=>zc(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:Uc()&&(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&&Bc(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()}},tl=(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 nl(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 rl(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=nl(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=tl(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 il=typeof document<`u`?Z.useLayoutEffect:Z.useEffect;function al({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,Zi.flushSync)(i):i()),(o=r.onChange)==null||o.call(r,t,n)}},[l]=Z.useState(()=>{let e=new el(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),il(()=>l._didMount(),[]),il(()=>(o(l),l._willUpdate())),il(()=>{s(l)}),l}function ol(e){return al({observeElementRect:qc,observeElementOffset:Zc,scrollToFn:$c,...e})}var sl=188;function cl({items:e,ariaLabel:t,trigger:n,triggerClassName:r}){let i=It(),a=(0,Z.useRef)(null),[o,s]=(0,Z.useState)(null),c=o!==null;(0,Z.useEffect)(()=>{if(!c)return;let e=()=>s(null),t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,e),window.removeEventListener(`keydown`,t)}},[c]);let l=()=>{if(c){s(null);return}let e=a.current;if(!e)return;let t=e.getBoundingClientRect();s({top:t.bottom+4,left:Math.max(8,t.right-sl)})};return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{ref:a,type:`button`,"aria-label":t,"aria-haspopup":`menu`,"aria-expanded":c,onClick:e=>{e.stopPropagation(),l()},className:r,children:n}),c&&o&&typeof document<`u`?(0,Zi.createPortal)((0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`fixed inset-0 z-40`,onPointerDown:()=>s(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:o.top,left:o.left,width:sl},initial:i?{opacity:0}:{opacity:0,scale:.96,y:-4},animate:i?{opacity:1}:{opacity:1,scale:1,y:0},transition:i?{duration:0}:At,children:e.map(e=>(0,Q.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{s(null),e.onSelect()},className:J(`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 ll({rowEl:e,id:t,index:n,onInsertRow:r,onDeleteRow:i,onEnter:a,onLeave:o}){if((0,Z.useEffect)(()=>(window.addEventListener(`scroll`,o,!0),()=>window.removeEventListener(`scroll`,o,!0)),[o]),!e||typeof document>`u`)return null;let s=e.getBoundingClientRect();return(0,Zi.createPortal)((0,Q.jsx)(`div`,{style:{position:`fixed`,top:s.top+s.height/2,left:s.left,transform:`translate(-50%, -50%)`,zIndex:40},onPointerEnter:a,onPointerLeave:o,children:(0,Q.jsx)(cl,{ariaLabel:`Row ${n+1} options`,triggerClassName:`flex h-6 w-2 items-center justify-center rounded-full bg-primary text-primary-foreground shadow-sm transition-colors hover:bg-primary/90`,trigger:(0,Q.jsx)(H,{icon:g,className:`size-3`}),items:[...r?[{label:`Insert before`,icon:(0,Q.jsx)(H,{icon:te}),onSelect:()=>r(n,`before`)},{label:`Insert after`,icon:(0,Q.jsx)(H,{icon:M}),onSelect:()=>r(n,`after`)}]:[],...i?[{label:`Delete row`,icon:(0,Q.jsx)(H,{icon:ge}),destructive:!0,onSelect:()=>i(t,n)}]:[]]})}),document.body)}var ul=`48px`,dl=J(`[&_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!`),fl=`inset 0 1px 0 var(--color-sky-500)`;function pl(e){return J(`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 ml(e){return e===`right`?`justify-end`:e===`center`?`justify-center`:`justify-start`}function hl(e){return e===`right`?`text-right`:e===`center`?`text-center`:`text-left`}function gl(e,t){return t.cell?t.cell(e):e[t.key]}function _l(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 vl(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 yl(e,t,n){return e?{inRange:Oi(e,t,n),isHead:e.head.row===t&&e.head.col===n}:{inRange:!1,isHead:!1}}function bl({count:e,columns:t,selectable:n,rowHeight:r,slack:i=!0}){return(0,Q.jsx)(Q.Fragment,{children:Array.from({length:e},(e,a)=>(0,Q.jsxs)(`tr`,{style:{height:r},children:[n?(0,Q.jsx)(`td`,{className:`px-4`}):null,t.map(e=>(0,Q.jsx)(`td`,{className:J(`px-4`,hl(e.align)),children:(0,Q.jsx)(`div`,{className:J(`h-3 animate-pulse rounded-full bg-muted`,e.align===`right`?`ml-auto w-10`:`w-2/3`)})},e.key)),i?(0,Q.jsx)(`td`,{"aria-hidden":!0}):null]},a))})}function xl(e,t,n,r){return[...n?[{label:`Insert before`,icon:(0,Q.jsx)(H,{icon:_}),onSelect:()=>n(t,`before`)},{label:`Insert after`,icon:(0,Q.jsx)(H,{icon:j}),onSelect:()=>n(t,`after`)}]:[],...r?[{label:`Delete column`,icon:(0,Q.jsx)(H,{icon:ge}),destructive:!0,onSelect:()=>r(e.key,t)}]:[]]}function Sl({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,Zi.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)(cl,{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)(H,{icon:F,className:`size-3`}),items:xl(e,t,r,i)})}),document.body)}function Cl({columns:e,rowHeight:t,reduce:n,thRefs:r,selectable:i,allSelected:a,someSelected:o,onToggleAll:s,sort:c,onToggleSort:l,resizable:u,onResizeStart:d,onResizeMove:f,onResizeEnd:p,reorderable:m,dragKey:h,dropIndex:g,onReorderStart:_,onReorderMove:v,onReorderEnd:y,onInsertColumn:b,onDeleteColumn:x,onColumnRename:S,activeColumn:C,onColumnActivate:w,onColumnDeactivate:T,slack:E=!0}){let D=!!(b||x),O=e.findIndex(e=>e.key===C),k=O>=0?e[O]:void 0;return(0,Q.jsxs)(Q.Fragment,{children:[D&&C&&k?(0,Q.jsx)(Sl,{column:k,index:O,thRefs:r,onInsertColumn:b,onDeleteColumn:x,onEnter:()=>w?.(C),onLeave:()=>T?.()}):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)(Ls,{checked:a,indeterminate:o&&!a,onCheckedChange:()=>s(),"aria-label":`Select all rows`,className:dl})})}):null,e.map((i,a)=>{let o=c?.key===i.key,s=h===i.key,b=C===i.key;return(0,Q.jsxs)(`th`,{ref:e=>{r.current[i.key]=e},onPointerEnter:()=>w?.(i.key),onPointerLeave:()=>T?.(),style:b?{boxShadow:fl}:void 0,"aria-sort":o?c?.direction===`asc`?`ascending`:`descending`:void 0,"data-drop":h?g===a:void 0,"data-dropend":h?g===e.length&&a===e.length-1:void 0,className:J(`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:J(`flex h-full w-full min-w-0 items-center`,ml(i.align)),style:{height:t},animate:n?{opacity:s?.5:1}:{scale:s?1.04:1,opacity:s?.5:1},transition:Mt,children:[m?(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Reorder ${i.key}`,onPointerDown:e=>_(i.key,e),onPointerMove:v,onPointerUp:y,className:`flex h-full w-6 cursor-grab touch-none items-center justify-center text-muted-foreground/60 transition-colors hover:text-foreground active:cursor-grabbing`,children:(0,Q.jsx)(H,{icon:ce,className:`size-3.5`})}):null,i.sortable?(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>l(i.key),className:J(`flex h-full min-w-0 flex-1 select-none items-center gap-1 px-4 transition-colors hover:text-foreground`,ml(i.align),o&&`text-foreground`),children:[i.header,(0,Q.jsx)(Lt.span,{"aria-hidden":!0,className:`inline-flex shrink-0`,animate:{rotate:o&&c?.direction===`desc`?180:0,opacity:o?1:.35},transition:n?{duration:0}:{duration:.18,ease:jt},children:(0,Q.jsx)(H,{icon:te,className:`size-3`})})]}):S?(0,Q.jsx)(`input`,{defaultValue:typeof i.header==`string`?i.header:i.key,"aria-label":`Rename ${i.key}`,onBlur:e=>S(i.key,e.target.value),onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()},className:J(`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`,hl(i.align))}):(0,Q.jsx)(`div`,{className:J(`min-w-0 flex-1 truncate px-4`,hl(i.align)),children:i.header})]}),u?(0,Q.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize ${i.key}`,onPointerDown:e=>d(i.key,e),onPointerMove:f,onPointerUp:p,className:`absolute top-0 right-0 h-full w-1.5 cursor-col-resize touch-none bg-transparent transition-colors hover:bg-primary/40`}):null]},i.key)}),E?(0,Q.jsx)(`th`,{className:`sticky top-0 z-10 border-b border-border/60 bg-background p-0`,"aria-hidden":!0}):null]})})]})}function wl({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 Tl({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 El({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=_l(e.row,n),i=_l(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 Dl({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 Ol=`input, textarea, button, [role='checkbox']`,kl=4;function Al(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 jl(e,t,n){return e?e.anchor.row===t&&e.anchor.col===n&&e.head.row===t&&e.head.col===n:!1}function Ml(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(Ol))return;t.current=!0,n.current=!1,i.current={x:l.clientX,y:l.clientY,row:e,col:s},r.current=!l.shiftKey&&jl(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||Al(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)>kl&&(n.current=!0,r.current=!1);let c=Al(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 Nl({data:e,columns:t,getRowId:n,selectable:r=!1,selectedRowIds:i,defaultSelectedRowIds:a,onSelectionChange:o,sort:s,defaultSort:c=null,onSortChange:l,resizable:u=!1,minColumnWidth:d=64,onColumnResize:f,reorderable:p=!1,onColumnOrderChange:m,onCellEdit:h,onColumnRename:g,onInsertRow:_,onDeleteRow:v,onInsertColumn:y,onDeleteColumn:b,onRowDoubleClick:x,onRowContextMenu:S,onViewportContextMenu:C,cellRange:w=null,onCellRangeChange:T,onCellActivate:E,rowHeight:D=48,height:O=440,overscan:k=10,onEndReached:A,loading:j=!1,skeletonRows:M=3,emptyState:N=`No data`,className:P}){let F=!!It(),ee=(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:te,dropIndex:z,startReorder:B,moveReorder:V,endReorder:H}=wl({columns:t,thRefs:I,onColumnOrderChange:m}),{sort:ne,sortedRows:re,toggleSort:U}=El({rows:L,columns:t,sort:s,defaultSort:c,onSortChange:l}),{widths:ie,startResize:ae,moveResize:oe,endResize:se}=Tl({orderedColumns:R,thRefs:I,minColumnWidth:d,onColumnResize:f}),{selected:ce,allSelected:le,someSelected:ue,toggleAll:de,toggleRow:fe}=Dl({sortedRows:re,selectedRowIds:i,defaultSelectedRowIds:a,onSelectionChange:o}),pe=Ml({enabled:T!==void 0,range:w,onChange:T,onActivate:E}),me=ol({count:re.length,getScrollElement:()=>ee.current,estimateSize:()=>D,overscan:k}),W=me.getVirtualItems(),he=me.getTotalSize(),ge=W[0],_e=W[W.length-1],ve=ge?ge.start:0,ye=_e?he-_e.end:0,be=!!(_||v),xe=R.length>0&&R.every(e=>ie[e.key]!=null),Se=(0,Z.useRef)(!1);(0,Z.useEffect)(()=>{j||(Se.current=!1)},[j]);let Ce=(0,Z.useCallback)(()=>{let e=ee.current;!e||!A||j||Se.current||e.scrollHeight-e.scrollTop-e.clientHeight<D*4&&(Se.current=!0,A())},[A,j,D]),[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)},[]),ke=(0,Z.useRef)({}),[G,Ae]=(0,Z.useState)(null),je=(0,Z.useRef)(null),Me=(0,Z.useCallback)((e,t)=>{je.current&&clearTimeout(je.current),je.current=null,Ae({id:e,index:t})},[]),Ne=(0,Z.useCallback)(()=>{je.current&&clearTimeout(je.current),je.current=setTimeout(()=>Ae(null),100)},[]),K=G?ke.current[G.id]??null:null,q=t.length+ +!!r,Pe=!R.some(e=>e.fill&&ie[e.key]==null),Fe=q+ +!!Pe;return(0,Q.jsxs)(`div`,{className:J(`w-full overflow-hidden border border-border/60 bg-background text-sm`,P),children:[(0,Q.jsx)(`div`,{ref:ee,"data-slot":`table-scroller`,onScroll:Ce,onPointerDown:pe.onScrollerPointerDown,onPointerMove:pe.onScrollerPointerMove,onPointerUp:pe.onPointerUp,onPointerCancel:pe.onPointerUp,onContextMenu:e=>{if(!C)return;let t=e.target;t instanceof Element&&t.closest(`[data-slot='table-row']`)||(e.preventDefault(),C())},className:J(`overflow-auto`,T?`select-none`:void 0),style:{height:O},children:(0,Q.jsxs)(`table`,{className:J(`border-collapse`,xe?`w-max min-w-full`:`min-w-full`),style:{tableLayout:`fixed`},children:[(0,Q.jsxs)(`colgroup`,{children:[r?(0,Q.jsx)(`col`,{style:{width:ul}}):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)}),Pe?(0,Q.jsx)(`col`,{}):null]}),(0,Q.jsx)(Cl,{columns:R,rowHeight:D,reduce:F,thRefs:I,selectable:r,allSelected:le,someSelected:ue,onToggleAll:de,sort:ne,onToggleSort:U,resizable:u,onResizeStart:ae,onResizeMove:oe,onResizeEnd:se,reorderable:p,dragKey:te,dropIndex:z,onReorderStart:B,onReorderMove:V,onReorderEnd:H,onInsertColumn:y,onDeleteColumn:b,onColumnRename:g,activeColumn:we,onColumnActivate:De,onColumnDeactivate:Oe,slack:Pe}),(0,Q.jsx)(`tbody`,{children:re.length===0?j?(0,Q.jsx)(bl,{count:M,columns:R,selectable:r,rowHeight:D,slack:Pe}):(0,Q.jsx)(`tr`,{children:(0,Q.jsx)(`td`,{colSpan:Fe,className:`px-4 py-8 text-center text-muted-foreground`,children:N})}):(0,Q.jsxs)(Q.Fragment,{children:[ve>0?(0,Q.jsx)(`tr`,{children:(0,Q.jsx)(`td`,{colSpan:Fe,style:{height:ve,padding:0,border:`none`}})}):null,W.map(e=>{let t=re[e.index];if(!t)return null;let n=ce.has(t.id);return(0,Q.jsxs)(`tr`,{ref:e=>{ke.current[t.id]=e},"data-slot":`table-row`,"data-selected":n,style:{height:D},onPointerEnter:be?()=>Me(t.id,e.index):void 0,onPointerLeave:be?Ne:void 0,onContextMenu:e=>{S&&(e.preventDefault(),e.stopPropagation(),S(t.row,t.id))},onDoubleClick:e=>{if(!x)return;let n=e.target;n instanceof Element&&n.closest(`input, textarea, button, [role='checkbox'], [data-slot='cell-display']`)||x(t.row,t.id)},className:J(`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:J(`px-4 align-middle`,pl(n),n&&`bg-sky-500/10`),children:(0,Q.jsx)(`div`,{className:`flex items-center justify-center`,style:{height:D},children:(0,Q.jsx)(Ls,{checked:n,onCheckedChange:()=>fe(t.id),"aria-label":`Select row ${e.index+1}`,className:dl})})}):null,R.map((r,i)=>{let a=yl(w,e.index,i);return(0,Q.jsx)(`td`,{"data-slot":`table-cell`,"data-row":String(e.index),"data-col":String(i),"data-range":a.inRange?`in`:void 0,"data-range-head":a.isHead?`true`:void 0,className:J(`relative h-full cursor-cell overflow-hidden p-0`,hl(r.align),pl(n),!a.inRange&&`has-[[data-pending=true]]:bg-amber-500/10`,a.inRange&&`bg-sky-500/15`,a.isHead&&`z-[1] shadow-[inset_0_0_0_2px_color-mix(in_oklab,var(--color-sky-500)_45%,transparent)] has-[input]:shadow-none`),onPointerDown:t=>pe.onCellPointerDown(e.index,i,t),children:!r.cell&&r.editable?(0,Q.jsx)(`span`,{className:`absolute inset-0 flex items-center px-4`,children:(0,Q.jsx)(vi,{value:vl(t.row,r.key),label:typeof r.header==`string`?r.header:r.key,onChange:e=>h?.(t.id,r.key,e)})}):gl(t.row,r)},r.key)}),Pe?(0,Q.jsx)(`td`,{"aria-hidden":!0,className:J(pl(n),n&&`bg-sky-500/10`)}):null]},t.id)}),ye>0?(0,Q.jsx)(`tr`,{children:(0,Q.jsx)(`td`,{colSpan:Fe,style:{height:ye,padding:0,border:`none`}})}):null,j?(0,Q.jsx)(bl,{count:M,columns:R,selectable:r,rowHeight:D,slack:Pe}):null]})})]})}),be&&G?(0,Q.jsx)(ll,{rowEl:K,id:G.id,index:G.index,onInsertRow:_,onDeleteRow:v,onEnter:()=>Me(G.id,G.index),onLeave:Ne}):null]})}function Pl(){return ot({mutationFn:async e=>{let t=await v(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 Fl({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)(h,{children:[(0,Q.jsx)(L,{render:a=>(0,Q.jsx)(z,{...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)(H,{icon:ke,className:`size-3`,"aria-hidden":!0})})}),(0,Q.jsx)(C,{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:Il(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:Il(s.value)}),(0,Q.jsxs)(h,{children:[(0,Q.jsx)(L,{render:e=>(0,Q.jsx)(z,{...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)(H,{icon:Ye,className:`size-3`,"aria-hidden":!0})})}),(0,Q.jsx)(C,{side:`top`,className:`text-[11px]`,children:`Hide cleartext`})]})]})}function Il(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 Ll({open:e,onOpenChange:t,model:n,row:r,facet:i,storeRef:a,childName:o,tenant:s,masked:l=!1,asGate:u=null,asUserId:f=null,onDeleteRow:p}){let m=Pa(),[h,g]=(0,Z.useState)(`fields`),[_,v]=(0,Z.useState)(!1),[y,b]=(0,Z.useState)({}),[x,S]=(0,Z.useState)(null),C=(0,Z.useMemo)(()=>n.columns.filter(e=>e.editable),[n.columns]),w=n.editable&&(i===`sql`||i===`kv`)&&C.length>0;(0,Z.useEffect)(()=>{e&&(g(`fields`),v(!1),S(null))},[e,r]);let T=(0,Z.useMemo)(()=>{if(!r)return``;try{return JSON.stringify(r.cells,null,2)}catch{return`[unserializable row]`}},[r]);if(!r)return(0,Q.jsx)(Q.Fragment,{});let E=()=>{let e={};for(let t of C)e[t.key]=Rl(t.type,r.cells[t.key]);b(e),S(null),v(!0),g(`fields`)},D=async()=>{S(null);let e={};for(let t of C){let n=y[t.key]??``;t.pii&&n.trim()===``||n!==Rl(t.type,r.cells[t.key])&&(e[t.key]=li(t.type,n))}if(Object.keys(e).length===0){v(!1);return}try{await m.mutateAsync({ref:a,...i===`sql`?{child:o,id:r.id}:{key:r.id},...s?{tenant:s}:{},...u?{asGate:u}:{},...f?{asUserId:f}:{},patch:ki(e),commit:!0}),v(!1)}catch(e){S(e instanceof Error?e.message:String(e))}};return(0,Q.jsx)(Te,{open:e,onOpenChange:t,children:(0,Q.jsxs)(K,{side:`right`,showOverlay:!1,className:`gap-0 p-0 sm:max-w-md`,"data-slot":`store-row-detail-sheet`,"data-editing":_?`true`:`false`,children:[(0,Q.jsxs)(Oe,{className:`gap-2 border-b border-border/50`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-0.5 pr-8`,children:[(0,Q.jsxs)(Je,{className:`text-sm`,children:[_?`Edit`:`Row`,` `,(0,Q.jsx)(`span`,{className:`font-mono`,children:r.id})]}),(0,Q.jsxs)(Ve,{className:`font-mono text-[11px]`,children:[a,i===`sql`?`/${o}`:``]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-4`,role:`tablist`,"aria-label":`Row detail tabs`,children:[(0,Q.jsx)(zl,{active:h===`fields`,onClick:()=>g(`fields`),id:`fields`,children:`Fields`}),(0,Q.jsx)(zl,{active:h===`json`,onClick:()=>g(`json`),id:`json`,children:`JSON`})]})]}),(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto px-4 pb-2`,children:h===`fields`?(0,Q.jsx)(`ul`,{className:`flex flex-col divide-y divide-border/50`,"data-slot":`row-fields`,children:n.columns.map(e=>{let t=r.cells[e.key],n=e.pii&&l&&hi(t),i=_&&e.editable;return(0,Q.jsxs)(`li`,{className:`flex items-baseline gap-3 py-1.5`,children:[(0,Q.jsxs)(`span`,{className:`flex w-32 shrink-0 items-center gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`truncate font-mono text-[11px] font-medium text-muted-foreground`,children:e.key}),(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[9px] text-muted-foreground/60`,children:e.type===`integer`||e.type===`number`?`123`:e.type===`json`?`{ }`:`abc`}),e.primaryKey?(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[9px] text-amber-600 dark:text-amber-400`,children:`PK`}):null,e.pii?(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[9px] text-sky-600 dark:text-sky-400`,children:`PII`}):null]}),i?e.type===`json`?(0,Q.jsx)(`textarea`,{value:y[e.key]??``,onChange:t=>b(n=>({...n,[e.key]:t.target.value})),"aria-label":e.key,rows:3,className:`min-h-16 min-w-0 flex-1 rounded-none border-0 bg-transparent font-mono text-[11px] outline-none`}):(0,Q.jsx)(d,{value:y[e.key]??``,onChange:t=>b(n=>({...n,[e.key]:t.target.value})),type:e.type===`integer`||e.type===`number`?`number`:`text`,"aria-label":e.key,flat:!0,className:J(X,`min-w-0 flex-1 px-0 font-mono`)}):n?(0,Q.jsx)(Fl,{refName:a,child:o,...s?{tenant:s}:{},rowId:r.id,column:e.key,maskedValue:t}):(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 font-mono text-[11px] break-words`,dir:di(t)?`rtl`:`ltr`,children:si(t)})]},e.key)})}):(0,Q.jsx)(`div`,{className:`rounded-md border border-border/60`,"data-slot":`row-json`,children:(0,Q.jsx)(Wr,{json:T,dataSlot:`store-row-json`,className:`flex max-h-none overflow-auto`})})}),x?(0,Q.jsx)(on,{slot:`row-detail-error`,children:x}):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-2`,children:[(0,Q.jsxs)(z,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{v(!1),S(null)},disabled:m.isPending,"data-slot":`row-detail-cancel`,children:[(0,Q.jsx)(H,{icon:c,className:`size-3.5`,"aria-hidden":!0}),`Cancel`]}),(0,Q.jsxs)(z,{type:`button`,size:`sm`,onClick:()=>void D(),disabled:m.isPending,"data-slot":`row-detail-save`,children:[(0,Q.jsx)(H,{icon:Ke,className:`size-3.5`,"aria-hidden":!0}),m.isPending?`Saving…`:`Save`]})]}):w?(0,Q.jsxs)(z,{type:`button`,variant:`outline`,size:`sm`,onClick:E,"data-slot":`row-detail-edit`,children:[(0,Q.jsx)(H,{icon:A,className:`size-3.5`,"aria-hidden":!0}),`Edit`]}):(0,Q.jsx)(`span`,{}),!_&&p?(0,Q.jsxs)(z,{type:`button`,variant:`destructive`,size:`sm`,onClick:()=>p(r),"data-slot":`row-detail-delete`,children:[(0,Q.jsx)(H,{icon:ge,className:`size-3.5`,"aria-hidden":!0}),`Delete 1 row`]}):null]})]})})}function Rl(e,t){if(t==null||hi(t))return``;if(e===`json`)try{return JSON.stringify(t,null,2)}catch{return``}if(typeof t==`string`)return t;if(typeof t==`number`||typeof t==`boolean`)return String(t);try{return JSON.stringify(t)}catch{return``}}function zl({active:e,onClick:t,id:n,children:r}){return(0,Q.jsx)(`button`,{type:`button`,role:`tab`,id:`tab-${n}`,"aria-selected":e,onClick:t,className:J(`px-2 py-1.5 text-[10px] font-semibold tracking-[0.08em] uppercase transition-colors hover:bg-muted/50`,e?`text-foreground`:`text-muted-foreground hover:text-foreground`),"data-slot":`row-tab-${n}`,children:r})}function Bl({open:e,onOpenChange:t,storeRef:n,childName:r,tenant:i,existingKeys:a}){let{mutate:o,isPending:s,reset:c}=Pa(),[l,u]=(0,Z.useState)(`${r}:`),[f,p]=(0,Z.useState)(`{
|
|
20
|
-
|
|
21
|
-
}`),[m,h]=(0,Z.useState)(``),[g,_]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{e&&(u(`${r}:`),p(`{
|
|
22
|
-
|
|
23
|
-
}`),h(``),_(null),c())},[e,r,c]),(0,Q.jsx)(Te,{open:e,onOpenChange:t,children:(0,Q.jsxs)(K,{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)(Je,{className:`text-sm`,children:`Add key`}),(0,Q.jsx)(Ve,{className:`font-mono text-[11px]`,children:n})]}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:[(0,Q.jsx)(Y,{label:`Key`,children:(0,Q.jsx)(d,{value:l,onChange:e=>u(e.target.value),"aria-label":`Key`,flat:!0,className:J(X,`font-mono`),autoFocus:!0})}),(0,Q.jsx)(Y,{label:`Value`,children:(0,Q.jsx)(`textarea`,{value:f,onChange:e=>p(e.target.value),"aria-label":`JSON value`,spellCheck:!1,className:`min-h-40 w-full flex-1 resize-y rounded-none border-0 bg-transparent px-4 py-1.5 font-mono text-[11px] leading-5 outline-none`})}),(0,Q.jsx)(Y,{label:`TTL`,children:(0,Q.jsx)(d,{value:m,onChange:e=>h(e.target.value),"aria-label":`TTL`,placeholder:`30m`,flat:!0,className:J(X,`font-mono`)})}),g?(0,Q.jsx)(on,{slot:`kv-add-error`,children:g}):null]}),(0,Q.jsxs)(pe,{children:[(0,Q.jsx)(Xt,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(Xt,{variant:`default`,disabled:s,onClick:()=>{let e=l.trim();if(e.length===0||e.endsWith(`:`)){_(`Key needs a name after the prefix`);return}if(a.includes(e)){_(`That key is already on this page`);return}let r=Jr(f);if(!r.ok){_(r.error);return}let s=Kr(m);if(s===void 0){_(`TTL must be a duration like 30m, 1h, or empty`);return}_(null),o({ref:n,key:e,...i?{tenant:i}:{},patch:{value:r.value,...s===null?{}:{ttl:s}},commit:!0},{onSuccess:()=>t(!1),onError:e=>_(e instanceof Error?e.message:String(e))})},"data-slot":`kv-add-submit`,children:s?`Adding…`:`Add key`})]})]})})}function Vl({open:e,onOpenChange:t,storeRef:n,childName:r,tenant:i,columns:a,asGate:o=null,asUserId:s=null}){let{mutate:c,isPending:l,reset:u}=Pa(),f=(0,Z.useMemo)(()=>gi(a),[a]),[p,m]=(0,Z.useState)({}),[h,g]=(0,Z.useState)(!1),[_,v]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{e&&(m(xi(f)),v(null),u())},[e,f,u]);let y=(e,t)=>{m(n=>({...n,[e]:t}))},b=()=>{let e=wi(f,p);if(!e.ok){v(e.error);return}v(null),c({ref:n,child:r,...i?{tenant:i}:{},...o?{asGate:o}:{},...s?{asUserId:s}:{},patch:e.patch,commit:!0},{onSuccess:()=>{if(h){m(xi(f));return}t(!1)},onError:e=>v(e instanceof Error?e.message:String(e))})};return(0,Q.jsx)(Te,{open:e,onOpenChange:t,children:(0,Q.jsxs)(K,{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||b())},children:[(0,Q.jsxs)(Oe,{className:`gap-1 border-b border-border/50`,children:[(0,Q.jsxs)(Je,{className:`text-sm`,children:[`Add new row to `,r]}),(0,Q.jsx)(Ve,{className:`font-mono text-[11px]`,children:n})]}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:[f.map(e=>{let t=p[e.key]??``;return(0,Q.jsx)(Y,{label:e.key,hint:e.type===`integer`||e.type===`number`?`integer`:e.type,children:e.type===`json`?(0,Q.jsx)(`textarea`,{value:t,onChange:t=>y(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)(d,{value:t,onChange:t=>y(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:J(X,`font-mono`),autoFocus:e.key===`id`})},e.key)}),_?(0,Q.jsx)(on,{slot:`sql-insert-error`,children:_}):null]}),(0,Q.jsx)(Zt,{label:`Create more`,children:(0,Q.jsx)(La,{size:`sm`,checked:h,onCheckedChange:g,ariaLabel:`Create more`})}),(0,Q.jsxs)(pe,{children:[(0,Q.jsx)(Xt,{split:!0,onClick:()=>t(!1),children:`Cancel`}),(0,Q.jsx)(Xt,{variant:`default`,disabled:l,onClick:b,"data-slot":`sql-insert-submit`,children:l?`Saving…`:`Save`})]})]})})}function Hl({value:e,type:t}){return e?(0,Q.jsxs)(`span`,{className:J(`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 Ul({file:e,lines:t,status:n=`streaming`,open:r,defaultOpen:i=!0,onOpenChange:a,collapseOnComplete:o=!0,maxHeight:s=220,language:c=`typescript`,copyText:l,onCopy:u,className:d}){let p=It()??!1,m=(0,Z.useId)(),h=`${m}-trigger`,g=`${m}-content`,_=(0,Z.useRef)(null),v=(0,Z.useRef)(n),y=(0,Z.useRef)(void 0),[b,x]=(0,Z.useState)(!1),[S,C]=(0,Z.useState)(i),w=r??S,T=n===`streaming`,E=t.filter(e=>e.type===`added`).length,D=t.filter(e=>e.type===`removed`).length,k=!!(l||u),A=jo(t.map(e=>e.content).join(`
|
|
24
|
-
`),c),j=(0,Z.useCallback)(e=>{r===void 0&&C(e),a?.(e)},[a,r]);(0,Z.useEffect)(()=>{v.current!==`streaming`&&n===`streaming`&&j(!0),v.current===`streaming`&&n===`complete`&&o&&j(!1),v.current=n},[o,j,n]),(0,Z.useEffect)(()=>()=>{y.current&&window.clearTimeout(y.current)},[]),(0,Z.useLayoutEffect)(()=>{let e=_.current;if(!e||!w||!T)return;let t=requestAnimationFrame(()=>{e.scrollHeight<=e.clientHeight||(typeof e.scrollTo==`function`?e.scrollTo({top:e.scrollHeight,behavior:p?`auto`:`smooth`}):e.scrollTop=e.scrollHeight)});return()=>cancelAnimationFrame(t)});let N=(0,Z.useCallback)(async()=>{u?await u():l&&await navigator.clipboard?.writeText(l),x(!0),y.current&&window.clearTimeout(y.current),y.current=window.setTimeout(()=>x(!1),1600)},[l,u]);return(0,Q.jsxs)(`div`,{"data-state":n,"aria-busy":T,className:J(`w-full text-sm`,d),children:[(0,Q.jsxs)(`button`,{id:h,type:`button`,"aria-expanded":w,"aria-controls":g,onClick:()=>j(!w),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)(H,{icon:se,"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)(Hl,{value:E,type:`added`}),(0,Q.jsx)(Hl,{value:D,type:`removed`}),T?(0,Q.jsx)(H,{icon:f,"aria-label":`Applying changes`,className:J(`size-3.5 text-muted-foreground`,!p&&`animate-spin`)}):null,(0,Q.jsx)(Lt.span,{"aria-hidden":`true`,animate:{rotate:w?180:0},transition:p?{duration:0}:Dt,className:`shrink-0 text-muted-foreground/45 transition-colors group-hover:text-muted-foreground`,children:(0,Q.jsx)(H,{icon:M,className:`size-3.5`})})]}),(0,Q.jsx)(Gr,{id:g,role:`region`,"aria-labelledby":h,open:w,children:(0,Q.jsxs)(`div`,{className:`relative overflow-hidden rounded-lg border border-border/70 bg-muted/20`,children:[(0,Q.jsxs)(`div`,{ref:_,"data-slot":`file-diff-viewport`,"aria-live":`polite`,className:`overflow-auto`,style:{maxHeight:s},children:[(0,Q.jsx)(`div`,{className:`sr-only`,children:`File changes`}),t.map((e,t)=>{let n=e.type??`context`;return(0,Q.jsxs)(`div`,{className:J(`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:J(`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)(Mo,{code:e.content,tokens:A?.[t],className:`block min-w-0 whitespace-pre-wrap break-all pr-1.5 pl-1`})]},e.id)})]}),k?(0,Q.jsx)(Lt.button,{type:`button`,"aria-label":b?`Copied`:`Copy diff`,title:b?`Copied`:`Copy diff`,onClick:()=>void N(),whileTap:p?void 0:{scale:.9},transition:Mt,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)(H,{icon:b?Ke:O,className:`size-3.5`})}):null]})})]})}function Wl(e,t){return`${e}\0${t}`}function Gl(e,t,n){let r=new Map(e),i=Wl(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 Kl(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 ql(e){return[...e.values()].map(e=>({rowId:e.rowId,key:e.key,prev:e.prev,next:e.next}))}function Jl(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 Yl(e){let{range:t,rowIds:n,columnKeys:r,text:i,writable:a}=e,o=[];for(let e of pi(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 Xl(e){return e==null?`NULL`:typeof e==`number`&&Number.isFinite(e)?String(e):typeof e==`boolean`?e?`TRUE`:`FALSE`:`'${(typeof e==`string`?e:tu(e)??`[unserializable]`).replaceAll(`'`,`''`)}'`}function Zl(e){return`${e.table} > row ${e.rowId} > ${e.key}`}function Ql(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}" = ${Xl(e.next)}`).join(`, `);r.push(`${o}\nUPDATE "${e.table}" SET ${s} WHERE "${t}" = ${Xl(i)};`)}return r.join(`
|
|
25
|
-
|
|
26
|
-
`)}function $l(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?eu(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 eu(e){try{return JSON.stringify(e,null,2)??`undefined`}catch{return`undefined`}}function tu(e){try{return JSON.stringify(e)}catch{return null}}function nu({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)(()=>ql(n),[n]),p=i===`kv`,m=(0,Z.useMemo)(()=>p?$l({updates:f}):Ql({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,_=br(`S`);return(0,Q.jsx)(Te,{open:e,onOpenChange:t,children:(0,Q.jsxs)(K,{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)(Je,{children:`Pending Changes`}),(0,Q.jsx)(Ve,{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)(ru,{active:u===`visual`,onClick:()=>d(`visual`),id:`visual`,children:`Visual`}),(0,Q.jsx)(ru,{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=Zl({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)(z,{type:`button`,variant:`ghost`,size:`icon-xs`,disabled:a,"aria-label":`Undo ${t}`,onClick:()=>s(e.rowId,e.key),children:(0,Q.jsx)(H,{icon:Ee,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:si(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:si(e.next)})]})]})]},`${e.rowId}\0${e.key}`)})}):(0,Q.jsx)(Ul,{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)(pe,{children:[(0,Q.jsx)(Xt,{split:!0,disabled:a||g===0,onClick:c,children:`Clear All`}),(0,Q.jsxs)(Xt,{variant:`default`,disabled:a||g===0,onClick:l,"data-slot":`commit-all`,children:[a?`Committing…`:`Commit All (${g})`,(0,Q.jsx)(Ge,{keys:_,className:`ml-1.5`})]})]})]})})}function ru({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:J(`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 iu={past:[],future:[]};function au(e,t,n=100){let r=[...e.past,t];return{past:r.length>n?r.slice(r.length-n):r,future:[]}}function ou(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 su(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 cu(e){return{at:e.at,updates:e.updates.map(e=>({...e,prev:e.next,next:e.prev}))}}var lu={short:26,medium:34,tall:44,"extra-tall":56};function uu(e){return e===`comment`||e===`value`}function du(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 fu(e){switch(e){case`integer`:case`number`:return`123`;case`json`:return`{ }`;case`boolean`:return`01`;default:return`abc`}}function pu(e){return e===`integer`||e===`number`}function mu(e,t){if(e.format===`ttl`){let e=Kr(t);return e===void 0?{ok:!1}:{ok:!0,next:e}}return{ok:!0,next:t.trim()===``?null:li(e.type,t)}}function hu(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 gu({model:e,facet:t,storeRef:n,childName:r,tenant:i,masked:a=!1,routedRole:o,limit:s,toolbarExtras:l,indexSearch:u,insertOpen:f=!1,onInsertOpenChange:p,onDeleteRows:m,asGate:h=null,asUserId:g=null,onViewportContextMenu:_}){let[v,y]=(0,Z.useState)(``),[b,S]=(0,Z.useState)([]),[C,w]=(0,Z.useState)(new Set),[T,E]=(0,Z.useState)(`medium`),[D,O]=(0,Z.useState)(null),[k,A]=(0,Z.useState)(null),[j,M]=(0,Z.useState)(null),[N,P]=(0,Z.useState)(iu),[F,ee]=(0,Z.useState)(new Map),[I,L]=(0,Z.useState)(null),[R,te]=(0,Z.useState)(null),[B,V]=(0,Z.useState)(null),[ne,re]=(0,Z.useState)(null),[ie,ae]=(0,Z.useState)(!1),[oe,se]=(0,Z.useState)(null),[ce,le]=(0,Z.useState)(null),[de,fe]=(0,Z.useState)(!1),[pe,me]=(0,Z.useState)(!1),[W,he]=(0,Z.useState)(!1),[_e,ve]=(0,Z.useState)(440),ye=(0,Z.useRef)(null),be=(0,Z.useRef)(null),xe=(0,Z.useRef)(null),Se=(0,Z.useRef)(F),Ce=(0,Z.useRef)([]);Se.current=F;let we=Pa(),Te=m!==void 0,De=e.editable&&(t===`sql`||t===`kv`),Oe=lu[T],G=(0,Z.useMemo)(()=>e.columns.filter(e=>!C.has(e.key)),[e.columns,C]),Ae=(e,n)=>{if(t===`kv`&&n===`size`){let t=F.get(Wl(e.id,`value`))?.next??e.cells.value;return yi(t)}return F.get(Wl(e.id,n))?.next??e.cells[n]},je=u!==void 0,Me=je?u.value:v,Ne=(0,Z.useMemo)(()=>{if(je||!v.trim())return e.rows;let t=v.trim().toLowerCase();return e.rows.filter(n=>e.columns.some(e=>{if(Xr(e,Ae(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,v,F,je]),K=(0,Z.useMemo)(()=>{if(!D)return Ne;let t=G.find(e=>e.key===D.key)??e.columns.find(e=>e.key===D.key);if(!t)return Ne;let n=[...Ne];return n.sort((e,n)=>{let r=Ae(e,t.key),i=Ae(n,t.key),a=typeof r==`number`&&typeof i==`number`?r-i:si(r).localeCompare(si(i));return D.direction===`asc`?a:-a}),n},[Ne,D,F,G,e.columns]);(0,Z.useEffect)(()=>{S([]),w(new Set),A(null),P(iu),ee(new Map),Ce.current=[],L(null),te(null),V(null),re(null),ae(!1),se(null),me(!1),O(null),y(``)},[t,n,r,i]),(0,Z.useEffect)(()=>{if(!j)return;let e=setTimeout(()=>M(null),2e3);return()=>clearTimeout(e)},[j]),(0,Z.useEffect)(()=>{let e=ye.current;if(!e)return;let t=new ResizeObserver(e=>{let t=e[0]?.contentRect.height;t&&ve(Math.max(120,Math.round(t)))});return t.observe(e),()=>t.disconnect()},[]);let q=(0,Z.useMemo)(()=>e.rows.filter(e=>b.includes(e.id)),[e.rows,b]),Fe=(e,t)=>De&&e.editable&&!(e.pii&&a&&hi(t)),Ie=(e,t)=>{Se.current=e,Ce.current=t,ee(e)},Le=(t,n)=>{let r=e.rows.find(e=>e.id===t),i=e.columns.find(e=>e.key===n);return!r||!i?!1:Fe(i,r.cells[n])},Re=t=>{if(t.length===0)return 0;let n=Se.current,r=Ce.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=mu(a,i.text);if(!s.ok)continue;let c=s.next,l=Gl(n,r,{rowId:t.id,key:a.key,prev:o,next:c});n=l.pending,r=l.log}return Ie(n,r),t.length},ze=e=>{let t=b.length>0?K.filter(e=>b.includes(e.id)):K,n=G.map(e=>e.key);if(t.length===0||n.length===0)return;let i=b.length>0?`selection`:`page`,a=r.replace(/[^\w.-]+/g,`_`);if(e===`csv`){let e=t.map(e=>n.map(t=>Ti(Ae(e,t))));Tu(`${a}-${i}.csv`,`\uFEFF${Ci(n,e)}`,`text/csv;charset=utf-8`)}else{let e=t.map(e=>{let t={};for(let r of n)t[r]=Ae(e,r)??null;return t});Tu(`${a}-${i}.json`,`${JSON.stringify(e,null,2)}\n`,`application/json`)}M(`Exported ${t.length} row(s)`)},Be=t=>{let n=t.target.files?.[0];t.target.value=``,!(!n||!De)&&n.text().then(t=>{try{let n=ui(t);if(n.length===0){M(`No rows in import file`);return}let{hits:r,unmatched:i}=_i({records:n,rowIds:new Set(e.rows.map(e=>e.id)),writable:Le});if(r.length===0){A(i===n.length?`No matching rows — import needs an id or key that exists on this page`:`Nothing writable to import`);return}let a=Re(r);A(null),M(i>0?`Imported ${a} cell(s) · ${i} row(s) unmatched`:`Imported ${a} cell(s)`)}catch(e){A(e instanceof Error?e.message:`Could not parse import file`)}})},Ve=(e,t,n)=>{let r=e.cells[t.key];if(!Fe(t,r))return;let i=mu(t,n);if(!i.ok){A(`TTL must be a duration like 30m, 1h, or empty to clear`);return}A(null);let a=i.next,o=Gl(Se.current,Ce.current,{rowId:e.id,key:t.key,prev:r,next:a});Ie(o.pending,o.log)},He=(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(!Fe(a,o))return;let s=Gl(Se.current,Ce.current,{rowId:i.id,key:a.key,prev:o,next:oi(o,r)?o:r});Ie(s.pending,s.log)},Ue=(e,t)=>{let n=Wl(e,t),r=new Map(Se.current);r.delete(n),Ie(r,Ce.current.filter(e=>e!==n))},We=async(e,a)=>{if(e.length===0)return!0;let o=new Map;for(let t of e){let e=o.get(t.rowId)??{};e[t.key]=t.next,o.set(t.rowId,e)}he(!0),A(null);let s=!0;try{await Promise.all([...o.entries()].map(([e,a])=>we.mutateAsync({ref:n,...t===`sql`?{child:r,id:e}:{key:e},...i?{tenant:i}:{},...h?{asGate:h}:{},...g?{asUserId:g}:{},patch:ki(a),commit:!0}))),a?.track!==!1&&P(t=>au(t,{updates:e,at:Date.now()})),a?.notice&&M(a.notice)}catch(e){s=!1,A(e instanceof Error?e.message:String(e))}finally{he(!1)}return s},Ge=()=>{if(W)return;if(Se.current.size>0){let e=Kl(Se.current,Ce.current);Ie(e.pending,e.log);return}let{history:e,batch:t}=ou(N);t&&(P(e),We(cu(t).updates,{track:!1,notice:`Undid ${t.updates.length} cell(s)`}))},qe=()=>{if(W||F.size>0)return;let{history:e,batch:t}=su(N);t&&(P(e),We(t.updates,{track:!1,notice:`Redid ${t.updates.length} cell(s)`}))},Je=(t,n,r)=>{if(W)return;let i=e.rows.find(e=>e.id===t),a=e.columns.find(e=>e.key===n);!i||!a||!Fe(a,i.cells[n])||(L({rowId:t,key:n}),re(r===void 0?null:r),V({rowId:t,key:n}))},Ye=(t,n,r)=>{if(W)return;let i=e.rows.find(e=>e.id===t),a=e.columns.find(e=>e.key===n);if(!(!i||!a)){if(a.type===`boolean`){let e=mu(a,r);if(!e.ok)return;We([{rowId:t,key:n,prev:i.cells[n],next:e.next}],{notice:e.next===!0?`Enabled ${t}`:`Disabled ${t}`});return}if(R&&fi(R)>1){Re(Yl({range:R,rowIds:K.map(e=>e.id),columnKeys:G.map(e=>e.key),text:r,writable:Le}));return}Ve(i,a,r)}},Xe=()=>{Se.current.size!==0&&ae(!0)},Ze=()=>{if(W||Se.current.size===0)return;let e=ql(Se.current);We(e,{notice:`Applied ${e.length} change(s)`}).then(e=>{e&&(Ie(new Map,[]),ae(!1))})},Qe=()=>{W||(Ie(new Map,[]),ae(!1))};(0,Z.useEffect)(()=>{if(!ie)return;let e=e=>{!(e.metaKey||e.ctrlKey)||e.key.toLowerCase()!==`s`||(e.preventDefault(),Ze())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[ie]);let J=()=>{if(b.length>1)return K.filter(e=>b.includes(e.id));let e=I?.rowId??b[0]??K[0]?.id;if(!e)return[];let t=K.findIndex(t=>t.id===e);return t<0?[]:K.slice(t)},$e=e=>{if(!De||W||e.length===0)return;let t=G.map(e=>e.key),n=[];if(R){let r=bi(R),i=[];for(let e=r.minRow;e<=r.maxRow;e++){let t=K[e];t&&i.push(t.id)}n=Jl({matrix:e,rowIds:i,columnKeys:t,startCol:r.minCol,writable:Le})}else{let r=J();if(r.length===0)return;let i=I?.key,a=Math.max(0,i?G.findIndex(e=>e.key===i):0);n=Jl({matrix:e,rowIds:b.length>1?r.map(e=>e.id):r.slice(0,e.length).map(e=>e.id),columnKeys:t,startCol:a,writable:Le})}let r=Re(n);r>0&&M(`Pasted ${r} cell(s)`)},et=async()=>{let t=[];if(R){let e=bi(R);for(let n=e.minRow;n<=e.maxRow;n++){let r=K[n];if(!r)continue;let i=[];for(let t=e.minCol;t<=e.maxCol;t++){let e=G[t];i.push(e?si(Ae(r,e.key)):``)}t.push(i)}}else{let n=b.length>0?K.filter(e=>b.includes(e.id)):[];if(n.length>0)for(let e of n)t.push(G.map(t=>si(Ae(e,t.key))));else if(I){let n=e.rows.find(e=>e.id===I.rowId);n&&t.push([si(Ae(n,I.key))])}}if(t.length!==0)try{await navigator.clipboard.writeText(Ei(t)),M(`Copied ${t.length} row(s)`)}catch{A(`Clipboard write blocked — allow clipboard access in the browser prompt.`)}},tt=e=>e instanceof Node&&(be.current===e||be.current?.contains(e)===!0),nt=e=>e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement,it=e=>e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement?e.selectionStart!==e.selectionEnd:!1,at=(0,Z.useMemo)(()=>G.map(e=>({key:e.key,header:(0,Q.jsx)(_u,{col:e}),sortable:!0,align:pu(e.type)?`right`:`left`,width:uu(e.key)?void 0:`${du(e.type,e.key)}px`,fill:uu(e.key),sortValue:t=>{let n=Ae(t,e.key);return typeof n==`number`?n:si(n)},cell:t=>{let o=F.get(Wl(t.id,e.key)),s=o?o.next:t.cells[e.key];return(0,Q.jsx)(bu,{row:t,col:e,storeRef:n,childName:r,tenant:i,masked:a,editable:De&&e.editable&&!(e.pii&&a&&hi(t.cells[e.key])),saving:W,dirty:o!==void 0,editing:B?.rowId===t.id&&B.key===e.key,draftSeed:B?.rowId===t.id&&B.key===e.key?ne:null,displayValue:s,onFocus:()=>L({rowId:t.id,key:e.key}),onStartEdit:()=>Je(t.id,e.key),onEditEnd:()=>{V(null),re(null)},onCommit:n=>Ye(t.id,e.key,n),onInspect:()=>se({rowId:t.id,column:e.key}),onUpgrade:t.cells.upgrade===!0?()=>{We([{rowId:t.id,key:`upgrade`,prev:t.cells.upgrade,next:!0}],{notice:`Upgraded ${t.id}`,track:!1})}:void 0})}})),[G,n,r,i,a,W,De,F,B,ne,We]),ot=e=>{let t=e.ctrlKey||e.metaKey;if(t&&e.key.toLowerCase()===`f`){e.preventDefault(),be.current?.focus();return}if(!(tt(e.target)||nt(e.target))){if(t&&e.key.toLowerCase()===`enter`){Se.current.size>0&&(e.preventDefault(),ie?Ze():Xe());return}if(t&&e.key.toLowerCase()===`s`){Se.current.size>0&&(e.preventDefault(),ie?Ze():Xe());return}if(t&&e.key.toLowerCase()===`z`){e.preventDefault(),e.shiftKey?qe():Ge();return}if(t&&e.key.toLowerCase()===`y`){e.preventDefault(),qe();return}if(e.key===`Escape`){if(tt(e.target)||!B&&!R)return;e.preventDefault(),V(null),re(null),te(null),e.currentTarget.focus({preventScroll:!0});return}if(!B){if(e.key===`Enter`&&R){e.preventDefault();let t=K[R.head.row],n=G[R.head.col];t&&n&&Je(t.id,n.key);return}if(R&&De&&e.key.length===1&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let t=K[R.head.row],n=G[R.head.col];t&&n&&(e.preventDefault(),Je(t.id,n.key,e.key));return}if((e.key===`Delete`||e.key===`Backspace`)&&R&&De){e.preventDefault();let t=Re(Yl({range:R,rowIds:K.map(e=>e.id),columnKeys:G.map(e=>e.key),text:``,writable:Le}));t>0&&M(`Cleared ${t} cell(s)`)}}}},st=e=>{tt(e.target)||it(e.target)||b.length===0&&!I&&!R||(e.preventDefault(),et())},ct=e=>{if(!De||tt(e.target))return;let t=e.clipboardData.getData(`text/plain`),n=mi(t);!(b.length>1||n.length>1||(n[0]?.length??0)>1)&&e.target instanceof HTMLInputElement||n.length!==0&&(e.preventDefault(),$e(n))},lt=oe?e.rows.find(e=>e.id===oe.rowId):void 0,ut=oe?e.columns.find(e=>e.key===oe.column):void 0,dt=lt&&ut?Ae(lt,ut.key):void 0,ft=lt!==void 0&&ut!==void 0&&!W&&Fe(ut,lt.cells[ut.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:ot,onCopy:st,onPaste:ct,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:[l,l?(0,Q.jsx)(Qi,{orientation:`vertical`,className:`mx-0.5 my-2 h-4 self-center`}):null,(0,Q.jsxs)(xr,{label:je?`Search this index`:`Find in this page`,keys:br(`F`),className:`relative min-w-40 flex-1`,children:[(0,Q.jsx)(H,{icon:x,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)(d,{ref:be,value:Me,onChange:e=>je?u.onChange(e.target.value):y(e.target.value),placeholder:je?`Find by title or id — or paste 1, 0, 0`:`Find in results…`,"aria-label":je?`Search this index`:`Find in results`,"data-slot":je?`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`})]}),je?(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)(d,{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:u.topK,onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&t>=1&&t<=100&&u.onTopKChange(t)}})]}):null,D?(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:[D.key,` `,D.direction===`desc`?`↓`:`↑`]}):null,(0,Q.jsx)(Qi,{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:[De&&t===`kv`?(0,Q.jsx)(Eu,{label:`Add key`,disabled:W,onClick:()=>me(!0),slot:`add-kv-key`,children:(0,Q.jsx)(H,{icon:rt,className:`size-3.5`,"aria-hidden":!0})}):null,De?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`input`,{ref:xe,type:`file`,accept:`.csv,.tsv,.txt,.json,text/csv,application/json`,className:`sr-only`,tabIndex:-1,"aria-hidden":!0,onChange:Be}),(0,Q.jsx)(Eu,{label:`Import CSV or JSON`,disabled:W,onClick:()=>xe.current?.click(),slot:`import-rows`,children:(0,Q.jsx)(H,{icon:Pe,className:`size-3.5`,"aria-hidden":!0})})]}):null,(0,Q.jsxs)(sn,{children:[(0,Q.jsx)(xr,{label:b.length>0?`Export ${b.length} selected row${b.length===1?``:`s`}`:`Export this page as CSV or JSON`,children:(0,Q.jsx)(Wt,{disabled:K.length===0,render:e=>(0,Q.jsx)(z,{...e,type:`button`,variant:`ghost`,size:`icon-xs`,disabled:K.length===0,"aria-label":`Export rows`,"data-slot":`export-rows`,children:(0,Q.jsx)(H,{icon:ue,className:`size-3.5`,"aria-hidden":!0})})})}),(0,Q.jsx)(en,{align:`end`,className:`w-40`,children:(0,Q.jsxs)($t,{children:[(0,Q.jsx)(un,{children:b.length>0?`Export selection`:`Export page`}),(0,Q.jsx)(qt,{onClick:()=>ze(`csv`),children:`CSV`}),(0,Q.jsx)(qt,{onClick:()=>ze(`json`),children:`JSON`})]})})]}),De?(0,Q.jsxs)(Q.Fragment,{children:[F.size>0?(0,Q.jsx)(Eu,{label:`Discard uncommitted changes`,disabled:W,onClick:Qe,slot:`discard-changes`,children:(0,Q.jsx)(H,{icon:c,className:`size-3.5`,"aria-hidden":!0})}):null,(0,Q.jsx)(xr,{label:F.size>0?`Review ${F.size} uncommitted change${F.size===1?``:`s`}`:`No uncommitted changes`,children:(0,Q.jsxs)(z,{type:`button`,variant:F.size>0?`outline`:`ghost`,size:`xs`,disabled:F.size===0||W,onClick:Xe,"aria-label":F.size>0?`Review ${F.size} uncommitted changes`:`Review changes`,"data-slot":`apply-changes`,className:F.size>0?`relative h-6 gap-1 overflow-visible border-amber-500/25 bg-amber-500/10 text-amber-800 hover:bg-amber-500/15 dark:text-amber-300`:`h-6`,children:[F.size>0?(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`oke-changes-border-run pointer-events-none absolute inset-0`}):null,(0,Q.jsx)(H,{icon:Ke,className:`relative size-3.5`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`relative`,children:`Changes`}),F.size>0?(0,Q.jsx)(`span`,{className:`relative min-w-3.5 rounded-full border border-amber-500/25 bg-amber-500/10 px-1 font-mono text-[9px] leading-3`,children:F.size}):null]})})]}):null,(0,Q.jsx)(Eu,{label:`Undo edit`,keys:br(`Z`),disabled:F.size===0&&N.past.length===0||W,onClick:Ge,slot:`undo-edit`,children:(0,Q.jsx)(H,{icon:Ee,className:`size-3.5`,"aria-hidden":!0})}),(0,Q.jsx)(Eu,{label:`Redo edit`,keys:yr(`Z`),disabled:N.future.length===0||W||F.size>0,onClick:qe,slot:`redo-edit`,children:(0,Q.jsx)(H,{icon:U,className:`size-3.5`,"aria-hidden":!0})}),(0,Q.jsxs)(sn,{children:[(0,Q.jsx)(xr,{label:`Row height and columns`,children:(0,Q.jsx)(Wt,{render:e=>(0,Q.jsx)(z,{...e,type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`View options`,"data-slot":`view-menu`,children:(0,Q.jsx)(H,{icon:ke,className:`size-3.5`,"aria-hidden":!0})})})}),(0,Q.jsxs)(en,{align:`end`,className:`w-48`,children:[(0,Q.jsxs)($t,{children:[(0,Q.jsx)(un,{children:`Row height`}),(0,Q.jsxs)(fn,{value:T,onValueChange:e=>E(e),children:[(0,Q.jsx)(Yt,{value:`short`,"data-slot":`row-height-menu`,children:`Short`}),(0,Q.jsx)(Yt,{value:`medium`,children:`Medium`}),(0,Q.jsx)(Yt,{value:`tall`,children:`Tall`}),(0,Q.jsx)(Yt,{value:`extra-tall`,children:`Extra tall`})]})]}),(0,Q.jsx)(dn,{}),(0,Q.jsxs)($t,{children:[(0,Q.jsx)(un,{children:`Columns`}),e.columns.map(e=>{let t=!C.has(e.key),n=t&&G.length===1;return(0,Q.jsx)(rn,{checked:t,disabled:n,onCheckedChange:t=>{w(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&&m?(0,Q.jsx)(xr,{label:q.length>0?`Delete ${q.length} selected row${q.length===1?``:`s`}`:`Select rows to delete`,children:(0,Q.jsxs)(z,{type:`button`,variant:`destructive`,size:q.length>0?`xs`:`icon-xs`,className:q.length>0?`ml-1 h-6`:`ml-1`,disabled:q.length===0,onClick:()=>m(q),"aria-label":q.length>0?`Delete ${q.length} selected rows`:`Delete selected rows`,"data-slot":`delete-selected`,children:[(0,Q.jsx)(H,{icon:ge,className:`size-3.5`,"aria-hidden":!0}),q.length>0?q.length:null]})}):null]})]}),(0,Q.jsx)(`div`,{ref:ye,className:`min-h-0 flex-1`,"data-slot":`grid-viewport`,"aria-label":`${r} rows`,children:(0,Q.jsx)(Nl,{data:K,columns:at,getRowId:e=>e.id,selectable:Te,selectedRowIds:b,onSelectionChange:S,sort:D,onSortChange:O,resizable:!0,reorderable:!0,onCellEdit:De?Ye:void 0,onDeleteRow:e.editable&&m?t=>{let n=e.rows.find(e=>e.id===t);n&&m([n])}:void 0,onRowContextMenu:e=>{le(e),fe(!0)},onViewportContextMenu:_,cellRange:R,onCellRangeChange:De?e=>{if(te(e),!e)return;let t=K[e.head.row],n=G[e.head.col];t&&n&&L({rowId:t.id,key:n.key});let r=ye.current?.closest(`[data-slot='store-data-grid']`);r instanceof HTMLElement&&!(document.activeElement instanceof HTMLInputElement)&&r.focus({preventScroll:!0})}:void 0,onCellActivate:De?(e,t)=>{let n=K[e],r=G[t];n&&r&&Je(n.id,r.key)}:void 0,rowHeight:Oe,height:_e,emptyState:je&&Me.trim()?`No hits — try a different query or raise topK.`:v.trim()?`No matches on this page — increase Limit to search more rows.`:`No rows.`,className:`h-full rounded-none border-0`})}),De?(0,Q.jsx)(nu,{open:ie,onOpenChange:ae,pending:F,table:r,facet:t===`kv`?`kv`:`sql`,saving:W,error:k,onUndoCell:Ue,onClearAll:Qe,onCommitAll:Ze}):null,De&&t===`sql`&&p?(0,Q.jsx)(Vl,{open:f,onOpenChange:p,storeRef:n,childName:r,tenant:i,columns:e.columns,asGate:h,asUserId:g}):null,De&&t===`kv`?(0,Q.jsx)(Bl,{open:pe,onOpenChange:me,storeRef:n,childName:r,tenant:i,existingKeys:e.rows.map(e=>e.id)}):null,(0,Q.jsx)(Ll,{open:de,onOpenChange:fe,model:e,row:ce?e.rows.find(e=>e.id===ce.id)??ce:null,facet:t,storeRef:n,childName:r,tenant:i,masked:a,asGate:h,asUserId:g,onDeleteRow:m?e=>{fe(!1),m([e])}:void 0}),oe&<&&ut?(0,Q.jsx)(Mi,{open:!0,onOpenChange:e=>{e||se(null)},rowId:oe.rowId,column:oe.column,storeRef:n,value:dt,originalValue:lt.cells[ut.key],editable:ft,onChange:ft?e=>He(oe.rowId,oe.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:[Ne.length,Ne.length===e.rows.length?``:` of ${e.rows.length}`,` `,e.rows.length===1?`row`:`rows`]}),o?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`text-border`,children:`·`}),(0,Q.jsx)(`span`,{children:o})]}):null,t===`sql`&&a?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`text-border`,children:`·`}),(0,Q.jsx)(`span`,{className:`text-sky-700 dark:text-sky-400`,children:`PII masked`})]}):t===`sql`&&e.columns.some(e=>e.pii)?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`text-border`,children:`·`}),(0,Q.jsx)(`span`,{className:`text-amber-800 dark:text-amber-300`,children:`PII visible`})]}):null,F.size>0?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`text-border`,children:`·`}),(0,Q.jsxs)(`span`,{className:`text-amber-800 dark:text-amber-300`,role:`status`,"data-slot":`pending-count`,children:[F.size,` uncommitted`]})]}):null,W?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`text-border`,children:`·`}),(0,Q.jsx)(`span`,{role:`status`,"data-slot":`cell-edit-saving`,children:`Saving…`})]}):null,j?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`text-border`,children:`·`}),(0,Q.jsx)(`span`,{role:`status`,"data-slot":`grid-notice`,children:j})]}):null,k?(0,Q.jsx)(`span`,{className:`text-destructive`,role:`alert`,"data-slot":`cell-edit-error`,children:k}):null,je&&Me.trim()?(0,Q.jsxs)(`span`,{className:`ml-auto truncate`,role:`status`,"data-slot":`find-scope`,children:[`Index query · topK `,u.topK]}):v.trim()?(0,Q.jsxs)(`span`,{className:`ml-auto truncate`,role:`status`,"data-slot":`find-scope`,children:[`This page only · limit `,s]}):q.length>0?(0,Q.jsxs)(`span`,{className:`ml-auto`,children:[q.length,` row`,q.length===1?``:`s`,` checked`]}):(0,Q.jsx)(`span`,{className:`ml-auto opacity-60`,children:`Click to select · two-finger click opens sheet · drag a range · type to edit`})]})]})}function _u({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:fu(e.type)}),e.primaryKey?(0,Q.jsx)(H,{icon:fe,className:`size-3 shrink-0 text-amber-600 dark:text-amber-400`,"aria-label":`Primary key`}):null,e.pii?(0,Q.jsx)(H,{icon:ne,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 vu=`text-[#9a5b12] dark:text-[#e8c48a]`,yu=`absolute inset-0 flex min-w-0 items-center overflow-hidden px-4 font-mono text-[11px]`;function bu({row:e,col:t,storeRef:n,childName:r,tenant:i,masked:a,editable:o,saving:s,dirty:c,editing:l,draftSeed:u,displayValue:d,onFocus:f,onStartEdit:p,onEditEnd:m,onCommit:h,onInspect:g,onUpgrade:_}){let v=d,y=pu(t.type),b=v==null;if(t.pii&&a&&hi(e.cells[t.key])&&!c)return(0,Q.jsx)(`span`,{className:yu,children:(0,Q.jsx)(Fl,{refName:n,child:r,...i?{tenant:i}:{},rowId:e.id,column:t.key,maskedValue:e.cells[t.key]})});if(t.type===`boolean`){let t=d===!0;return(0,Q.jsx)(`span`,{className:J(yu,`justify-center`,c&&vu),"data-slot":o?`cell-display`:void 0,"data-pending":c?`true`:void 0,onClick:e=>e.stopPropagation(),children:(0,Q.jsx)(La,{size:`sm`,checked:t,disabled:!o||s,ariaLabel:t?`Disable ${e.id}`:`Enable ${e.id}`,onCheckedChange:e=>{o&&!s&&h(e?`true`:`false`)}})})}if(o&&l)return(0,Q.jsx)(`span`,{className:J(yu,c&&vu,y&&`tabular-nums`),"data-slot":`cell-editor`,"data-pending":c?`true`:void 0,children:(0,Q.jsx)(vi,{value:u??hu(t,v),label:`Edit ${t.key}`,dirty:c,autoFocus:!0,placeholder:t.format===`ttl`?`30m`:void 0,onFocus:f,onIdle:m,onChange:e=>{s||h(e)},className:J(`h-full min-w-0 font-mono text-[11px]`,y&&`text-right tabular-nums`,di(v)&&`text-right`)})});let x=ji(v)!==null,S=Xr(t,v);return(0,Q.jsxs)(`span`,{role:o?`button`:void 0,tabIndex:o?-1:void 0,"data-slot":o?`cell-display`:void 0,"data-pending":c?`true`:void 0,className:J(yu,`group/cell gap-1`,o&&`cursor-cell`,c&&vu,y&&`tabular-nums`,b&&!c&&`text-muted-foreground/40`,t.type===`json`&&!b&&!c&&`text-muted-foreground`),title:t.format===`name-key`&&typeof e.cells.url==`string`?e.cells.url:S,onDoubleClick:o?e=>{e.stopPropagation(),s||p()}:void 0,children:[t.format===`source`?(0,Q.jsx)(Cu,{value:S}):t.format===`name-key`?(0,Q.jsx)(xu,{title:S,url:typeof e.cells.url==`string`?e.cells.url:null}):(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,dir:di(v)?`rtl`:`ltr`,children:S}),t.format===`name-key`?(0,Q.jsx)(Su,{name:typeof e.cells.name==`string`?e.cells.name:``,version:e.cells.version==null?``:String(e.cells.version),available:e.cells.available==null?``:String(e.cells.available),upgradeable:e.cells.upgrade===!0,saving:s,onUpgrade:_}):null,x?(0,Q.jsx)(wu,{onInspect:g}):null]})}function xu({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)(H,{icon:V,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 Su({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 Cu({value:e}){let t=e===`library`;return(0,Q.jsxs)(Or,{variant:`outline`,className:J(`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)(H,{icon:t?s:I,className:`size-3`,"aria-hidden":!0}),t?`Library`:`Builtin`]})}function wu({onInspect:e}){return(0,Q.jsxs)(h,{children:[(0,Q.jsx)(L,{render:t=>(0,Q.jsx)(`button`,{...t,type:`button`,"aria-label":`Open as table`,"data-slot":`json-inspect`,className:J(`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)(H,{icon:l,className:`size-3`,"aria-hidden":!0})})}),(0,Q.jsx)(C,{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 Eu({label:e,keys:t,disabled:n,onClick:r,slot:i,children:a}){return(0,Q.jsxs)(h,{children:[(0,Q.jsx)(L,{render:t=>(0,Q.jsx)(z,{...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)(C,{side:`bottom`,className:`text-[11px]`,children:[e,t&&t.length>0?(0,Q.jsx)(Ge,{keys:t}):null]})]})}var Du=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/;function Ou(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 ku(e){let t=e.trim().split(/[\s,]+/).filter(e=>e.length>0);return t.length>=2&&t.every(e=>Du.test(e))}function Au(e){let t=e.trim();if(t.length===0)return{kind:`empty`};if(ku(t)){let e=Ou(t);if(e&&e.length>=2)return{kind:`vector`,vector:e}}return{kind:`text`,q:t}}function ju({manifest:e,value:t,onChange:n}){let{asGate:r,asUserId:i}=t,a=bn(!0),o=qn(),s=(0,Z.useMemo)(()=>Yn(mr(e),a.data??null),[e,a.data]),c=(0,Z.useMemo)(()=>Wn(s),[s]),l=(0,Z.useMemo)(()=>pr(o.data??[],s),[o.data,s]),u=s.gates.find(e=>e.kind===`public`)?.description??`Intentionally unauthenticated.`,d=lr(r),f=r!==null,[p,m]=(0,Z.useState)(i?`user`:`policy`),h=c.find(e=>e.id===r)??null,g=l.find(e=>e.id===i&&e.gate===r)??null,_=c.length>0||l.length>0,v=e=>{if(e===`operator`){n({asGate:null,asUserId:null});return}if(e===`public`){n({asGate:`public`,asUserId:null});return}if(d===`as`)return;let t=h?.id??c[0]?.id??l[0]?.gate??null;if(t!==null){if(l[0]&&t===l[0].gate&&c.length===0){m(`user`),n({asGate:l[0].gate,asUserId:l[0].id});return}m(`policy`),n({asGate:t,asUserId:null})}};return(0,Q.jsxs)(sn,{children:[(0,Q.jsx)(Wt,{render:e=>(0,Q.jsxs)(z,{...e,type:`button`,variant:`ghost`,size:`sm`,className:J(`h-full max-w-44 min-w-0 rounded-none px-2 text-[11px]`,f&&`text-sky-800 dark:text-sky-300`),"aria-label":f?`View data as Gate ${r}`:`View data as Operator (default)`,"data-slot":`store-query-gate`,children:[(0,Q.jsx)(H,{icon:wr.gate.icon,"data-icon":`inline-start`,className:`size-3.5`}),(0,Q.jsx)(`span`,{className:`truncate`,children:er(r,i,g?.label)})]})}),(0,Q.jsxs)(en,{align:`start`,className:`w-80 overflow-hidden p-0`,children:[(0,Q.jsx)(ir,{children:`View as`}),(0,Q.jsxs)(Vn,{label:`View data as`,children:[(0,Q.jsx)(sr,{mode:`operator`,title:`Operator`,caption:`Bypass`,selected:d===`operator`,onSelect:()=>v(`operator`)}),(0,Q.jsx)(sr,{mode:`public`,title:`Public`,caption:`Anonymous`,selected:d===`public`,onSelect:()=>v(`public`)}),(0,Q.jsx)(sr,{mode:`as`,title:`As`,caption:g?g.label:h?.label??`User / policy`,selected:d===`as`,disabled:!_,onSelect:()=>v(`as`)})]}),d===`operator`?(0,Q.jsxs)(Xn,{title:`Operator`,badge:`Default`,children:[`Bypasses RLS. No `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`oke.gate()`}),` stamp.`]}):null,d===`public`?(0,Q.jsxs)(Xn,{title:`Public`,children:[u,` Sets `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`oke.gate()`}),` to`,` `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`public`}),`.`]}):null,d===`as`?(0,Q.jsx)(nr,{tab:p,onTabChange:m,policies:c,users:l,asGate:r,asUserId:g?.id??null,onSelectPolicy:e=>{m(`policy`),n({asGate:e.id,asUserId:null})},onSelectUser:e=>{m(`user`),n({asGate:e.gate,asUserId:e.id})}}):null]})]})}function Mu(e){return[...new Set(e)].sort((e,t)=>e.localeCompare(t))}function Nu({child:e}){let t=Mu(e.writers),n=Mu(e.readers);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,"data-slot":`touched-by-lists`,children:[(0,Q.jsx)(Pu,{title:`Writers`,ids:t,empty:`No Manifest flow declares writes for this resource.`}),(0,Q.jsx)(Pu,{title:`Readers`,ids:n,empty:`No Manifest flow declares reads for this resource.`})]})}function Pu({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 Fu=[10,25,50,100,250,500],Iu=280;function Lu(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 Ru({store:e,child:t,manifest:n,tenancyDeclared:r,tenants:i,tenant:o,onTenantChange:c,piiMasked:l=!0}){let[u,d]=(0,Z.useState)(500),[f,p]=(0,Z.useState)(``),[m,g]=(0,Z.useState)(5),[_,v]=(0,Z.useState)(null),[y,b]=(0,Z.useState)(!1),[x,S]=(0,Z.useState)(!1),[w,E]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(!1),[k,j]=(0,Z.useState)(!1),[M,N]=(0,Z.useState)(!1),[P,F]=(0,Z.useState)({asGate:null,asUserId:null}),ee=Lu(f,Iu),I=(0,Z.useMemo)(()=>Au(ee),[ee]),R=!r||o!==null&&o.length>0,te=(0,Z.useMemo)(()=>R?{ref:e.ref,child:t.name,...o?{tenant:o}:{},limit:u,...e.facet===`index`&&I.kind===`vector`?{vector:I.vector,topK:m}:{},...e.facet===`index`&&I.kind===`text`?{q:I.q,topK:m}:{},...e.facet===`sql`&&!l?{revealPii:!0}:{},...e.facet===`sql`&&!Hn(t)&&P.asGate?{asGate:P.asGate}:{},...e.facet===`sql`&&!Hn(t)&&P.asUserId?{asUserId:P.asUserId}:{}}:null,[e.ref,e.facet,t,o,R,u,I,m,l,P]),B=rr(te,R),V=Fa(),re=cr(t),U=re===`extension`,ie=re===`policy`,ae=re===`function`,oe=re===`index`,se=re===`trigger`,ce=Hn(t)&&!U,le=e.ref===`sql:oke_console`||ce,{columnTypes:ue,primaryKeyColumns:de}=(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]),pe=(0,Z.useMemo)(()=>{if(!B.data)return null;let n=Ai({facet:e.facet,data:B.data,piiColumns:t.piiColumns,columnTypes:ue,columnDescriptions:t.columnDescriptions,primaryKeyColumns:de});return ie&&e.ref!==`sql:oke_console`?{...n,editable:!0,columns:n.columns.filter(e=>e.key!==`id`&&e.key!==`schema`).map(e=>({...e,editable:e.key===`roles`||e.key===`using`||e.key===`with_check`||e.key===`command`||e.key===`permissive`,...e.key===`origin`?{label:`Origin`}:{},...e.key===`code`?{label:`Code`}:{}}))}:ie?{...n,editable:!1,columns:n.columns.filter(e=>e.key!==`id`&&e.key!==`schema`).map(e=>({...e,editable:!1}))}:U&&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`}:{}}))}:le?{...n,editable:!1,columns:n.columns.map(e=>({...e,editable:!1}))}:n},[B.data,e.facet,e.ref,t,ue,de,le,U,ie]),me=n=>{if(!_)return;let r=_.map(e=>e.id);V.mutate({ref:e.ref,...e.facet===`sql`?{child:t.name}:{},...o?{tenant:o}:{},...pe?.deleteKind===`keys`?{keys:r}:{ids:r},confirmation:n.confirmation,reason:n.reason},{onSuccess:()=>{v(null)}})},W=new Set(t.writers).size,he=new Set(t.readers).size,ge=R&&pe!==null,_e=(0,Q.jsxs)(Q.Fragment,{children:[e.facet===`sql`&&!Hn(t)?(0,Q.jsx)(ju,{manifest:n,value:P,onChange:F}):null,(0,Q.jsxs)(h,{children:[(0,Q.jsx)(L,{render:e=>(0,Q.jsx)(z,{...e,type:`button`,variant:`ghost`,size:`icon-xs`,onClick:()=>void B.refetch(),disabled:B.isFetching,"aria-label":`Refresh`,"data-slot":`browse-refresh`,children:(0,Q.jsx)(H,{icon:T,className:B.isFetching?`size-3.5 animate-spin`:`size-3.5`,"aria-hidden":!0})})}),(0,Q.jsx)(C,{side:`bottom`,className:`text-[11px]`,children:`Reload from the store`})]}),e.facet===`sql`&&!le&&!Hn(t)?(0,Q.jsx)(xr,{label:`Insert a row`,children:(0,Q.jsxs)(z,{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:()=>N(!0),children:[(0,Q.jsx)(H,{icon:rt,className:`size-3.5`,"aria-hidden":!0}),`Insert data`]})}):null,oe&&e.ref!==`sql:oke_console`?(0,Q.jsx)(xr,{label:`CREATE INDEX`,children:(0,Q.jsxs)(z,{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:()=>O(!0),children:[(0,Q.jsx)(H,{icon:fe,className:`size-3.5`,"aria-hidden":!0}),`Create index`]})}):null,ae&&e.ref!==`sql:oke_console`?(0,Q.jsx)(xr,{label:`CREATE FUNCTION`,children:(0,Q.jsxs)(z,{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:()=>E(!0),children:[(0,Q.jsx)(H,{icon:xe,className:`size-3.5`,"aria-hidden":!0}),`New function`]})}):null,se&&e.ref!==`sql:oke_console`?(0,Q.jsx)(xr,{label:`CREATE TRIGGER`,children:(0,Q.jsxs)(z,{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)(H,{icon:ve,className:`size-3.5`,"aria-hidden":!0}),`New trigger`]})}):null,ie&&e.ref!==`sql:oke_console`?(0,Q.jsx)(xr,{label:`CREATE POLICY on a table`,children:(0,Q.jsxs)(z,{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:()=>S(!0),children:[(0,Q.jsx)(H,{icon:ne,className:`size-3.5`,"aria-hidden":!0}),`Create policy`]})}):null,U&&e.ref!==`sql:oke_console`?(0,Q.jsx)(xr,{label:`Add Timescale, PostGIS, pg_cron…`,children:(0,Q.jsxs)(z,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px] text-muted-foreground`,"data-slot":`extension-library`,onClick:()=>b(!0),children:[(0,Q.jsx)(H,{icon:s,className:`size-3.5`,"aria-hidden":!0}),`Library`]})}):null,(0,Q.jsxs)(sn,{children:[(0,Q.jsx)(xr,{label:`${W} writer${W===1?``:`s`} · ${he} reader${he===1?``:`s`}`,children:(0,Q.jsx)(Wt,{render:e=>(0,Q.jsxs)(z,{...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":`${W} writers, ${he} readers`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(H,{icon:A,className:`size-3`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:W})]}),(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)(H,{icon:ke,className:`size-3`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:he})]})]})})}),(0,Q.jsx)(en,{align:`start`,className:`w-72 p-3`,children:(0,Q.jsx)(Nu,{child:t})})]}),r?(0,Q.jsx)(xr,{label:`Tenant for this browse`,children:(0,Q.jsxs)(`div`,{className:`relative flex items-center`,children:[(0,Q.jsx)(H,{icon:He,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:o??``,onChange:e=>c(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)(H,{icon:q,className:`pointer-events-none absolute right-1.5 size-3.5 text-muted-foreground`,"aria-hidden":!0})]})}):null,(0,Q.jsx)(xr,{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)(Oa,{value:String(u),onValueChange:e=>{let t=Number(e);Number.isFinite(t)&&d(t)},className:`z-30 w-14`,children:[(0,Q.jsx)(ka,{"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)(Aa,{})}),(0,Q.jsx)(ja,{className:`min-w-16`,children:Fu.map(e=>(0,Q.jsx)(Ma,{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`&&B.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`&&B.data&&!B.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?B.isLoading&&!B.data?(0,Q.jsx)(Bu,{}):B.isError?(0,Q.jsx)(zu,{children:(0,Q.jsx)(Sr,{role:`alert`,"data-slot":`browse-error`,children:(0,Q.jsxs)(Fr,{children:[(0,Q.jsx)(Cr,{variant:`icon`,className:`bg-destructive/10 text-destructive`,children:(0,Q.jsx)(H,{icon:a,"aria-hidden":!0})}),(0,Q.jsx)(kr,{children:`Couldn’t load rows`}),(0,Q.jsx)(Mr,{children:B.error.message})]})})}):e.facet===`files`&&B.data?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,Q.jsx)(Pc,{store:e,child:t,tenant:o,data:B.data,fetching:B.isFetching,onRefresh:()=>void B.refetch()})}):pe?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,Q.jsx)(gu,{model:pe,facet:e.facet,storeRef:e.ref,childName:t.name,tenant:o,masked:B.data?.masked??!1,routedRole:B.data?.routedRole,limit:u,toolbarExtras:ge?_e:void 0,indexSearch:e.facet===`index`?{value:f,onChange:p,topK:m,onTopKChange:g}:void 0,insertOpen:M,onInsertOpenChange:N,asGate:P.asGate,asUserId:P.asUserId,onDeleteRows:le||U?void 0:e=>v(e),onViewportContextMenu:e.ref===`sql:oke_console`?void 0:ie?()=>S(!0):ae?()=>E(!0):oe?()=>O(!0):se?()=>j(!0):e.facet===`sql`&&!Hn(t)?()=>N(!0):void 0})}):null:(0,Q.jsx)(zu,{children:(0,Q.jsx)(Sr,{role:`status`,"data-slot":`browse-gate`,children:(0,Q.jsxs)(Fr,{children:[(0,Q.jsx)(Cr,{variant:`icon`,children:(0,Q.jsx)(H,{icon:He,"aria-hidden":!0})}),(0,Q.jsx)(kr,{children:`Select a tenant`}),(0,Q.jsx)(Mr,{children:`Tenancy is a compliance boundary, not a display filter — choose a tenant to browse its data.`})]})})}),U&&e.ref!==`sql:oke_console`?(0,Q.jsx)(ho,{open:y,onOpenChange:b,storeRef:e.ref,presentNames:(pe?.rows??[]).map(e=>e.id)}):null,oe&&e.ref!==`sql:oke_console`?(0,Q.jsx)(bs,{open:D,onOpenChange:O,storeRef:e.ref,tables:Zn(e.children).tables.map(e=>e.name)}):null,ae&&e.ref!==`sql:oke_console`?(0,Q.jsx)(fs,{open:w,onOpenChange:E,storeRef:e.ref}):null,se&&e.ref!==`sql:oke_console`?(0,Q.jsx)(Ns,{open:k,onOpenChange:j,storeRef:e.ref,tables:Zn(e.children).tables.map(e=>e.name)}):null,ie&&e.ref!==`sql:oke_console`?(0,Q.jsx)(Io,{open:x,onOpenChange:S,storeRef:e.ref,tables:Zn(e.children).tables.map(e=>e.name),manifest:n}):null,(0,Q.jsx)(Ps,{open:_!==null,onOpenChange:e=>{e||v(null)},phrase:`DELETE`,title:`Delete ${_?.length??0} ${_?.length===1?`row`:`rows`}`,description:`Permanently delete ${_?.length??0} item(s) from ${e.ref}${e.facet===`sql`?`/${t.name}`:``}. This is not a flow execution.`,pending:V.isPending,error:V.isError?V.error.message:null,onConfirm:me})]})}function zu({children:e}){return(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center px-6`,children:e})}function Bu(){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)(Tt,{className:`h-5 w-8`}),(0,Q.jsx)(Tt,{className:`h-5 w-16`}),(0,Q.jsx)(Tt,{className:`h-5 w-14`}),(0,Q.jsx)(Tt,{className:`ml-auto h-5 w-48`}),(0,Q.jsx)(Tt,{className:`h-5 w-6`}),(0,Q.jsx)(Tt,{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)(Tt,{className:`size-3.5`}),(0,Q.jsx)(Tt,{className:`h-3 w-20`}),(0,Q.jsx)(Tt,{className:`h-3 w-24`}),(0,Q.jsx)(Tt,{className:`h-3 w-12`}),(0,Q.jsx)(Tt,{className:`h-3 w-28`}),(0,Q.jsx)(Tt,{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)(Tt,{className:`size-3.5`}),(0,Q.jsx)(Tt,{className:`h-3 w-16`}),(0,Q.jsx)(Tt,{className:`h-3 w-20`}),(0,Q.jsx)(Tt,{className:`h-3 w-8`}),(0,Q.jsx)(Tt,{className:`h-3 w-24`}),(0,Q.jsx)(Tt,{className:`h-3 flex-1`})]},t))})]})}function Vu({store:e,child:t,manifest:n,tenancyDeclared:r,tenants:i,tenant:o,onTenantChange:s,runs:c=[],leading:l}){let u=e.migrationDrift,d=aa[e.facet],f=Hn(t)?0:Fi(t.piiColumns),[p,m]=(0,Z.useState)(!0);(0,Z.useEffect)(()=>{m(!0)},[t.effectRef]);let h=(0,Z.useMemo)(()=>new Set(e.children.map(e=>e.effectRef)),[e.children]),g=Di(c,h)??e.replicaLagMs,_=g==null?null:Vt(g),v=e.facet===`files`,y=Gn(t),b=t.rls===!0,x=ur(t,n,e.name),C=!!(u||g!==null||e.contentAddressed||f>0||y);return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`resource-panel`,children:[(0,Q.jsx)(nn,{dataSlot:`resource-header`,leading:l,icon:(0,Q.jsx)(H,{icon:v?je:d.icon,className:`size-4`}),wellClassName:d.wellClass,title:ar(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`:d.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:ea(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:ta(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)(Bi,{value:t.effectRef,label:`Copy effect ref`})]}):(0,Q.jsx)(Hu,{storeRef:e.ref,effectRef:t.effectRef})}),actions:C?(0,Q.jsxs)(`div`,{className:`flex h-full shrink-0 items-stretch`,"data-slot":`resource-status`,children:[g!==null&&_?(0,Q.jsxs)(Wu,{chipClassName:Ht(_),icon:(0,Q.jsx)(H,{icon:Me,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:Br(g)}),(0,Q.jsx)(`span`,{className:`opacity-70`,children:`lag`})]}):null,e.contentAddressed?(0,Q.jsx)(Wu,{children:`content-addressed`}):null,y?(0,Q.jsx)(Wu,{tone:b?`emerald`:`neutral`,icon:(0,Q.jsx)(H,{icon:b?D:Re,className:`size-3`,"aria-hidden":!0}),title:b?x>0?`Row-level security enabled · ${x} ${x===1?`policy`:`policies`}`:`Row-level security enabled`:`Row-level security disabled`,role:`status`,"data-slot":`resource-rls`,"data-rls":b?`on`:`off`,children:b&&x>0?`${x} RLS`:`RLS`}):null,f>0?(0,Q.jsxs)(Wu,{tone:p?`sky`:`amber`,icon:(0,Q.jsx)(H,{icon:ne,className:`size-3`,"aria-hidden":!0}),title:p?`PII masked on ${t.piiColumns.join(`, `)}. Click to show all cleartext (audited).`:`PII visible on ${t.piiColumns.join(`, `)}. Click to remask.`,pressed:p,ariaLabel:p?`PII masking on for ${f} columns. Show all.`:`PII visible for ${f} columns. Hide all.`,"data-slot":`pii-toggle`,onClick:()=>m(e=>!e),children:[f,` PII`]}):null,u?(0,Q.jsxs)(Wu,{tone:u.drifted?`amber`:`emerald`,icon:(0,Q.jsx)(H,{icon:u.drifted?a:S,className:`size-3`,"aria-hidden":!0}),title:`Migration — declared ${u.declared} / applied ${u.applied??`(none)`}`,role:`status`,"data-slot":`migration-drift`,"data-drifted":u.drifted?`true`:`false`,children:[u.drifted?`Drifted`:`In sync`,(0,Q.jsx)(`span`,{className:`font-mono opacity-70`,children:Gu(u.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)(H,{icon:a,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)(Ru,{store:e,child:t,manifest:n,tenancyDeclared:r,tenants:i,tenant:o,onTenantChange:s,piiMasked:p})]})}function Hu({storeRef:e,effectRef:t}){let n=ua(e,t);return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[11px] leading-none text-muted-foreground`,children:e}),n?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`text-border`,children:`·`}),(0,Q.jsx)(`code`,{className:`min-w-0 truncate font-mono text-[11px] leading-none text-foreground/70`,children:n})]}):null,(0,Q.jsx)(Bi,{value:t,label:`Copy effect ref`})]})}var Uu={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 Wu({tone:e=`neutral`,icon:t,title:n,children:r,role:i,"data-slot":a,"data-drifted":o,"data-rls":s,pressed:c,onClick:l,ariaLabel:u,chipClassName:d}){let f=J(Qe,`whitespace-nowrap`,d??Uu[e],l&&`cursor-pointer outline-none focus-visible:ring-2 focus-visible:ring-ring/40`),p=l?(0,Q.jsxs)(`button`,{type:`button`,className:f,"aria-pressed":c,"aria-label":u,"data-slot":a,"data-drifted":o,"data-rls":s,onClick:l,children:[t,r]}):(0,Q.jsxs)(`span`,{className:f,role:i,"data-slot":a,"data-drifted":o,"data-rls":s,children:[t,r]});return n?(0,Q.jsxs)(h,{children:[(0,Q.jsx)(L,{render:e=>(0,Q.jsx)(`span`,{...e,className:`flex self-stretch`,children:p})}),(0,Q.jsx)(C,{side:`bottom`,className:`max-w-xs text-[11px]`,children:n})]}):p}function Gu(e){return e.length>12?`${e.slice(0,12)}…`:e}function Ku({stores:e,selectedEffectRef:t,onSelect:n,queryFacet:r=null,onOpenQuery:i,schemaActive:a=!1,onOpenSchema:o,performanceActive:s=!1,performanceFacet:c=null,onOpenPerformance:l}){let[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)({}),[m,h]=(0,Z.useState)(ya),g=(0,Z.useMemo)(()=>oa(sa(e,u)),[e,u]),_=(0,Z.useMemo)(()=>xa(g,m),[g,m]),v=(0,Z.useMemo)(()=>ma(_),[_]),y=u.trim().length>0,b=v.length>0&&v.every(e=>pa(e,f)),x=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{if(!t)return;let n=ha(e,t).find(e=>e.startsWith(`facet:`));n&&p(e=>e[n]===!1?{...e,[n]:!0}:e);let r=x.current!==null&&x.current!==t;if(x.current=t,!r)return;let i=ca(e,t);i&&h(e=>{if(!e.has(i.store.facet))return e;let t=new Set(e);return t.delete(i.store.facet),ba(t),t})},[t,e]);let S=(e,t)=>{p(n=>n[e]===t?n:{...n,[e]:t})};return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`store-tree`,children:[(0,Q.jsx)(`div`,{className:`shrink-0 border-b border-border/60`,children:(0,Q.jsxs)(`div`,{className:J(et,`border-b-0`),children:[(0,Q.jsx)(Lr,{value:u,onChange:e=>d(e.target.value),placeholder:`Search stores…`,"aria-label":`Search stores`,"data-slot":`store-search`}),(0,Q.jsx)(qu,{hiddenFacets:m,onHiddenChange:(e,t)=>{h(n=>{if(n.has(e)===t)return n;let r=new Set(n);return t?r.add(e):r.delete(e),ba(r),r})}}),(0,Q.jsx)(dr,{allOpen:b,disabled:v.length===0,onToggle:()=>{let e=!b;p(t=>{let n={...t};for(let t of v)n[t]=e;return n})},dataSlot:`store-tree-expand-toggle`,className:`mr-1.5`})]})}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-x-hidden overflow-y-auto`,children:_.length===0?(0,Q.jsx)(`p`,{className:W,children:g.length===0?`No stores match.`:`All facets hidden.`}):(0,Q.jsx)(`div`,{className:`flex flex-col`,children:_.map(e=>{let u=da(e.facet);return(0,Q.jsx)(Ju,{band:e,open:pa(u,f),onOpenChange:e=>S(u,e),storeOpen:e=>y?f[e]!==!1:f[e]===!0,onStoreOpenChange:S,selectedEffectRef:t,onSelect:n,queryActive:r===e.facet,onOpenQuery:i&&(e.facet===`sql`||e.facet===`kv`)?()=>i(e.facet===`kv`?`kv`:`sql`):void 0,schemaActive:e.facet===`sql`&&a,onOpenSchema:e.facet===`sql`?o:void 0,performanceActive:(e.facet===`sql`||e.facet===`kv`)&&s&&(c??`sql`)===(e.facet===`kv`?`kv`:`sql`),onOpenPerformance:l&&(e.facet===`sql`||e.facet===`kv`)?()=>l(e.facet===`kv`?`kv`:`sql`):void 0},e.facet)})})})]})}function qu({hiddenFacets:e,onHiddenChange:t}){return(0,Q.jsx)(`div`,{className:`flex h-full shrink-0 items-stretch`,role:`group`,"aria-label":`Store facets`,"data-slot":`store-tree-facet-toggles`,children:na.map(n=>{let r=aa[n],i=!e.has(n);return(0,Q.jsx)(xr,{label:i?`Hide ${r.label}`:`Show ${r.label}`,className:`flex self-stretch`,children:(0,Q.jsx)(`button`,{type:`button`,"aria-label":i?`Hide ${r.label}`:`Show ${r.label}`,"aria-pressed":i,"data-slot":`store-tree-facet-toggle`,"data-facet":n,onClick:()=>t(n,i),className:J(Fe,i?u(r.wellClass):`text-muted-foreground/40 hover:text-muted-foreground`),children:(0,Q.jsx)(H,{icon:r.icon,className:We,"aria-hidden":!0})})},n)})})}function Ju({band:e,open:t,onOpenChange:r,storeOpen:i,onStoreOpenChange:a,selectedEffectRef:o,onSelect:s,queryActive:c,onOpenQuery:l,schemaActive:d,onOpenSchema:f,performanceActive:p,onOpenPerformance:m}){let h=aa[e.facet],g=e.stores.reduce((e,t)=>t.store.facet===`sql`?e+Zn(t.children).tables.length:e+t.children.length,0),_=e.stores.filter(e=>!la(e.store)).map(e=>e.store.ref),v=_.length>0&&_.every(e=>i(e)),y=()=>{let e=!v;for(let t of _)a(t,e);e&&r(!0)},b=(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(H,{icon:h.icon,className:J(We,u(h.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:qe,children:e.label}),(0,Q.jsx)(`span`,{className:Be,children:g})]})]});return(0,Q.jsx)(`section`,{"data-slot":`store-facet-band`,"data-facet":e.facet,"aria-label":e.label,className:n,children:(0,Q.jsxs)(Ir,{open:t,onOpenChange:r,children:[(0,Q.jsx)(Pr,{nativeButton:!1,className:_e,"data-slot":`store-facet-band-toggle`,render:n=>(0,Q.jsxs)(`div`,{...n,children:[(0,Q.jsx)(td,{open:t}),b,(0,Q.jsxs)(`span`,{className:J(ee,(d||c||p)&&`opacity-100`),children:[f?(0,Q.jsx)($u,{active:d,onOpen:f}):null,m?(0,Q.jsx)(ed,{active:p,onOpen:m}):null,l?(0,Q.jsx)(Qu,{facet:e.facet===`kv`?`kv`:`sql`,active:c,onOpen:l}):null,(0,Q.jsx)(dr,{allOpen:v,disabled:_.length===0,onToggle:y,collapseLabel:`Collapse all in ${e.label}`,expandLabel:`Expand all in ${e.label}`,dataSlot:`store-facet-expand-toggle`,disclose:!0,bare:!0})]})]})}),(0,Q.jsx)(jr,{children:(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:e.stores.map(e=>(0,Q.jsx)(Yu,{node:e,facetWellClass:h.wellClass,facetIcon:h.icon,open:i(e.store.ref),onOpenChange:t=>a(e.store.ref,t),tablesOpen:i(fa(e.store.ref)),onTablesOpenChange:t=>a(fa(e.store.ref),t),selectedEffectRef:o,onSelect:s},e.store.ref))})})]})})}function Yu({node:e,facetWellClass:t,facetIcon:n,open:r,onOpenChange:i,tablesOpen:a,onTablesOpenChange:o,selectedEffectRef:s,onSelect:c}){let l=e.children[0];return $i(e.store)&&l?(0,Q.jsx)(id,{store:e.store,child:l,selected:s===l.effectRef,onSelect:c}):la(e.store)&&l?(0,Q.jsx)(ad,{child:l,wellClass:t,icon:n,selected:s===l.effectRef,onSelect:c,nest:`store`}):(0,Q.jsx)(`li`,{"data-slot":`store-group`,"data-ref":e.store.ref,children:(0,Q.jsxs)(Ir,{open:r,onOpenChange:i,children:[(0,Q.jsx)(Pr,{nativeButton:!1,className:J(De,`group/store pl-4`),"data-slot":`store-group-toggle`,render:t=>(0,Q.jsxs)(`div`,{...t,children:[(0,Q.jsx)(td,{open:r}),(0,Q.jsx)(H,{icon:je,className:J(We,`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:Be,children:e.store.facet===`sql`?Zn(e.children).tables.length:e.children.length}),e.store.facet===`files`?(0,Q.jsx)(rd,{driverId:e.store.driverId}):null]})}),(0,Q.jsx)(jr,{children:(0,Q.jsx)(Xu,{node:e,facetWellClass:t,facetIcon:n,tablesOpen:a,onTablesOpenChange:o,selectedEffectRef:s,onSelect:c})})]})})}function Xu({node:e,facetWellClass:n,facetIcon:r,tablesOpen:i,onTablesOpenChange:a,selectedEffectRef:o,onSelect:s}){let c=Zn(e.children);return e.store.facet!==`sql`||c.catalog.length===0?(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:e.children.map(t=>(0,Q.jsx)(ad,{child:t,wellClass:n,icon:e.store.facet===`sql`?Ue:e.store.facet===`files`?je:r,hint:e.store.facet===`files`?`bucket`:void 0,selected:o===t.effectRef,onSelect:s},t.effectRef))}):(0,Q.jsxs)(`ul`,{className:`flex flex-col`,children:[(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(Ir,{open:i,onOpenChange:a,children:[(0,Q.jsx)(Pr,{nativeButton:!1,className:J(De,`group/tables group/store pl-6`),"data-slot":`store-tables-toggle`,render:e=>(0,Q.jsxs)(`div`,{...e,children:[(0,Q.jsx)(td,{open:i}),(0,Q.jsx)(H,{icon:t,className:J(We,u(n)),"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:Be,children:c.tables.length})]})}),(0,Q.jsx)(jr,{children:(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:c.tables.map(e=>(0,Q.jsx)(ad,{child:e,wellClass:n,icon:Ue,nest:`deep`,selected:o===e.effectRef,onSelect:s},e.effectRef))})})]})}),c.catalog.map(e=>(0,Q.jsx)(ad,{child:e,wellClass:n,icon:Zu(e),selected:o===e.effectRef,onSelect:s},e.effectRef))]})}function Zu(e){let t=cr(e);return t===`index`?fe:t===`function`?xe:t===`trigger`?ve:t===`extension`?s:t===`policy`?ne:je}function Qu({facet:e,active:t,onOpen:n}){let r=e===`sql`?`SQL console`:`KV console`;return(0,Q.jsxs)(h,{children:[(0,Q.jsx)(L,{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:J(`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)(H,{icon:se,className:`size-3.5`,"aria-hidden":!0})})}),(0,Q.jsx)(C,{side:`bottom`,className:`text-[11px]`,children:r})]})}function $u({active:e,onOpen:t}){return(0,Q.jsxs)(h,{children:[(0,Q.jsx)(L,{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:J(`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)(H,{icon:Ze,className:`size-3.5`,"aria-hidden":!0})})}),(0,Q.jsx)(C,{side:`bottom`,className:`text-[11px]`,children:`Schema visualizer`})]})}function ed({active:e,onOpen:t}){return(0,Q.jsxs)(h,{children:[(0,Q.jsx)(L,{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:J(`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)(H,{icon:p,className:`size-3.5`,"aria-hidden":!0})})}),(0,Q.jsx)(C,{side:`bottom`,className:`text-[11px]`,children:`Query performance`})]})}function td({open:e}){return(0,Q.jsx)(H,{icon:M,className:J(Ne,!e&&`-rotate-90`),"aria-hidden":!0})}function nd({enabled:e}){let t=e?`RLS enabled`:`RLS disabled`;return(0,Q.jsxs)(h,{children:[(0,Q.jsx)(L,{render:n=>(0,Q.jsx)(`span`,{...n,"data-slot":`store-table-rls`,"data-rls":e?`on`:`off`,"aria-label":t,className:J(We,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)(H,{icon:e?D:Re,className:`size-3.5`,"aria-hidden":!0})})}),(0,Q.jsx)(C,{side:`right`,children:t})]})}function rd({driverId:e}){return(0,Q.jsxs)(h,{children:[(0,Q.jsx)(L,{render:t=>(0,Q.jsx)(`span`,{...t,className:`shrink-0 font-mono text-[10px] text-muted-foreground`,"data-slot":`files-driver`,children:ea(e)})}),(0,Q.jsx)(C,{side:`right`,className:`text-[11px]`,children:ta(e)})]})}function id({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:J(be,`group/child pl-4`,n&&`bg-muted/70 text-foreground`),children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:J(he,n?Xe:`bg-transparent`)}),(0,Q.jsx)(H,{icon:je,className:J(We,u(aa.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)(rd,{driverId:e.driverId})]})})}function ad({child:e,wellClass:t,icon:n,selected:r,onSelect:i,hint:a,nest:o=`child`}){return(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,"data-slot":`store-child-item`,"data-effect-ref":e.effectRef,"aria-current":r?`true`:void 0,onClick:()=>i(e.effectRef),className:J(be,`group/child`,o===`store`?`pl-4`:o===`deep`?`pl-12`:`pl-8`,r&&`bg-muted/70 text-foreground`),children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:J(he,r?Xe:`bg-transparent`)}),(0,Q.jsx)(H,{icon:n,className:J(We,u(t)),"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:ar(e)}),a?(0,Q.jsx)(`span`,{className:`shrink-0 text-[10px] tracking-[0.08em] text-muted-foreground/70 uppercase`,children:a}):null,Gn(e)?(0,Q.jsx)(nd,{enabled:e.rls===!0}):null]})})}var od=`sql:oke_console`;function sd(e){return e?`SELECT *\nFROM "${e}"\nLIMIT 50;`:`SELECT 1;`}var cd=/^SELECT \*\nFROM "([^"]+)"\nLIMIT 50;$/,ld=/^\/\/ list · get · set · delete · ttl\nlist(?: (.+))?$/;function ud(e,t,n=Math.random){let r=cd.exec(e);if(!r)return e;let i=r[1];return i&&t.includes(i)?e:sd(hd(t,n))}function dd(e,t,n=Math.random){let r=ld.exec(e);if(!r)return e;let i=r[1];if(!i)return e;let a=i.endsWith(`:`)?i.slice(0,-1):i;if(t.includes(a))return e;let o=hd(t,n);return pd(o?`${o}:`:void 0)}function fd(e,t,n){return n===`sql`?ud(e,t):dd(e,t)}function pd(e){return e?`// list · get · set · delete · ttl\nlist ${e}`:`// list · get · set · delete · ttl
|
|
30
|
-
list`}function md(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 hd(e,t=Math.random){if(e.length!==0)return e[Math.min(e.length-1,Math.floor(t()*e.length))]}function gd(e,t=Math.random){return hd(e.children.map(e=>e.name),t)}function _d(e){return e===od}function vd(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 yd(){return ot({mutationFn:async e=>{let t=await Le(e),n=vd(t);if(n)throw n;if(!t.data)throw Error(`Empty advise result`);return t.data}})}var bd=[`console.store.sql.locks`],xd=1e4;function Sd(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 Cd(e){return m({queryKey:[...bd,e],enabled:e!==null,refetchInterval:xd,queryFn:async()=>{if(!e)throw Error(`Missing store ref`);let t=await E(e),n=Sd(t);if(n)throw n;if(!t.data)throw Error(`Empty SQL locks`);return t.data}})}var wd=[`console.store.sql.stats`];function Td(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 Ed(e){return m({queryKey:[...wd,e],enabled:e!==null,queryFn:async()=>{if(!e)throw Error(`Missing store ref`);let t=await oe(e),n=Td(t);if(n)throw n;if(!t.data)throw Error(`Empty SQL stats`);return t.data}})}function Dd(e){return e?e.installed?`on`:e.available?`enable`:`cta`:null}var Od=[`console.store.kv.stats`];function kd(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 Ad(e){return m({queryKey:[...Od,e],enabled:e!==null,queryFn:async()=>{if(!e)throw Error(`Missing store ref`);let t=await b(e),n=kd(t);if(n)throw n;if(!t.data)throw Error(`Empty KV stats`);return t.data}})}function jd({stores:e,selectedEffectRef:t,tenant:n,leading:r}){let i=md(e,`kv`,t),[a,o]=(0,Z.useState)(!1),s=Ad(i?{ref:i.ref,...n?{tenant:n}:{},...a?{revealPii:!0}:{}}:null),c=Id(s.error),l=Ld(s.error),u=(0,Z.useMemo)(()=>(s.data?.commands??[]).map(Nd),[s.data?.commands]),d=(0,Z.useMemo)(()=>(s.data?.slowlog??[]).map(Pd),[s.data?.slowlog]);if(!i)return(0,Q.jsx)(Pi,{icon:p,title:`No KV store`,description:`KV performance reads INFO / COMMANDSTATS / SLOWLOG on a redis-backed namespace.`,leading:r});if(l===`KvStatsUnsupported`)return(0,Q.jsx)(Pi,{leading:r,icon:p,title:`Engine telemetry unavailable`,description:c??`KV stats are not available on this driver (in-process memory has no INFO / SLOWLOG).`});let f=s.data?.kpis;return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-slot":`store-kv-performance`,children:[(0,Q.jsx)(nn,{dataSlot:`store-kv-performance-header`,leading:r,icon:(0,Q.jsx)(H,{icon:p,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)(zi,{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: `,Ie,`. SLOWLOG args are keys and values — collapsed until reveal. Limitation: `,Ae,`. No hot-key table (OSS Redis does not expose one without MONITOR).`]}),(0,Q.jsxs)(`div`,{className:Se,children:[(0,Q.jsx)(Md,{label:`Hit rate`,value:Fd(f?.hitRate??null),title:`keyspace_hits / (hits + misses)`}),(0,Q.jsx)(Md,{label:`Ops / sec`,value:f?.opsPerSec==null?`—`:String(f.opsPerSec),title:`instantaneous_ops_per_sec`}),(0,Q.jsx)(Md,{label:`Evicted`,value:f?.evictedKeys==null?`—`:String(f.evictedKeys),title:`evicted_keys`}),(0,Q.jsx)(Md,{label:`Expired`,value:f?.expiredKeys==null?`—`:String(f.expiredKeys),title:`expired_keys`})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,Q.jsx)(Si,{rows:u,error:c,pending:s.isPending,meta:s.data?`${s.data.commands.length} commands`:null,storeRef:i.ref})}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 border-t border-border/60`,children:(0,Q.jsx)(Si,{rows:d,error:null,pending:s.isPending&&!s.data,meta:s.data?`${s.data.slowlog.length} slowlog · ${s.data.masked?`args collapsed`:`args revealed`}`:`slowlog`,storeRef:i.ref})})]})}function Md({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 Pd(e){return{command:e.command,duration_us:e.durationUs,args:e.args.join(` `),id:e.id}}function Fd(e){return e==null?`—`:`${(e*100).toFixed(2)}%`}function Id(e){return e?e instanceof Error?e.message:String(e):null}function Ld(e){return!e||typeof e!=`object`||!(`code`in e)?null:typeof e.code==`string`?e.code:null}function Rd({stores:e,selectedEffectRef:t,tenant:n,facet:r=`sql`,leading:i}){if(r===`kv`)return(0,Q.jsx)(jd,{stores:e,selectedEffectRef:t,tenant:n,leading:i});let a=md(e,`sql`,t),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(null),u=a?{ref:a.ref,...n?{tenant:n}:{}}:null,d=Ed(u),f=Cd(a?{...u,...o?{revealPii:!0}:{}}:null),m=yd(),h=Zo(),g=Kd(d.error),_=qd(d.error),v=Kd(f.error),y=(0,Z.useMemo)(()=>(d.data?.statements??[]).map(Hd),[d.data?.statements]),b=(0,Z.useMemo)(()=>(f.data?.rows??[]).map(Ud),[f.data?.rows]);if(!a)return(0,Q.jsx)(Pi,{icon:p,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)(Pi,{leading:i,icon:p,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)(Pi,{leading:i,icon:p,title:`Engine telemetry unavailable`,description:g??`pg_stat_statements is not available on this driver (memory, pglite, or CockroachDB).`});let x=d.data?.advisor,S=Dd(x),C=d.data?.kpis,w=Va.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)(nn,{dataSlot:`store-performance-header`,leading:i,icon:(0,Q.jsx)(H,{icon:p,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)(zi,{piiMasked:!o,disabled:f.isPending,onToggle:()=>s(e=>!e)}),(0,Q.jsx)(zd,{advisor:x,pending:h.isPending,onEnable:()=>{h.mutateAsync({ref:a.ref,sql:co(`index_advisor`,{cascade:!0}),allowWrite:!0,...n?{tenant:n}:{}}).then(()=>d.refetch())}})]})}),(0,Q.jsxs)(`p`,{className:`shrink-0 border-b border-border/60 bg-amber-500/8 px-3 py-1.5 text-[11px] leading-relaxed text-amber-900 dark:text-amber-200`,"data-slot":`store-sql-stats-pii-gap`,role:`note`,children:[`Engine-native query text from pg_stat_statements (usually`,` `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`$n`}),` fingerprints) and live lock activity. Live`,` `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`pg_stat_activity.query`}),` can contain literals — collapsed until reveal. Limitation: `,Ce,`. 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:Se,children:[(0,Q.jsx)(Vd,{label:`Slow queries`,value:C?String(C.slowQueries):`—`,title:`Statements with mean exec ≥ 100ms`}),(0,Q.jsx)(Vd,{label:`Cache hit rate`,value:Wd(C?.cacheHitRate??null),title:`shared_blks_hit / (hit + read) across listed statements`}),(0,Q.jsx)(Vd,{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)(Si,{rows:y,error:_&&_!==`PgStatStatementsNotCreated`?g:null,pending:d.isPending,meta:d.data?`${d.data.rowCount} statements${d.data.truncated?` (capped)`:``}`:null,storeRef:a.ref})}),x?.installed&&(d.data?.statements.length??0)>0?(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1.5 border-t border-border/60 px-3 py-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:`Suggest indexes`}),(d.data?.statements??[]).slice(0,6).map((e,t)=>(0,Q.jsxs)(z,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 rounded-none text-[11px]`,disabled:!e.query||m.isPending,onClick:()=>{l(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)(Bd,{query:c.query,result:m.data??null,error:Kd(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)(Si,{rows:b,error:v,pending:f.isPending&&!f.data,meta:f.data?`${f.data.rows.length} blocking pair${f.data.rows.length===1?``:`s`} · polling`:`locks`,storeRef:a.ref})})]})}function zd({advisor:e,pending:t,onEnable:n}){let r=Dd(e);return r===`on`?(0,Q.jsx)(`span`,{className:J(Qe,tt),"data-slot":`index-advisor-on`,children:`Index Advisor on`}):r===`cta`||r!==`enable`?null:(0,Q.jsx)(z,{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 Bd({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 `,Gd(t.totalCostBefore),` → `,Gd(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)(z,{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 Vd({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 Hd(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:Wd(e.cacheHitRate)}}function Ud(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 Wd(e){return e==null?`—`:`${(e*100).toFixed(2)}%`}function Gd(e){return e==null?`—`:String(e)}function Kd(e){return e?e instanceof Error?e.message:String(e):null}function qd(e){return!e||typeof e!=`object`||!(`code`in e)?null:typeof e.code==`string`?e.code:null}var Jd=/^\s*(\/\/|#|--)/,Yd=/^(list|get|set|delete|ttl)\b/i;function Xd(e){let t=$d(e);if(t.length===0)return{kind:`list`,prefix:``};let n=Yd.exec(t)?.[1]?.toLowerCase();if(n===`set`)return nf(t);if(n===`list`)return ef(t);if(n===`get`||n===`delete`||n===`ttl`)return tf(n,t);let r=Qd(t)??t;return/\s/.test(r)?{kind:`error`,message:"Use `list`, `get`, `set`, `delete`, or `ttl`."}:{kind:`list`,prefix:r}}function Zd(e){let t={};return e.keepValue||(t.value=e.value),e.ttl!==void 0&&(t.ttl=e.ttl),t}function Qd(e){let t=e.split(`
|
|
31
|
-
`);for(let e=t.length-1;e>=0;--e){let n=t[e]?.trim()??``;if(!(n.length===0||Jd.test(n)))return n}return null}function $d(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||Jd.test(r)||Yd.test(r)&&(n=e)}return n>=0?t.slice(n).join(`
|
|
33
|
-
`).trim():Qd(e)??``}function ef(e){if(e.includes(`(`)){let t=rf(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=af(t.args[0]??``,`list prefix`);return n.kind===`error`?n:{kind:`list`,prefix:n.value}}let t=/^list(?:\s+(\S.*))?$/i.exec(Qd(e)??e);return t?{kind:`list`,prefix:t[1]?.trim()??``}:{kind:`error`,message:'Use `list [prefix]` or `list("prefix")`.'}}function tf(e,t){if(t.includes(`(`)){let n=rf(t,e);if(n.kind===`error`)return n;if(n.args.length!==1)return{kind:`error`,message:`${e} requires a key.`};let r=af(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(Qd(t)??t)?.[1]?.trim()??``;return n.length===0?{kind:`error`,message:`${e} requires a key.`}:{kind:e,key:n}}function nf(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=rf(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=of(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=of(a);if(!e.ok)return{kind:`error`,message:`set value: ${e.error}`};s=e.value}let c;if(r[2]!==void 0){let e=of(r[2]);if(!e.ok||typeof e.value!=`string`)return{kind:`error`,message:`TTL must be a duration string like "30m".`};let t=Kr(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 rf(e,t){let n=e.indexOf(`(`);if(n<0)return{kind:`error`,message:`${t} requires parentheses.`};let r=cf(e,n);if(r<0)return{kind:`error`,message:`Unclosed ${t}(…).`};let i=e.slice(r+1).trim();return i.length>0&&!Jd.test(i)?{kind:`error`,message:`Unexpected input after ${t}(…).`}:{kind:`ok`,args:sf(e.slice(n+1,r))}}function af(e,t){let n=of(e);return!n.ok||typeof n.value!=`string`?{kind:`error`,message:`${t} must be a string.`}:{kind:`ok`,value:n.value}}function of(e){try{return{ok:!0,value:JSON.parse(e)}}catch(e){return{ok:!1,error:e instanceof Error?e.message:`invalid JSON`}}}function sf(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 cf(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 lf=8,uf=24,df=24;function ff(e){return/^Query \d+$/.test(e)}function pf(e){let t=new Set(e.map(e=>e.title)),n=1;for(;t.has(`Query ${n}`);)n+=1;return`Query ${n}`}function mf(e,t){return e.length>=lf?e:[...e,{id:Af(),title:pf(e),text:t}]}function hf(e,t,n){let r=e.filter(e=>e.id!==t);return r.length>0?r:[{id:Af(),title:`Query 1`,text:n}]}function gf(e,t,n){return e.map(e=>e.id===t?{...e,text:n}:e)}function _f(e,t,n){let r=n.trim().replace(/\s+/g,` `),i=r.length>0?r.slice(0,48):pf(e.filter(e=>e.id!==t));return e.map(e=>e.id===t?{...e,title:i}:e)}function vf(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,df)}function yf(e,t){return[{...t,id:Af()},...e].slice(0,uf)}function bf(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 xf(e){let t=Df(e),n=If(Pf(),t,jf);if(n)return n;let r=If(Ff(),t,jf);return r&&Lf(Pf(),t,r),r}function Sf(e,t){Lf(Pf(),Df(e),t)}function Cf(e){return If(Ff(),Of(e),Mf)??[]}function wf(e,t){Lf(Ff(),Of(e),t)}function Tf(e){return If(Pf(),kf(e),Nf)??[]}function Ef(e,t){Lf(Pf(),kf(e),t)}function Df(e){return`oke_store_query_tabs_${e}`}function Of(e){return`oke_store_query_history_${e}`}function kf(e){return`oke_store_query_saved_${e}`}function Af(){return`q_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function jf(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 Mf(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 Nf(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 Pf(){try{return typeof localStorage>`u`?null:localStorage}catch{return null}}function Ff(){try{return typeof sessionStorage>`u`?null:sessionStorage}catch{return null}}function If(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 Lf(e,t,n){if(e)try{e.setItem(t,JSON.stringify(n))}catch{}}var Rf=/^\s*(\/\/|#|--)/,zf=/^(list|get|set|delete|ttl)\b/i;function Bf(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||Rf.test(e)){n.push(e),r+=1;continue}let i=r+1;if(zf.test(e))for(;i<t.length;){let e=t[i]?.trim()??``;if(zf.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||Rf.test(e)){o.unshift(a.pop()?.trim()??``);continue}break}n.push(Vf(a.join(`
|
|
36
|
-
`))),n.push(...o),r=i}return n.join(`
|
|
37
|
-
`).replace(/\n{3,}/g,`
|
|
38
|
-
|
|
39
|
-
`).trim()}function Vf(e){let t=Xd(e);return t.kind===`error`?e.trim():Hf(t)}function Hf(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`:Uf(e.value)];return e.ttl!==void 0&&e.ttl!==null&&t.push(JSON.stringify(e.ttl)),`set(${t.join(`, `)})`}}}function Uf(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 Wf(e,t,n,r){let i=e?.stores?.[t]?.tables?.[n];return i?.columns?Gf(i.columns,r):[]}function Gf(e,t){return Object.entries(e).map(([e,n])=>Kf(e,n,t?.[e]))}function Kf(e,t,n){let r=qf(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 qf(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 Jf(e,t,n){if(e){let r=Wf(n,e.name,t.name,t.columnDescriptions);if(r.length>0)return r}let r=Ii(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 Yf(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,Xf(r));return[...t.entries()].map(([e,t])=>({name:e,type:t}))}function Xf(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 Zf(e,t){if(!e)return[];let n=new Map(e.facet===`sql`?xn([e],t).map(e=>[e.name,e]):[]);return e.children.filter(e=>!Hn(e)).map(r=>({name:r.name,columns:Jf(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 Qf({store:e,facet:t,manifest:n,onPickTable:r,onPickColumn:i,onCollapse:a,tenant:o=null,tenancyDeclared:s=!1}){let c=e?.children??[],l=t===`sql`,u=(0,Z.useMemo)(()=>Zf(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:J(Se,`justify-between px-2`),children:[(0,Q.jsx)(`p`,{className:J(B,`min-w-0 truncate font-mono`),children:l?`Schema`:`Namespaces`}),a?(0,Q.jsx)(xr,{label:`Collapse schema`,className:`flex self-stretch`,children:(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Collapse schema`,"data-slot":`store-query-schema-collapse`,onClick:a,className:Fe,children:(0,Q.jsx)(H,{icon:j,className:`size-3.5`})})}):null]}),(0,Q.jsx)(`ul`,{className:`min-h-0 flex-1 overflow-y-auto`,children:c.length===0?(0,Q.jsx)(`li`,{className:`px-2 py-4 text-[11px] text-muted-foreground`,children:`No resources.`}):c.map(a=>(0,Q.jsx)($f,{store:e,child:a,facet:t,manifest:n,sqlColumns:u.find(e=>e.name===a.name)?.columns,onPickTable:r,onPickColumn:i,tenant:o,tenancyDeclared:s},a.effectRef))})]})}function $f({store:e,child:t,facet:n,manifest:r,sqlColumns:i,onPickTable:a,onPickColumn:o,tenant:s,tenancyDeclared:c}){let l=n===`sql`,[u,d]=(0,Z.useState)(!0),f=i??Jf(e,t,r),p=!l||f.length>0;return(0,Q.jsxs)(`li`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center`,children:[p?(0,Q.jsx)(`button`,{type:`button`,"aria-expanded":u,"aria-label":`${u?`Collapse`:`Expand`} ${t.name}`,onClick:()=>d(e=>!e),className:de,children:(0,Q.jsx)(H,{icon:M,className:J(`size-3 transition-transform`,!u&&`-rotate-90`)})}):(0,Q.jsx)(`span`,{className:`size-6`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>a(t.name),className:`min-w-0 flex-1 truncate px-2 py-1.5 text-left font-mono text-[11px] text-foreground hover:bg-muted/50`,title:l?`SELECT * FROM "${t.name}"`:`list ${t.name}:`,children:t.name})]}),l&&u&&f.length>0?(0,Q.jsx)(`ul`,{className:`border-l border-border/60 ml-3`,children:f.map(e=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>o(t.name,e.name),className:`flex w-full items-center gap-1.5 px-2 py-1 text-left hover:bg-muted/50`,children:[(0,Q.jsx)(Li,{primaryKey:e.primaryKey,foreignKey:`references`in e&&e.references!==void 0,unique:`unique`in e?e.unique:void 0,inferred:`inferredRef`in e?e.inferredRef:void 0}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[10px] text-muted-foreground`,children:e.name}),`references`in e&&e.references?.table?(0,Q.jsxs)(`span`,{className:`max-w-[4rem] shrink-0 truncate font-mono text-[8px] text-muted-foreground`,children:[`→ `,e.references.table]}):null,(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[9px] tracking-wide text-muted-foreground/70 uppercase`,children:e.type===`unknown`?``:e.type}),e.pii?(0,Q.jsx)(`span`,{className:`shrink-0 rounded border border-sky-500/30 px-1 text-[8px] text-sky-700 dark:text-sky-400`,children:`PII`}):null]})},e.name))}):null,!l&&u&&e?(0,Q.jsx)(ep,{store:e,namespace:t.name,tenant:s,tenancyDeclared:c,onPickField:e=>o(t.name,e)}):null]})}function ep({store:e,namespace:t,tenant:n,tenancyDeclared:r,onPickField:i}){let a=!r||n!==null&&n.length>0,o=rr({ref:e.ref,child:t,prefix:`${t}:`,limit:40,...n?{tenant:n}:{}},a),s=Yf((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 tp({facet:e,onExpand:t}){let n=e===`sql`?`Schema`:`Fields`;return(0,Q.jsx)(xr,{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)(H,{icon:_,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 np({facet:e,stores:t,selectedEffectRef:n,tenancyDeclared:r,tenants:i,tenant:s,onTenantChange:l,manifest:u=null,leading:d}){let p=aa[e],m=(0,Z.useMemo)(()=>t.filter(t=>t.facet===e),[t,e]),[h,g]=(0,Z.useState)(()=>md(t,e,n)?.ref??m[0]?.ref??``),_=m.find(e=>e.ref===h)??md(m,e,null),v=op(_,e,n),y=_?.children.map(e=>e.name)??[],[b,x]=(0,Z.useState)(()=>ap(xf(e)??[{id:`q_1`,title:`Query 1`,text:v}],y,e)),[S,C]=(0,Z.useState)(()=>b[0]?.id??`q_1`),w=b.find(e=>e.id===S)??b[0],T=w?.text??v,[E,D]=(0,Z.useState)(null),[O,k]=(0,Z.useState)(null),[A,j]=(0,Z.useState)(null),[N,F]=(0,Z.useState)(null),[ee,L]=(0,Z.useState)(!1),[te,V]=(0,Z.useState)(!1),[ne,re]=(0,Z.useState)(!0),[U,ae]=(0,Z.useState)({asGate:null,asUserId:null}),[oe,ce]=(0,Z.useState)(!0),[le,ue]=(0,Z.useState)(()=>Cf(e)),[de,fe]=(0,Z.useState)(()=>Tf(e)),[pe,me]=(0,Z.useState)(!1),[W,he]=(0,Z.useState)(null),[ge,_e]=(0,Z.useState)(``),[ve,be]=(0,Z.useState)({start:0,end:0}),[xe,Ce]=(0,Z.useState)([]),[we,Te]=(0,Z.useState)(0),[Ee,De]=(0,Z.useState)(!1),Oe=(0,Z.useRef)(null),G=(0,Z.useRef)(!1),Ae=(0,Z.useRef)(null),je=Zo(),Me=P(),Ne=!r||s!==null&&s.length>0,K=_?_d(_.ref):!1,q=e===`sql`,Pe=br(`Enter`),Ie=br(`S`),Le=(0,Z.useMemo)(()=>Zf(_,u),[_,u]),Re=(0,Z.useMemo)(()=>q?$r(T):[],[q,T]),ze=(0,Z.useMemo)(()=>Re.map(e=>e.startLine),[Re]),Be=ve.end!==ve.start,Ve=(0,Z.useMemo)(()=>q?ei(T,ve.start,ve.end,`current`):[T],[ve.end,ve.start,q,T]),He=q&&Ve.some(e=>Zr(e));(0,Z.useEffect)(()=>{let r=md(t,e,n);r&&g(e=>m.some(t=>t.ref===e)?e:r.ref)},[t,e,n,m]);let Ue=y.join(`\0`);(0,Z.useEffect)(()=>{let t=Ue.length===0?[]:Ue.split(`\0`);t.length!==0&&x(n=>ap(n,t,e))},[Ue,e]),(0,Z.useEffect)(()=>{Sf(e,b)},[e,b]),(0,Z.useEffect)(()=>{Ef(e,de)},[e,de]),(0,Z.useEffect)(()=>()=>{Ae.current!==null&&window.clearTimeout(Ae.current)},[]);let We=e=>{w&&x(t=>gf(t,w.id,e))},qe=t=>{ue(n=>{let r=yf(n,t);return wf(e,r),r})},Je=e=>{let t=Math.max(0,Date.now()-e.started);Ce([]),Te(0),D(e.nextRows),k(e.nextMeta?`${e.nextMeta} · ${t}ms`:`${t}ms`),j(e.sqlText),F(e.nextError),qe({at:Date.now(),storeRef:_?.ref??``,text:e.sqlText,ok:e.nextError===null,rowCount:e.nextRows?.length??null,durationMs:t,...e.nextError?{error:e.nextError}:{}})},Xe=(e,t)=>{let n=e[t];Ce(e),Te(t),D(n?.rows??null),F(n?.error??null),k(n?.meta??null),j(n?.executed??e.map(e=>e.executed).join(`
|
|
40
|
-
`)??null)},Ze=(e,t=!ne,n=U)=>{if(!_)return;if(ce(!0),F(null),!Ne){F(`Select a tenant first.`);return}if(K){F(`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){F(`Nothing to run.`);return}let i=Date.now();De(!0),Ce([]),Te(0),(async()=>{try{let e=[],a=!1;for(let i of r){let r=ii(i);r&&(a=!0);try{let a=await je.mutateAsync({ref:_.ref,sql:i,...r?{allowWrite:!0}:{},...t?{revealPii:!0}:{},...n.asGate?{asGate:n.asGate}:{},...n.asUserId?{asUserId:n.asUserId}:{},...s?{tenant:s}:{}}),o=ip(a.rows),c=[o===null?`${a.rows.length} row${a.rows.length===1?``:`s`}`:`${o} change${o===1?``:`s`}`,`routed ${a.routedRole}`];if(a.masked?c.push(`PII masked`):t&&c.push(`PII visible`),a.rls?.gate??a.asGate){let e=a.rls?.userId?`${a.rls.gate} / ${a.rls.userId}`:a.rls?.gate??a.asGate;c.push(a.gateApplied||a.rls?.applied?`as ${e}`:`as ${e} (not applied)`)}e.push({label:ai(i),rows:a.rows,error:null,meta:c.join(` · `),executed:i})}catch(t){e.push({label:ai(i),rows:null,error:t instanceof Error?t.message:String(t),meta:null,executed:i});break}}a&&Me.invalidateQueries({queryKey:fr});let o=Math.max(0,Date.now()-i),c=e[e.length-1],l=r.join(`
|
|
41
|
-
`);Xe(e.map(e=>({...e,meta:e.meta?`${e.meta} · ${o}ms`:e.error?null:`${o}ms`})),Math.max(0,e.length-1)),qe({at:Date.now(),storeRef:_.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{De(!1)}})()},Qe=(e,t=!ne,n=U)=>{if(!_)return;if(ce(!0),F(null),!Ne){F(`Select a tenant first.`);return}if(q){Ze([e],t,n);return}let r=Date.now(),i=Xd(e);if(i.kind===`error`){F(i.message);return}L(!0);let a=s?{tenant:s}:{};(async()=>{try{if(i.kind===`delete`){let t=await nt({ref:_.ref,keys:[i.key],...a});if(t.error){Je({sqlText:e,nextRows:null,nextMeta:null,nextError:rp(t.error),started:r});return}await Me.invalidateQueries({queryKey:fr});let n=t.data?.deleted??0;Je({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 o({ref:_.ref,key:i.key,...a,patch:Zd(i),commit:!0});if(t.error){Je({sqlText:e,nextRows:null,nextMeta:null,nextError:rp(t.error),started:r});return}await Me.invalidateQueries({queryKey:fr})}let t=i.kind===`list`?i.prefix:i.key,n=await ie({ref:_.ref,prefix:t,limit:i.kind===`list`?200:1,...a});if(n.error){Je({sqlText:e,nextRows:null,nextMeta:null,nextError:rp(n.error),started:r});return}let s=n.data?.keys??[],c=i.kind===`list`?s:s.filter(e=>e.key===i.key);if(i.kind===`ttl`){let t=c[0];Je({sqlText:e,nextRows:[{key:i.key,ttlMs:t?.ttlMs??null,ttl:ri(t?.ttlMs??null)}],nextMeta:t?`ttl ${i.key}`:`ttl ${i.key} · missing`,nextError:null,started:r});return}let l=c.length>0?c.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}]:[];Je({sqlText:e,nextRows:l,nextMeta:i.kind===`set`?`set ${i.key}`:`${l.length} key${l.length===1?``:`s`}`,nextError:null,started:r})}finally{L(!1)}})()},$e=()=>{if(q){Ze(Ve);return}let e=Math.min(ve.start,ve.end),t=Math.max(ve.start,ve.end);Qe(t>e?T.slice(e,t):T)},et=()=>{Ze(ei(T,ve.start,ve.end,`all`))},tt=e=>{Ze(Ve.map(t=>Ni(t,e)))},it=e=>{let t=Re.find(t=>t.startLine===e);t&&Ze([t.text])},at=t=>{let n=m.find(e=>e.ref===t);g(t),w&&x(t=>gf(t,w.id,op(n,e,null))),D(null),k(null),j(null),F(null),Ce([]),Te(0)},ot=e=>{We(q?sd(e):pd(`${e}:`))},st=()=>{let t=mf(b,op(_,e,null)),n=t[t.length-1];!n||t===b||(x(t),C(n.id))},ct=e=>{ff(e.title)||(fe(t=>vf(t,{id:e.id,title:e.title,text:e.text})),me(!0),Ae.current!==null&&window.clearTimeout(Ae.current),Ae.current=window.setTimeout(()=>me(!1),1200))},lt=(e,t)=>{let n=_f(b,e,t);if(x(n),he(null),!G.current)return;G.current=!1;let r=n.find(t=>t.id===e);r&&ct(r)},ut=()=>{G.current=!1,he(null)},dt=e=>{C(e.id),he(e.id),_e(e.title)},ft=()=>{if(w){if(ff(w.title)){G.current=!0,dt(w);return}ct(w)}},pt=e=>{if(b.find(t=>t.id===e.id)){x(t=>gf(_f(t,e.id,e.title),e.id,e.text)),C(e.id);return}if(b.length>=8){if(!w)return;x(t=>gf(_f(t,w.id,e.title),w.id,e.text));return}let t=[...b,{id:e.id,title:e.title,text:e.text}];x(t),C(e.id)},mt=e=>{W===e&&ut();let t=hf(b,e,v);x(t),S===e&&C(t[t.length-1]?.id??t[0]?.id??`q_1`)},ht=q?je.isPending||Ee:ee,gt=yr(`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(),ft())},children:[(0,Q.jsx)(nn,{dataSlot:`store-query-header`,className:`relative z-30`,leading:d,icon:(0,Q.jsx)(H,{icon:p.icon,className:`size-4`}),wellClassName:p.wellClass,title:q?`SQL Query`:`KV Query`,badge:(0,Q.jsx)(`span`,{className:`font-mono text-[10px] font-medium tracking-[0.08em] text-muted-foreground`,children:_?.ref??`No store`}),subtitle:(0,Q.jsxs)(`span`,{className:`truncate font-mono text-[11px] leading-none text-muted-foreground`,children:[q?`DML / DDL`:`list / get / set / delete / ttl`,Be?` · selection${Ve.length>1?` (${Ve.length})`:``}`:q?Re.length>1?` · ${Re.length} statements`:` · current statement`:``]}),actions:(0,Q.jsxs)(Q.Fragment,{children:[m.length>1?(0,Q.jsxs)(`div`,{className:`flex h-full items-stretch`,"data-slot":`store-query-store`,children:[(0,Q.jsx)(`span`,{className:J(B,`flex items-center px-2`),children:`Store`}),(0,Q.jsxs)(Oa,{value:_?.ref??``,onValueChange:at,className:`z-40 inline-flex h-full min-w-[8rem]`,children:[(0,Q.jsx)(ka,{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)(Aa,{})}),(0,Q.jsx)(ja,{children:m.map(e=>(0,Q.jsx)(Ma,{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)(Oa,{value:s??``,onValueChange:e=>l(e.length>0?e:null),className:`z-40 inline-flex h-full min-w-[8rem]`,children:[(0,Q.jsx)(ka,{flat:!0,"aria-label":`Tenant`,className:`h-full w-auto px-2 font-mono text-[11px] hover:bg-muted/50`,children:(0,Q.jsx)(Aa,{placeholder:`Select tenant…`})}),(0,Q.jsx)(ja,{children:i.map(e=>(0,Q.jsx)(Ma,{value:e,className:`font-mono text-[11px]`,children:e},e))})]})}):null]})}),(0,Q.jsxs)(`div`,{className:`${Se} overflow-x-auto`,role:`tablist`,"aria-label":`Query tabs`,children:[b.map(e=>(0,Q.jsxs)(`div`,{className:J(`group/tab flex h-full items-center gap-0.5 border-b-2 px-1`,e.id===S?`border-foreground text-foreground`:`border-transparent text-muted-foreground`),children:[W===e.id?(0,Q.jsx)(`input`,{autoFocus:!0,value:ge,maxLength:48,"aria-label":`Rename query`,"data-slot":`store-query-tab-rename`,onFocus:e=>e.currentTarget.select(),onChange:e=>_e(e.target.value),onBlur:()=>lt(e.id,ge),onKeyDown:t=>{t.key===`Enter`&&(t.preventDefault(),lt(e.id,ge)),t.key===`Escape`&&(t.preventDefault(),ut())},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,ge.length+1)}ch`}}):(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":e.id===S,title:`Double-click to rename`,"data-slot":`store-query-tab`,onClick:()=>C(e.id),onDoubleClick:t=>{t.preventDefault(),dt(e)},className:`max-w-[12rem] truncate px-1.5 font-mono text-[11px]`,children:e.title}),de.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:()=>mt(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)(H,{icon:c,className:`size-2.5`})})]},e.id)),(0,Q.jsx)(xr,{label:`New query`,className:`flex self-stretch`,children:(0,Q.jsx)(`button`,{type:`button`,"aria-label":`New query`,disabled:b.length>=8,onClick:st,"data-slot":`store-query-tab-add`,className:Fe,children:(0,Q.jsx)(H,{icon:rt,className:`size-3.5`})})})]}),(0,Q.jsxs)(`div`,{className:Se,children:[(0,Q.jsxs)(z,{type:`button`,variant:`ghost`,size:`sm`,className:`h-full rounded-none px-2 text-[11px]`,onClick:()=>We(q?qr(T):Bf(T)),"data-slot":`store-query-prettify`,children:[(0,Q.jsx)(H,{icon:se,"data-icon":`inline-start`,className:`size-3.5`}),`Prettify`]}),(0,Q.jsx)(xr,{label:pe?`Saved`:`Save`,keys:Ie,className:`flex self-stretch`,children:(0,Q.jsxs)(z,{type:`button`,variant:`ghost`,size:`sm`,className:`h-full rounded-none px-2 text-[11px]`,onClick:ft,"data-slot":`store-query-save`,children:[(0,Q.jsx)(H,{icon:pe?Ke:ye,"data-icon":`inline-start`,className:`size-3.5`}),pe?`Saved`:`Save`]})}),(0,Q.jsx)(sp,{entries:le,saved:de,onPick:e=>{We(e.text),Oe.current?.focus()},onPickSaved:e=>{pt(e),Oe.current?.focus()}}),(0,Q.jsxs)(z,{type:`button`,variant:`ghost`,size:`sm`,className:J(`h-full rounded-none px-2 text-[11px]`,te&&`text-foreground`),"aria-pressed":te,onClick:()=>V(e=>!e),"data-slot":`store-query-schema`,children:[(0,Q.jsx)(H,{icon:I,"data-icon":`inline-start`,className:`size-3.5`}),q?`Schema`:`Keys`]}),q?(0,Q.jsx)(xr,{label:ne?`PII hidden. Click to include cleartext (audited).`:`PII included. Click to remask.`,className:`flex self-stretch`,children:(0,Q.jsxs)(z,{type:`button`,variant:`ghost`,size:`sm`,className:J(`h-full rounded-none px-2 text-[11px]`,!ne&&`text-amber-800 dark:text-amber-300`),"aria-pressed":!ne,"aria-label":ne?`Include PII: disabled`:`Include PII: enabled`,onClick:()=>{let e=!ne;re(e),A&&!ii(A)&&Qe(A,!e)},"data-slot":`store-query-pii`,children:[(0,Q.jsx)(H,{icon:ne?Ye:ke,"data-icon":`inline-start`,className:`size-3.5`}),`PII`]})}):null,q?(0,Q.jsx)(ju,{manifest:u,value:U,onChange:e=>{ae(e),A&&!ii(A)&&Qe(A,!ne,e)}}):null,He?(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)(H,{icon:a,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)(xr,{label:Be?`Run selection`:`Run`,keys:Pe,className:`flex self-stretch`,children:(0,Q.jsxs)(z,{type:`button`,size:`sm`,className:`h-full gap-1.5 rounded-none`,disabled:!_||ht,onClick:$e,"data-slot":`store-query-run`,children:[ht?(0,Q.jsx)(H,{icon:f,className:`size-3.5 animate-spin`}):(0,Q.jsx)(H,{icon:R,className:`size-3.5`}),Be?`Run selection`:`Run`]})}),q?(0,Q.jsxs)(sn,{children:[(0,Q.jsx)(Wt,{render:e=>(0,Q.jsx)(z,{...e,type:`button`,size:`sm`,className:`h-full rounded-none border-l border-primary-foreground/20 px-1.5`,disabled:!_||ht,"aria-label":`More run options`,"data-slot":`store-query-run-menu`,children:(0,Q.jsx)(H,{icon:M,className:`size-3.5`})})}),(0,Q.jsxs)(en,{align:`end`,className:`w-56`,children:[(0,Q.jsxs)($t,{children:[(0,Q.jsxs)(qt,{onClick:$e,children:[`Run current`,(0,Q.jsx)(Kt,{children:(0,Q.jsx)(Ge,{keys:Pe})})]}),(0,Q.jsxs)(qt,{onClick:et,disabled:Re.length<2,children:[`Run all`,(0,Q.jsx)(Kt,{children:(0,Q.jsx)(Ge,{keys:gt})})]})]}),(0,Q.jsx)(dn,{}),(0,Q.jsxs)($t,{children:[(0,Q.jsx)(qt,{onClick:()=>tt(!1),children:`EXPLAIN`}),(0,Q.jsx)(qt,{onClick:()=>tt(!0),children:`EXPLAIN ANALYZE`})]})]})]}):null]})]}),(0,Q.jsxs)(Dr,{orientation:`vertical`,className:`min-h-0 flex-1`,children:[(0,Q.jsx)(Ar,{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)(ti,{value:T,onChange:We,language:q?`sql`:`kv`,onRun:$e,onRunAll:q?et:void 0,onRunLine:q?it:void 0,runLines:ze,onCursorChange:(e,t)=>be({start:e,end:t}),editorRef:Oe,label:q?`SQL query`:`KV command`,tables:Le,facet:e}),te?(0,Q.jsx)(Qf,{store:_,facet:e,manifest:u,tenant:s,tenancyDeclared:r,onPickTable:ot,onPickColumn:(e,t)=>{Oe.current?.insert(q?`"${t}"`:t)},onCollapse:()=>V(!1)}):(0,Q.jsx)(tp,{facet:e,onExpand:()=>V(!0)})]})}),oe?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Nr,{withHandle:!0,className:`justify-end pr-8`}),(0,Q.jsx)(Ar,{defaultSize:`28%`,minSize:`20%`,className:`min-h-0 overflow-hidden`,children:(0,Q.jsx)(Si,{rows:E,error:N,pending:ht,meta:O,executed:A,executedLanguage:q?`sql`:`kv`,storeRef:_?.ref,sets:xe,activeSet:we,onSelectSet:e=>Xe(xe,e),onToggleCollapse:()=>ce(!1)})})]}):null]}),oe?null:(0,Q.jsx)(Si,{rows:E,error:N,pending:ht,meta:O,executed:A,executedLanguage:q?`sql`:`kv`,storeRef:_?.ref,sets:xe,activeSet:we,onSelectSet:e=>Xe(xe,e),collapsed:!0,onToggleCollapse:()=>ce(!0)})]})}function rp(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 ip(e){if(e.length!==1)return null;let t=e[0]?.changes;return typeof t==`number`&&Number.isFinite(t)?t:null}function ap(e,t,n){let r=!1,i=e.map(e=>{let i=fd(e.text,t,n);return i===e.text?e:(r=!0,{...e,text:i})});return r?i:e}function op(e,t,n){if(!e)return t===`sql`?sd():pd();let r=(n?e.children.find(e=>e.effectRef===n)?.name:void 0)??gd(e);return t===`sql`?sd(r):pd(r?`${r}:`:void 0)}function sp({entries:e,saved:t,onPick:n,onPickSaved:r}){return(0,Q.jsxs)(sn,{children:[(0,Q.jsx)(Wt,{render:e=>(0,Q.jsxs)(z,{...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)(H,{icon:ae,"data-icon":`inline-start`,className:`size-3.5`}),`History`]})}),(0,Q.jsxs)(en,{align:`start`,className:`w-80`,children:[(0,Q.jsxs)($t,{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)(qt,{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:bf(e.text)})]},e.id))]}),(0,Q.jsx)(dn,{}),(0,Q.jsxs)($t,{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)(qt,{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:bf(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 cp=`#38BDF8`,lp=[`#38BDF8`,`#34D399`,`#FBBF24`,`#A78BFA`,`#FB7185`,`#22D3EE`,`#F472B6`,`#4ADE80`,`#F59E0B`,`#818CF8`];function up(e){let t=new Set(e.map(e=>e.name)),n=new Map;for(let r of e)n.set(r.name,hp(r,t));return n}function dp(e){let t=up(e),n=[...new Set(t.values())].sort(),r=new Map;for(let[e,t]of n.entries())r.set(t,lp[e]??bp(t));let i=new Map;for(let n of e){let e=t.get(n.name)??yp(n.name);i.set(n.id,{cluster:e,hex:r.get(e)??`#38BDF8`})}return i}function fp(e,t){let n=t?dp(e.tables):new Map(e.tables.map(e=>[e.id,{cluster:`schema`,hex:cp}])),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=>pp(e,n.get(e.id),r)),edges:e.edges.map(e=>mp(e,n.get(e.target)))}}function pp(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 mp(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 hp(e,t){let n=gp(e.name,t);if(n)return n;if(_p(e.name,t))return yp(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 gp(e,t)??yp(e)}return yp(e.name)}function gp(e,t){let n=e.split(`_`)[0];if(!n||n===e)return null;for(let r of[n,`${n}s`,vp(n)])if(t.has(r)&&r!==e)return yp(r);return null}function _p(e,t){let n=yp(e);for(let r of t)if(r!==e&&gp(r,t)===n)return!0;return!1}function vp(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 yp(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 bp(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 xp={"many-to-one":`Many-to-one`,"one-to-one":`One-to-one`,"many-to-many":`Many-to-many`,self:`Self`};function Sp({kind:e,className:t,hex:n}){return(0,Q.jsx)(`svg`,{viewBox:`0 0 24 24`,className:J(`size-3.5 shrink-0`,!n&&`text-muted-foreground`,t),style:n?{color:n}:void 0,"aria-label":xp[e],fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,Q.jsx)(Cp,{kind:e})})}function Cp({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 wp({id:e,sourceX:t,sourceY:n,targetX:r,targetY:i,sourcePosition:a,targetPosition:o,style:s,markerEnd:c,data:l}){let[u,d,f]=gt({sourceX:t,sourceY:n,sourcePosition:a,targetX:r,targetY:i,targetPosition:o}),p=l?.relation??`many-to-one`,m=l?.column??``,g=`${l?.inferred===!0?`Inferred`:`Declared`} ${In(p,m)}`;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_t,{id:e,path:u,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(${d}px,${f}px)`,opacity:typeof s?.opacity==`number`?s.opacity:1},children:(0,Q.jsxs)(h,{children:[(0,Q.jsx)(L,{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)(Sp,{kind:p,hex:l?.hex})})}),(0,Q.jsx)(C,{side:`top`,className:`text-[11px]`,children:g})]})})})]})}var Tp={relation:wp};function Ep({data:e}){let{table:t,showStore:n,dimmed:r,selected:i,color:a,refHex:o}=e,s=a?.hex??`#38BDF8`;return(0,Q.jsxs)(`div`,{"data-slot":`store-schema-table`,"data-table":t.name,"data-cluster":a?.cluster,className:J(`flex h-full w-full flex-col overflow-hidden rounded-lg border bg-card text-[11px] shadow-sm`,r&&`opacity-30 saturate-[0.4]`),style:{borderColor:i?s:`color-mix(in oklab, ${s} 42%, var(--border))`,boxShadow:i?`0 0 0 2px color-mix(in oklab, ${s} 35%, transparent)`:void 0},children:[(0,Q.jsxs)(`div`,{className:`flex h-8 shrink-0 items-center gap-1.5 border-b px-2`,style:{background:`color-mix(in oklab, ${s} 22%, var(--card))`,borderColor:`color-mix(in oklab, ${s} 28%, var(--border))`},children:[(0,Q.jsx)(`span`,{className:`size-2 shrink-0 rounded-full`,style:{background:s},"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate font-semibold text-foreground`,children:t.name}),(0,Q.jsx)(`span`,{"data-slot":`store-schema-rls`,"data-rls":t.rls===!0?`on`:`off`,title:t.rls===!0?`RLS enabled`:`RLS disabled`,className:J(`shrink-0`,t.rls===!0?`text-emerald-500`:`text-muted-foreground/35`),children:(0,Q.jsx)(H,{icon:t.rls===!0?D:Re,className:`size-3`,"aria-hidden":!0})}),n?(0,Q.jsx)(`span`,{className:`ml-auto shrink-0 font-mono text-[9px] tracking-[0.08em] text-muted-foreground uppercase`,children:t.storeName}):(0,Q.jsx)(`span`,{className:`ml-auto shrink-0 tabular-nums text-[10px] text-muted-foreground`,children:t.columns.length})]}),(0,Q.jsx)(`ul`,{className:`flex min-h-0 flex-1 flex-col`,children:t.columns.length===0?(0,Q.jsx)(`li`,{className:`relative flex h-[22px] items-center px-2 text-muted-foreground`,children:`No columns`}):t.columns.map(e=>(0,Q.jsx)(Dp,{column:e,tableName:t.name,junction:Op(t.columns),tableHex:s,refHex:o?.[e.name]},e.name))})]})}function Dp({column:e,tableName:t,junction:n,tableHex:r,refHex:i}){let a=i??r,o=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:J(`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)(Li,{primaryKey:e.primaryKey,foreignKey:e.references!==void 0,unique:e.unique,inferred:e.inferredRef,hex:a}),(0,Q.jsx)(`span`,{className:J(`min-w-0 truncate font-mono text-[10px]`,!i&&`text-foreground`),style:i?{color:i}:void 0,title:Ap(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:Ap(e,t,n),children:[(0,Q.jsx)(Sp,{kind:kp(e,t,n),hex:a,className:`size-3`}),(0,Q.jsx)(`span`,{className:`truncate font-mono text-[8px]`,children:e.references.table})]}):null,(0,Q.jsx)(`span`,{className:J(`ml-auto shrink-0 font-mono text-[9px]`,o),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:a}})]})}function Op(e){return e.filter(e=>e.references?.table).length<2?!1:e.every(e=>e.primaryKey===!0||e.references!==void 0)}function kp(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 Ap(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`:In(kp(e,t,n),e.name);return`${e.inferredRef?`Inferred`:`Declared`} ${i} → ${r}`}var jp={table:Ep};function Mp(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)(Np,{...e})})})}function Np({stores:e,manifest:t,selectedEffectRef:n,onSelectTable:r,leading:i}){let{fitView:a}=ft(),{theme:o}=Ut(),s=It(),[c,l]=(0,Z.useState)(``),[u,d]=(0,Z.useState)(0),[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(!0),[g,_]=(0,Z.useState)(!0),v=o===`system`?window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`:o,b=(0,Z.useMemo)(()=>xn(e,t),[e,t]),x=(0,Z.useMemo)(()=>fp(vr(b),m),[b,m]),[S,C,w]=Ct([...x.nodes]),[T,E,D]=ht([...x.edges]);(0,Z.useEffect)(()=>{C(Fn(x.nodes,c,n,x.edges,g)),E(hn(x.edges,n,g,s!==!0))},[x,g,u,c,s,n,E,C]),(0,Z.useEffect)(()=>{let e=window.setTimeout(()=>{a({padding:.18,duration:240})},40);return()=>window.clearTimeout(e)},[a,u,b.length]);let k=(0,Z.useCallback)(async()=>{let e=Pn(b);if(e.length!==0)try{await navigator.clipboard.writeText(e),p(!0),window.setTimeout(()=>p(!1),1400)}catch{p(!1)}},[b]);return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,Q.jsxs)(`div`,{className:et,"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:J(B,`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)(Lr,{value:c,onChange:e=>l(e.target.value),placeholder:`Find table…`,"aria-label":`Find table`,"data-slot":`store-schema-find`}),(0,Q.jsxs)(`span`,{className:J(Be,`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)(Qt,{active:m,"aria-pressed":m,onClick:()=>h(e=>!e),className:`h-full`,"data-slot":`store-schema-colorize`,children:[(0,Q.jsx)(H,{icon:y,className:`size-3`,"aria-hidden":!0}),`Colorize`]}),(0,Q.jsxs)(Qt,{active:f,disabled:b.length===0,onClick:()=>void k(),className:`h-full disabled:pointer-events-none disabled:opacity-40`,"data-slot":`store-schema-copy-sql`,children:[(0,Q.jsx)(H,{icon:f?Ke:O,className:`size-3`,"aria-hidden":!0}),f?`Copied`:`Copy as SQL`]}),(0,Q.jsx)(Qt,{active:!1,disabled:b.length===0,onClick:()=>d(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:jp,edgeTypes:Tp,onNodesChange:w,onEdgesChange:D,colorMode:v,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)=>{_(!0),r(t.id)},onPaneClick:()=>_(!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)(Ri,{kind:`pk`}),`primary`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(Ri,{kind:`fk`}),`foreign`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(Ri,{kind:`unique`}),`unique`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(Sp,{kind:`many-to-one`}),`many`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(Sp,{kind:`one-to-one`}),`one`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(Sp,{kind:`many-to-many`}),`join`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,Q.jsx)(Sp,{kind:`self`}),`self`]}),(0,Q.jsx)(`span`,{children:`dashed = inferred`}),(0,Q.jsx)(`span`,{children:`filled = not null`})]})})]})]})}function Pp(){let e=Qr(),t=zr(),n=Ur();Rr(!0);let{selectedResource:r,selectedTenant:i,queryFacet:a,schemaView:o,performanceView:s,performanceFacet:c,setSelectedResource:l,setSelectedTenant:u,setQueryFacet:d,setSchemaView:f,setPerformanceView:p}=wt(),m=Tr(),h=(0,Q.jsx)(Er,{open:m.open,onToggle:m.toggle,noun:`store`,controlsId:`store-tree`,dataSlot:`store-tree-toggle`}),g=e.data?.stores??[],_=r??ga(g),v=(0,Z.useMemo)(()=>_?ca(g,_):null,[g,_]);return(0,Q.jsx)(`div`,{className:G,"data-slot":`store-page`,children:(0,Q.jsxs)(Dr,{orientation:`horizontal`,className:`min-h-0 flex-1`,children:[(0,Q.jsx)(Ar,{panelRef:m.panelRef,collapsible:!0,collapsedSize:0,defaultSize:we.start.defaultSize,minSize:we.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)(Ku,{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)(Nr,{withHandle:!0}):null,(0,Q.jsx)(Ar,{defaultSize:we.end.defaultSize,minSize:we.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)(Mp,{stores:g,manifest:t.data??null,selectedEffectRef:_,onSelectTable:e=>l(e,{keepView:!0}),leading:h}):s?(0,Q.jsx)(Rd,{stores:g,selectedEffectRef:_,tenant:i,facet:c??`sql`,leading:h}):a?(0,Q.jsx)(np,{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)(Vu,{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)(Pi,{leading:h,icon:wr.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{Pp as StorePage};
|