@lunora/studio 1.0.0-alpha.237 → 1.0.0-alpha.239
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/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/packem_chunks/SqlEditorPanel.mjs +9 -7
- package/dist/packem_chunks/TableEditor.mjs +1 -1
- package/dist/packem_chunks/dashboards-panel.mjs +1 -1
- package/dist/packem_shared/{DataBrowser-YscAF4OI.mjs → DataBrowser-B-jVLGCS.mjs} +1 -1
- package/dist/packem_shared/use-sql-assistant-CZydTzd5.mjs +1 -0
- package/dist/standalone/{chunk-D2A2AR4A.js → chunk-5EKU6J7E.js} +1 -1
- package/dist/standalone/{chunk-PHDRSIJK.js → chunk-CZMVDPDO.js} +1 -1
- package/dist/standalone/{chunk-UNIL6B6P.js → chunk-DXVAAESF.js} +1 -1
- package/dist/standalone/chunk-N5WACH4X.js +15 -0
- package/dist/standalone/chunk-OOTQQBVC.js +1 -0
- package/dist/standalone/{chunk-GS7U4RYT.js → chunk-TIYNL2DI.js} +1 -1
- package/dist/standalone/{chunk-AS7X7XLQ.js → chunk-ZGHK6YA6.js} +1 -1
- package/dist/standalone/studio.js +1 -1
- package/dist/styles.css +1 -1
- package/package.json +6 -5
- package/dist/packem_shared/use-sql-assistant-pjfGp-Ol.mjs +0 -1
- package/dist/standalone/chunk-2EX3RVZC.js +0 -8
- package/dist/standalone/chunk-AVVMOLTL.js +0 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import{c as
|
|
2
|
-
`;)n+=1;return n},
|
|
1
|
+
import{c as X}from"react/compiler-runtime";import{useLunora as Ue}from"@lunora/react";import{useState as se,useMemo as Xe,useCallback as yt,useEffect as Ce,useRef as me,useId as vt}from"react";import{ADMIN_FUNCTIONS as Me}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{u as Qe,n as ot,b as je,r as Le,s as St}from"../packem_shared/browser-storage-BH1MxLZs.mjs";import{d as De,f as fe,c as $e,b as wt}from"../packem_shared/internal-Df43vQI0.mjs";import{r as Ct}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{u as Et}from"../packem_shared/use-sql-assistant-CZydTzd5.mjs";import Nt from"../packem_shared/useDebounced-DVeQ5-oW.mjs";import{useT as ce}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{c as ue}from"../packem_shared/utils-bhneXptQ.mjs";import{jsxs as H,jsx as h,Fragment as Ne}from"react/jsx-runtime";import{I as lt}from"../packem_shared/input-CXhxesPC.mjs";import{diffLines as kt}from"diff";import{S as Tt,a as Rt}from"../packem_shared/sql-result-table-DyK762_A.mjs";import{ShardInput as It}from"../packem_shared/ShardInput-C6mjgAh4.mjs";import{A as Lt}from"../packem_shared/alert-PB5W11MM.mjs";import{E as _t}from"../packem_shared/grid-features-OVIMIQan.mjs";const At="x",Ze=" ",qt={'"':'"',"'":"'","[":"]","`":"`"},rt=(l,e)=>{let n=e+2;for(;n<l.length&&l[n]!==`
|
|
2
|
+
`;)n+=1;return n},it=(l,e)=>{const n=l.indexOf("*/",e+2);return n===-1?-1:n+2},at=l=>{const e=l.split("");let n=0;for(;n<l.length;){const t=l[n]??"",o=qt[t];if(t==="-"&&l[n+1]==="-"){const s=rt(l,n);e.fill(Ze,n,s),n=s}else if(t==="/"&&l[n+1]==="*"){const s=it(l,n);if(s===-1)return;e.fill(Ze,n,s),n=s}else if(o!==void 0){let s=n+1;for(;s<l.length;)if(l[s]!==o)s+=1;else if(o!=="]"&&l[s+1]===o)s+=2;else break;if(s>=l.length)return;e.fill(At,n,s+1),n=s+1}else n+=1}for(let t=0;t<l.length;t+=1)l[t]===`
|
|
3
3
|
`&&(e[t]=`
|
|
4
|
-
`);return e.join("")},
|
|
5
|
-
${l}`})),
|
|
6
|
-
`,e);return t===-1?l.length:t}if(n==="/"&&l[e+1]==="*"){const t=l.indexOf("*/",e+2);return t===-1?l.length:t+2}return-1},Kt=l=>{let e="",n=0;for(;n<l.length;){const t=Yt(l,n);t===-1?(e+=l.slice(n,n+1),n+=1):(e+=l.slice(n,t).replaceAll(jt," "),n=t)}return e},Gt=l=>{const e=new Set;for(const n of l.matchAll(zt))e.add((n[1]??"").toLowerCase());return e},Jt=(l,e)=>{const n=new Map;for(const t of l.matchAll(Qt)){const o=(t[1]??"").toLowerCase(),s=(t[2]??"").toLowerCase();e.has(o)&&(n.set(o,o),s!==""&&!Ut.has(s)&&n.set(s,o))}return n},rt=(l,e)=>{const n=Kt(l),t=new Set(e.map(o=>o.toLowerCase()));return{ctes:Gt(n),masked:n,targets:Jt(n,t)}},Vt=/^(?:__lunora|sqlite_)/iu,Xt=/\b(?:from|join)\s+([a-z_][\w$]*)/giu,Zt=/\b([a-z_][\w$]*)\.([a-z_][\w$]*)/giu,en=new Set(["cross","full","group","having","inner","join","lateral","left","limit","offset","order","right","select","union","where","window"]),tn=(l,e,n)=>{const t=[];for(const o of l.matchAll(Xt)){const s=o[1]??"",r=s.toLowerCase();!e.has(r)&&!n.has(r)&&!en.has(r)&&!Vt.test(s)&&t.push({length:s.length,message:`unknown table \`${s}\``,offset:o.index+o[0].length-s.length,severity:"error",source:"schema"})}return t},nn=(l,e,n)=>{const t=[],o=new Map;for(const[s,r]of Object.entries(e.columns))o.set(s.toLowerCase(),new Set(r.map(c=>c.toLowerCase())));for(const s of l.matchAll(Zt)){const r=(s[1]??"").toLowerCase(),c=s[2]??"",a=n.get(r),i=a===void 0?void 0:o.get(a);i!==void 0&&!i.has(c.toLowerCase())&&t.push({length:c.length,message:`\`${a??""}\` has no column \`${c}\``,offset:s.index+s[0].length-c.length,severity:"error",source:"schema"})}return t},sn=/(?<![\w$."])(?:"([a-z_][\w$]*)"|([a-z_][\w$]*))(?![.(])/giu,on=/\bas\s+"?([a-z_][\w$]*)"?/giu,ln=(l,e,n,t)=>{const o=[...new Set(n.values())],s=new Map,r=new Set;for(const i of o){for(const f of e.columns[i]??[])r.add(f.toLowerCase());for(const f of e.docFields?.[i]??[])s.set(f.toLowerCase(),f)}if(s.size===0)return[];const c=new Set([...l.matchAll(on)].map(i=>(i[1]??"").toLowerCase())),a=[];for(const i of l.matchAll(sn)){const f=i[1],p=f??i[2]??"",m=p.toLowerCase(),x=s.get(m);x===void 0||r.has(m)||c.has(m)||t.has(m)||n.has(m)||a.push({length:p.length,message:`\`${x}\` is a \`__doc__\` field, not a column — use \`json_extract(__doc__, '$.${x}')\``,offset:i.index+(f===void 0?0:1),severity:"error",source:"schema"})}return a},rn=(l,e)=>{if(l.trim()==="")return[];const n=lt(l),t=new Set(e.tables.map(s=>s.toLowerCase())),o=[];for(const s of n){const{offset:r,rejection:c}=s;if(c!==void 0){o.push({length:c.length,message:c.message,offset:c.offset===void 0?r:r+c.offset,severity:"error",source:"gate"});continue}const{ctes:a,masked:i,targets:f}=rt(s.sql,e.tables);o.push(...[...tn(i,t,a),...nn(i,e,f),...ln(i,e,f,a)].map(p=>({...p,offset:p.offset===void 0?r:r+p.offset})))}return o},an=Oe(qe.lintSql),cn=600,dn=(l,e,n)=>{const t=Qe(),[o,s]=ie([]),r=Ke(()=>rn(l,e),[l,e]),c=yt(l,cn),i=r.some(m=>m.source==="gate")||c.trim()==="",f=ht(async m=>{try{const x=await t.query(an,{sql:c},_e(n));m.cancelled||s(x.diagnostics??[])}catch{m.cancelled||s([])}},[t,c,n]);Ne(()=>{if(i){s([]);return}const m={cancelled:!1};return ue(f(m)),()=>{m.cancelled=!0}},[f,i]);const p=c===l;return Ke(()=>p?[...r,...o]:r,[r,o,p])},Le=8,un=["AND","ASC","AS","BY","COUNT","DESC","DISTINCT","EXPLAIN","FROM","GROUP","HAVING","INNER","JOIN","LEFT","LIKE","LIMIT","NOT","NULL","OFFSET","ON","ORDER","OR","QUERY","SELECT","WHERE","WITH"],fn=new Set(["AND","BY","HAVING","ON","OR","SELECT","WHERE"]),mn=/[\w$]/,it=l=>l!==void 0&&mn.test(l),at=l=>{let e=l.length;for(;e>0&&it(l[e-1]);)e-=1;return l.slice(e)},ct=(l,e)=>{let n=e;for(;n>0&&it(l[n-1]);)n-=1;return{end:e,start:n,text:l.slice(n,e)}},Je=(l,e)=>{const n=l.slice(0,e).trimEnd();return n.endsWith(".")||fn.has(at(n).toUpperCase())},hn=(l,e,n)=>{const t=l.slice(0,e);if(!t.endsWith("."))return;const o=at(t.slice(0,-1));if(o!=="")return rt(l,n).targets.get(o.toLowerCase())??o},Ue=(l,e)=>l.toLowerCase().startsWith(e.toLowerCase()),Ve=(l,e,n,t)=>{const o=[];for(const s of l)if(Ue(s,e)&&(o.push(t(s)),o.length>=n))break;return o},pn=(l,e,n)=>{const t=new Map;for(const[o,s]of Object.entries(l.columns))for(const r of s)if(Ue(r,e)&&!t.has(r)&&(t.set(r,o),t.size>=n))return[...t].map(([c,a])=>({detail:a,kind:"column",label:c}));return[...t].map(([o,s])=>({detail:s,kind:"column",label:o}))},bn=(l,e,n)=>{const t=ct(l,e),o=hn(l,t.start,n.tables);if(o!==void 0){const i=n.columns[o]??n.columns[o.toLowerCase()]??[];return Ve(i,t.text,Le,f=>({detail:o,kind:"column",label:f}))}if(t.text===""&&!Je(l,t.start))return[];const s=Ve(n.tables,t.text,Le,i=>({kind:"table",label:i})),r=pn(n,t.text,Le),c=un.flatMap(i=>t.text!==""&&Ue(i,t.text)&&i.toLowerCase()!==t.text.toLowerCase()?[{kind:"keyword",label:i}]:[]);return(Je(l,t.start)?[...r,...s,...c]:[...s,...r,...c]).slice(0,Le)},gn=(l,e,n)=>{const t=ct(l,e),o=l.slice(0,t.start)+n.label+l.slice(t.end);return{caret:t.start+n.label.length,value:o}},xn=["boxSizing","borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textTransform","width","wordSpacing"],vn=(l,e)=>{const n=globalThis.getComputedStyle(l),t=globalThis.document.createElement("div"),{style:o}=t;o.position="absolute",o.visibility="hidden",o.whiteSpace="pre-wrap",o.overflowWrap="break-word";for(const a of xn)o[a]=n[a];t.textContent=l.value.slice(0,Math.max(0,e));const s=globalThis.document.createElement("span");s.textContent=l.value.slice(Math.max(0,e))||".",t.append(s),globalThis.document.body.append(t);const r=s.offsetLeft-l.scrollLeft,c=s.offsetTop-l.scrollTop;return t.remove(),{left:r,top:c}},yn=(l,e,n)=>{const t=Y(16),[o,s]=ie(null);let r;t[0]!==l||t[1]!==e?(r=(v,g)=>{const N=bn(v,g,l);if(N.length===0){s(null);return}const y=e.current,{left:h,top:E}=y===null?{left:0,top:0}:vn(y,g);s(w=>w!==null&&w.active===0&&w.left===h&&w.top===E&&w.suggestions.length===N.length&&w.suggestions.every((T,_)=>{const C=N.at(_);return T.kind===C?.kind&&T.label===C.label&&T.detail===C.detail})?w:{active:0,left:h,suggestions:N,top:E})},t[0]=l,t[1]=e,t[2]=r):r=t[2];const c=r;let a;t[3]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{s(null)},t[3]=a):a=t[3];const i=a;let f;t[4]===Symbol.for("react.memo_cache_sentinel")?(f=v=>{s(g=>{if(g===null)return g;const N=g.suggestions.length,y=(g.active+v+N)%N;return{...g,active:y}})},t[4]=f):f=t[4];const p=f;let m;t[5]!==n||t[6]!==o||t[7]!==e?(m=v=>{const g=e.current;if(o===null||g===null)return!1;const N=o.suggestions[v??o.active];if(N===void 0)return!1;const y=gn(g.value,g.selectionStart,N);return n(y.value),s(null),requestAnimationFrame(()=>{const h=e.current;h!==null&&(h.focus(),h.setSelectionRange(y.caret,y.caret))}),!0},t[5]=n,t[6]=o,t[7]=e,t[8]=m):m=t[8];const x=m;let d;t[9]!==x?(d=()=>x(),t[9]=x,t[10]=d):d=t[10];const S=d;let u;return t[11]!==S||t[12]!==x||t[13]!==c||t[14]!==o?(u={close:i,commit:S,commitAt:x,move:p,refresh:c,state:o},t[11]=S,t[12]=x,t[13]=c,t[14]=o,t[15]=u):u=t[15],u},Sn={column:"column",keyword:"keyword",table:"table"},wn=20,Cn=l=>{const e=Y(17),{listboxId:n,onPick:t,state:o}=l,s=de();let r;e[0]!==o?(r=o===null?void 0:{left:o.left,top:o.top+wn},e[0]=o,e[1]=r):r=e[1];const c=r;if(o===null)return null;let a;if(e[2]!==n||e[3]!==t||e[4]!==o.active||e[5]!==o.suggestions||e[6]!==s){let f;e[8]!==n||e[9]!==t||e[10]!==o.active||e[11]!==s?(f=(p,m)=>W("li",{"aria-selected":m===o.active,className:fe("flex cursor-pointer items-center gap-2 px-2 py-1 text-[13px]",m===o.active?"bg-accent text-accent-foreground":"text-foreground"),"data-testid":"sql-autocomplete-item",id:`${n}-opt-${m.toString()}`,onMouseDown:x=>{x.preventDefault(),t(m)},role:"option",children:[b("span",{className:"truncate font-mono",children:p.label}),p.detail!==void 0&&b("span",{className:"ms-auto truncate text-xs text-muted-foreground",children:p.detail}),b("span",{className:"shrink-0 font-mono text-[10px] tracking-wide text-muted-foreground/70 uppercase",children:s(Sn[p.kind])})]},`${p.kind}:${p.label}`),e[8]=n,e[9]=t,e[10]=o.active,e[11]=s,e[12]=f):f=e[12],a=o.suggestions.map(f),e[2]=n,e[3]=t,e[4]=o.active,e[5]=o.suggestions,e[6]=s,e[7]=a}else a=e[7];let i;return e[13]!==n||e[14]!==c||e[15]!==a?(i=b("ul",{className:"absolute z-30 max-h-56 w-72 overflow-auto rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-autocomplete",id:n,role:"listbox",style:c,children:a}),e[13]=n,e[14]=c,e[15]=a,e[16]=i):i=e[16],i},Nn=Oe(qe.listTables),kn=Oe(qe.readTablePage),En=l=>{const e=Y(18),n=Qe();let t;e[0]===Symbol.for("react.memo_cache_sentinel")?(t=[],e[0]=t):t=e[0];const[o,s]=ie(t);let r;e[1]===Symbol.for("react.memo_cache_sentinel")?(r={},e[1]=r):r=e[1];const[c,a]=ie(r);let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i={},e[2]=i):i=e[2];const[f,p]=ie(i);let m;e[3]===Symbol.for("react.memo_cache_sentinel")?(m=new Set,e[3]=m):m=e[3];const x=Ce(m);let d,S;e[4]!==n||e[5]!==l?(d=()=>{const h={cancelled:!1};return ue((async()=>{try{const w=await n.query(Nn,{},_e(l));h.cancelled||(s(w.map(Rn)),a({}),p({}),x.current=new Set)}catch{h.cancelled||(s([]),a({}),p({}),x.current=new Set)}})()),()=>{h.cancelled=!0}},S=[n,l],e[4]=n,e[5]=l,e[6]=d,e[7]=S):(d=e[6],S=e[7]),Ne(d,S);let u;e[8]!==n||e[9]!==l?(u=h=>{if(x.current.has(h))return;x.current.add(h),ue((async()=>{try{const w=await n.query(kn,{limit:1,offset:0,table:h},_e(l)),{sqlColumns:R}=w;if(R===void 0){x.current.delete(h);return}const T=new Set(R),_=w.columns.filter(C=>!T.has(C));a(C=>({...C,[h]:R})),p(C=>({...C,[h]:_}))}catch{x.current.delete(h)}})())},e[8]=n,e[9]=l,e[10]=u):u=e[10];const v=u;let g;e[11]!==c||e[12]!==f||e[13]!==o?(g={columns:c,docFields:f,tables:o},e[11]=c,e[12]=f,e[13]=o,e[14]=g):g=e[14];const N=g;let y;return e[15]!==v||e[16]!==N?(y={probe:v,schema:N},e[15]=v,e[16]=N,e[17]=y):y=e[17],y},Pe=/\b(?:from|join|update|into)\s+([a-z_][\w$]*)|\b([a-z_][\w$]*)\s*\./gi,Tn=l=>{const e=new Set;Pe.lastIndex=0;let n=Pe.exec(l);for(;n!==null;)e.add(n[1]??n[2]),n=Pe.exec(l);return[...e]};function Rn(l){return l.name}const Ln=l=>{const e=Y(34),{onSubmit:n,probe:t,schema:o,setDraft:s}=l,r=pt(),c=Ce(null),a=Ce(null),i=Ce(null),f=yn(o,i,s),{close:p,commit:m,commitAt:x,move:d,refresh:S,state:u}=f;let v;e[0]!==x?(v=k=>{x(k)},e[0]=x,e[1]=v):v=e[1];const g=v;let N;e[2]!==S?(N=()=>{const k=i.current;k!==null&&k===document.activeElement&&S(k.value,k.selectionStart)},e[2]=S,e[3]=N):N=e[3];let y;e[4]!==S||e[5]!==o?(y=[S,o],e[4]=S,e[5]=o,e[6]=y):y=e[6],Ne(N,y);let h;e[7]!==t||e[8]!==S||e[9]!==s?(h=k=>{const{selectionStart:F,value:L}=k.target;s(L);for(const M of Tn(L))t(M);S(L,F)},e[7]=t,e[8]=S,e[9]=s,e[10]=h):h=e[10];const E=h;let w;e[11]!==S?(w=k=>{const F=k.currentTarget;S(F.value,F.selectionStart)},e[11]=S,e[12]=w):w=e[12];const R=w;let T;e[13]!==u||e[14]!==p||e[15]!==m||e[16]!==d||e[17]!==n?(T=k=>{if(u!==null){if(k.key==="ArrowDown"){k.preventDefault(),d(1);return}if(k.key==="ArrowUp"){k.preventDefault(),d(-1);return}if(k.key==="Escape"){k.preventDefault(),p();return}if((k.key==="Enter"||k.key==="Tab")&&!k.metaKey&&!k.ctrlKey&&m()){k.preventDefault();return}}(k.metaKey||k.ctrlKey)&&k.key==="Enter"&&(k.preventDefault(),n())},e[13]=u,e[14]=p,e[15]=m,e[16]=d,e[17]=n,e[18]=T):T=e[18];const _=T;let C;e[19]!==p?(C=()=>{requestAnimationFrame(()=>{p()})},e[19]=p,e[20]=C):C=e[20];const A=C;let q;e[21]===Symbol.for("react.memo_cache_sentinel")?(q=k=>{const{scrollLeft:F,scrollTop:L}=k.currentTarget;c.current!==null&&(c.current.scrollTop=L),a.current!==null&&(a.current.scrollTop=L,a.current.scrollLeft=F)},e[21]=q):q=e[21];const I=q;let B;e[22]===Symbol.for("react.memo_cache_sentinel")?(B=k=>{const F=i.current;F===null||k.offset===void 0||(F.focus(),F.setSelectionRange(k.offset,k.offset+(k.length??0)))},e[22]=B):B=e[22];const D=B;let P;e[23]!==E||e[24]!==A||e[25]!==_||e[26]!==R?(P={onBlur:A,onChange:E,onKeyDown:_,onScroll:I,onSelect:R},e[23]=E,e[24]=A,e[25]=_,e[26]=R,e[27]=P):P=e[27];let O;return e[28]!==u||e[29]!==p||e[30]!==r||e[31]!==g||e[32]!==P?(O={autocompleteState:u,closeAutocomplete:p,handlers:P,listboxId:r,onPickSuggestion:g,editorRef:i,gutterRef:c,overlayRef:a,revealDiagnostic:D},e[28]=u,e[29]=p,e[30]=r,e[31]=g,e[32]=P,e[33]=O):O=e[33],O},In="lunora-studio-sql-tabs",_n="lunora-studio-sql-active-tab",je=12,we=(l="",e="")=>({activeId:null,id:et("tab"),name:e,sql:l}),An=()=>ze(_n,""),qn=l=>{const e=Y(16),[n,t]=Fe(In),[o,s]=An(),[r]=ie(l);let c,a;e[0]!==r||e[1]!==t||e[2]!==n.length?(c=()=>{n.length===0&&t([r])},a=[r,t,n.length],e[0]=r,e[1]=t,e[2]=n.length,e[3]=c,e[4]=a):(c=e[3],a=e[4]),Ne(c,a);let i;e[5]!==r||e[6]!==n?(i=n.length===0?[r]:n,e[5]=r,e[6]=n,e[7]=i):i=e[7];const f=i;let p;e[8]!==o||e[9]!==f?(p=f.some(d=>d.id===o)?o:f[0]?.id??"",e[8]=o,e[9]=f,e[10]=p):p=e[10];const m=p;let x;return e[11]!==m||e[12]!==s||e[13]!==t||e[14]!==f?(x={activeId:m,setActiveId:s,setTabs:t,tabs:f},e[11]=m,e[12]=s,e[13]=t,e[14]=f,e[15]=x):x=e[15],x},dt=l=>l.activeId===null&&l.sql.trim()!=="",On=(l,e)=>[...l,e].slice(-je),Dn=(l,e,n)=>{const t=l.findIndex(r=>r.id===e);if(t===-1)return{activeId:l[0]?.id??"",tabs:[...l]};const o=l.filter(r=>r.id!==e);if(o.length===0){const r=n();return{activeId:r.id,tabs:[r]}}return{activeId:o[Math.min(t,o.length-1)].id,tabs:o}},Mn=(l,e)=>{const n=l.filter(t=>t.id===e);return n.length===0?{activeId:l[0]?.id??"",tabs:[...l]}:{activeId:e,tabs:n}},$n=(l,e,n)=>{const t=l.findIndex(s=>s.id===e);if(t===-1)return{activeId:n,tabs:[...l]};const o=l.slice(0,t+1);return{activeId:o.some(s=>s.id===n)?n:e,tabs:o}},Bn=l=>{const e=l();return{activeId:e.id,tabs:[e]}},Hn=(l,e,n)=>{if(l==="others")return e.filter(t=>t.id!==n);if(l==="right"){const t=e.findIndex(o=>o.id===n);return t===-1?[]:e.slice(t+1)}return[...e]},Xe={error:null,pane:"results",result:null,running:!1},Pn=l=>{const e=Y(66),{activeId:n,setActiveId:t,setTabs:o,tabs:s}=qn(l);let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={},e[0]=r):r=e[0];const[c,a]=ie(r),[i,f]=ie(null),[p,m]=ie(null);let x;e[1]!==n||e[2]!==s?(x=s.find(H=>H.id===n)??s[0]??we(),e[1]=n,e[2]=s,e[3]=x):x=e[3];const d=x,S=c[d.id]??Xe;let u;e[4]!==d.id||e[5]!==o?(u=H=>{o(U=>U.map(j=>j.id===d.id?{...j,...H}:j))},e[4]=d.id,e[5]=o,e[6]=u):u=e[6];const v=u;let g;e[7]!==d.id?(g=H=>{a(U=>{const j=U[d.id]??Xe;return{...U,[d.id]:{...j,...H}}})},e[7]=d.id,e[8]=g):g=e[8];const N=g;let y;e[9]!==t||e[10]!==o||e[11]!==s.length?(y=()=>{if(s.length>=je)return;const H=we();o(U=>On(U,H)),t(H.id)},e[9]=t,e[10]=o,e[11]=s.length,e[12]=y):y=e[12];const h=y;let E;e[13]!==t||e[14]!==o?(E=H=>{f(null),m(null),o(H.tabs),t(H.activeId);const U=new Set(H.tabs.map(Fn));a(j=>Object.fromEntries(Object.entries(j).filter(J=>{const[me]=J;return U.has(me)})))},e[13]=t,e[14]=o,e[15]=E):E=e[15];const w=E;let R;e[16]!==w||e[17]!==s?(R=H=>{w(Dn(s,H,we))},e[16]=w,e[17]=s,e[18]=R):R=e[18];const T=R;let _;e[19]!==n||e[20]!==w||e[21]!==s?(_=(H,U)=>{w(H==="others"?Mn(s,U):H==="right"?$n(s,U,n):Bn(we))},e[19]=n,e[20]=w,e[21]=s,e[22]=_):_=e[22];const C=_;let A;e[23]!==C||e[24]!==i||e[25]!==s?(A=H=>{i!==null&&(Hn(H,s,i.id).some(Wn)?m(H):C(H,i.id))},e[23]=C,e[24]=i,e[25]=s,e[26]=A):A=e[26];const q=A;let I;e[27]===Symbol.for("react.memo_cache_sentinel")?(I=(H,U)=>{U.preventDefault(),m(null),f({id:H,x:U.clientX,y:U.clientY})},e[27]=I):I=e[27];const B=I;let D;e[28]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{f(null),m(null)},e[28]=D):D=e[28];const P=D;let O;e[29]===Symbol.for("react.memo_cache_sentinel")?(O=H=>{H.preventDefault(),f(null),m(null)},e[29]=O):O=e[29];const k=O;let F;e[30]!==q?(F=()=>{q("others")},e[30]=q,e[31]=F):F=e[31];const L=F;let M;e[32]!==q?(M=()=>{q("right")},e[32]=q,e[33]=M):M=e[33];const z=M;let $;e[34]!==q?($=()=>{q("all")},e[34]=q,e[35]=$):$=e[35];const X=$;let Z;e[36]!==C||e[37]!==p||e[38]!==i?(Z=()=>{i!==null&&p!==null&&C(p,i.id),m(null)},e[36]=C,e[37]=p,e[38]=i,e[39]=Z):Z=e[39];const ee=Z;let te;e[40]===Symbol.for("react.memo_cache_sentinel")?(te=()=>{m(null)},e[40]=te):te=e[40];const ae=te;let G;e[41]!==i?(G=i===null?void 0:{left:i.x,top:i.y},e[41]=i,e[42]=G):G=e[42];const Q=G;let ne;e[43]!==o?(ne=H=>{o(U=>U.map(j=>j.activeId===H?{...j,activeId:null}:j))},e[43]=o,e[44]=ne):ne=e[44];const se=ne;let oe;e[45]!==o?(oe=(H,U)=>{o(j=>j.map(J=>J.id===H?{...J,name:U}:J))},e[45]=o,e[46]=oe):oe=e[46];const le=oe;let re;return e[47]!==d||e[48]!==n||e[49]!==h||e[50]!==T||e[51]!==ee||e[52]!==X||e[53]!==L||e[54]!==z||e[55]!==S||e[56]!==N||e[57]!==v||e[58]!==p||e[59]!==le||e[60]!==t||e[61]!==i||e[62]!==Q||e[63]!==s||e[64]!==se?(re={activeTab:d,activeTabId:n,addEditorTab:h,cancelBulk:ae,closeEditorTab:T,closeTabMenu:P,confirmBulk:ee,menuStyle:Q,onBackdropContextMenu:k,onCloseAll:X,onCloseOthers:L,onCloseToRight:z,openTabMenu:B,output:S,patchActiveOutput:N,patchActiveTab:v,pendingBulk:p,renameTab:le,setActiveTabId:t,tabMenu:i,tabs:s,unlinkQuery:se},e[47]=d,e[48]=n,e[49]=h,e[50]=T,e[51]=ee,e[52]=X,e[53]=L,e[54]=z,e[55]=S,e[56]=N,e[57]=v,e[58]=p,e[59]=le,e[60]=t,e[61]=i,e[62]=Q,e[63]=s,e[64]=se,e[65]=re):re=e[65],re};function Fn(l){return l.id}function Wn(l){return dt(l)}const Qn="lunora-studio-sql-queries",Se="lunora-studio-sql-history",zn="lunora-studio-sql-remember-history",Un=25,jn=l=>{const e=Y(41),{loadIntoActiveTab:n,unlinkQuery:t}=l,o=de(),[s,r]=Fe(Qn),[c,a]=ze(zn,!1),[i,f]=Fe(Se,c?"local":"session");let p,m;e[0]!==c?(p=()=>{c||Re(Se,"local")},m=[c],e[0]=c,e[1]=p,e[2]=m):(p=e[1],m=e[2]),Ne(p,m);const[x,d]=ie(""),S=Ce(null);let u;e[3]!==f?(u=L=>{f(M=>M[0]?.sql===L?M:[{at:Date.now(),sql:L},...M.filter($=>$.sql!==L)].slice(0,Un))},e[3]=f,e[4]=u):u=e[4];const v=u;let g;e[5]!==n||e[6]!==r||e[7]!==o?(g=()=>{const L={id:et("q"),name:o("Untitled query"),sql:""};r(M=>[L,...M]),n("",L.id)},e[5]=n,e[6]=r,e[7]=o,e[8]=g):g=e[8];const N=g;let y;e[9]!==n||e[10]!==s?(y=L=>{const M=s.find(z=>z.id===L);M!==void 0&&(n(M.sql,L),S.current?.querySelector(`[data-testid="sql-query-${L}"]`)?.scrollIntoView({block:"nearest"}))},e[9]=n,e[10]=s,e[11]=y):y=e[11];const h=y;let E;e[12]!==r||e[13]!==t?(E=L=>{r(M=>M.filter(z=>z.id!==L)),t(L)},e[12]=r,e[13]=t,e[14]=E):E=e[14];const w=E;let R;e[15]!==n?(R=L=>{n(L.currentTarget.dataset.sql??"",null)},e[15]=n,e[16]=R):R=e[16];const T=R;let _;e[17]!==n?(_=L=>{n(L.currentTarget.dataset.sql??"",null)},e[17]=n,e[18]=_):_=e[18];const C=_;let A;e[19]!==f?(A=()=>{f([]),Re(Se,"local"),Re(Se,"session")},e[19]=f,e[20]=A):A=e[20];const q=A;let I;e[21]!==i||e[22]!==a?(I=L=>{bt(Se,i,L?"local":"session"),L||Re(Se,"local"),a(L)},e[21]=i,e[22]=a,e[23]=I):I=e[23];const B=I;let D;e[24]===Symbol.for("react.memo_cache_sentinel")?(D=L=>{d(L.target.value)},e[24]=D):D=e[24];const P=D;let O;e[25]!==r?(O=(L,M)=>{r(z=>z.map($=>$.id===L?{...$,sql:M}:$))},e[25]=r,e[26]=O):O=e[26];const k=O;let F;return e[27]!==q||e[28]!==w||e[29]!==i||e[30]!==C||e[31]!==T||e[32]!==N||e[33]!==s||e[34]!==v||e[35]!==c||e[36]!==x||e[37]!==h||e[38]!==B||e[39]!==k?(F={clearHistory:q,deleteQuery:w,history:i,listRef:S,loadFromHistory:C,loadTemplate:T,newQuery:N,onSearchChange:P,queries:s,recordHistory:v,rememberHistory:c,search:x,selectQuery:h,setRememberHistory:B,updateQuerySql:k},e[27]=q,e[28]=w,e[29]=i,e[30]=C,e[31]=T,e[32]=N,e[33]=s,e[34]=v,e[35]=c,e[36]=x,e[37]=h,e[38]=B,e[39]=k,e[40]=F):F=e[40],F},ut="p-3 font-mono text-xs leading-5 whitespace-pre-wrap break-words",Yn=(l,e)=>{const n=[];for(const o of l){if(o.offset===void 0||o.length===void 0||o.length<=0)continue;const s=Math.max(0,Math.min(o.offset,e)),r=Math.max(s,Math.min(o.offset+o.length,e));s!==r&&n.push({end:r,severity:o.severity,start:s})}n.sort((o,s)=>o.start-s.start);const t=[];for(const o of n)o.start>=(t.at(-1)?.end??0)&&t.push(o);return t},Kn=l=>l==="unsafe-response"?"The model returned a statement that is not read-only, so it was discarded.":l==="empty-response"?"The model returned nothing usable.":"The model could not be reached.",Gn=l=>{const e=Y(51),{assistant:n,failed:t,onGenerated:o}=l,s=de(),[r,c]=ie("");if(n.unavailable)return null;let a;e[0]!==n?(a=n.pending("sql"),e[0]=n,e[1]=a):a=e[1];const i=a;let f;if(e[2]!==n||e[3]!==t||e[4]!==o||e[5]!==i||e[6]!==r||e[7]!==s){const p=n.reason("sql");let m;e[9]!==n||e[10]!==t||e[11]!==o||e[12]!==r?(m=C=>{const A=r.trim();if(A===""&&!C)return;ue((async()=>{const I=await n.generate(A===""?"fix the failing statement":A,C?t:void 0);I!==void 0&&o(I)})())},e[9]=n,e[10]=t,e[11]=o,e[12]=r,e[13]=m):m=e[13];const x=m;let d;e[14]!==s?(d=s("Describe the query you want"),e[14]=s,e[15]=d):d=e[15];let S;e[16]===Symbol.for("react.memo_cache_sentinel")?(S=C=>{c(C.target.value)},e[16]=S):S=e[16];let u;e[17]!==x?(u=C=>{C.key==="Enter"&&(C.preventDefault(),x(!1))},e[17]=x,e[18]=u):u=e[18];let v;e[19]!==s?(v=s("Describe the query you want"),e[19]=s,e[20]=v):v=e[20];let g;e[21]!==i||e[22]!==r||e[23]!==d||e[24]!==u||e[25]!==v?(g=b(St,{"aria-label":d,className:"h-7 flex-1 text-xs","data-testid":"sql-assistant-prompt",disabled:i,onChange:S,onKeyDown:u,placeholder:v,value:r}),e[21]=i,e[22]=r,e[23]=d,e[24]=u,e[25]=v,e[26]=g):g=e[26];const N=i&&"opacity-60";let y;e[27]!==N?(y=fe("rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",N),e[27]=N,e[28]=y):y=e[28];let h;e[29]!==i||e[30]!==r?(h=i||r.trim()==="",e[29]=i,e[30]=r,e[31]=h):h=e[31];let E;e[32]!==x?(E=()=>{x(!1)},e[32]=x,e[33]=E):E=e[33];let w;e[34]!==i||e[35]!==s?(w=s(i?"Thinking…":"Draft SQL"),e[34]=i,e[35]=s,e[36]=w):w=e[36];let R;e[37]!==y||e[38]!==h||e[39]!==E||e[40]!==w?(R=b("button",{className:y,"data-testid":"sql-assistant-generate",disabled:h,onClick:E,type:"button",children:w}),e[37]=y,e[38]=h,e[39]=E,e[40]=w,e[41]=R):R=e[41];let T;e[42]!==t||e[43]!==i||e[44]!==x||e[45]!==s?(T=t!==void 0&&b("button",{className:"rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-assistant-fix",disabled:i,onClick:()=>{x(!0)},type:"button",children:s("Fix this")}),e[42]=t,e[43]=i,e[44]=x,e[45]=s,e[46]=T):T=e[46];let _;e[47]!==R||e[48]!==T||e[49]!==g?(_=W("div",{className:"flex items-center gap-2",children:[g,R,T]}),e[47]=R,e[48]=T,e[49]=g,e[50]=_):_=e[50],f=W("div",{className:"flex flex-col gap-1 border-b border-border px-3 py-2","data-testid":"sql-assistant",children:[_,p!==void 0&&b("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-assistant-reason",role:"status",children:Kn(p)})]}),e[2]=n,e[3]=t,e[4]=o,e[5]=i,e[6]=r,e[7]=s,e[8]=f}else f=e[8];return f},Jn=l=>{const e=Y(8),{diagnostics:n,draft:t,scrollRef:o}=l;let s,r;if(e[0]!==n||e[1]!==t){r=Symbol.for("react.early_return_sentinel");e:{const i=Yn(n,t.length);if(i.length===0){r=null;break e}s=[];let f=0;for(const[p,m]of i.entries())m.start>f&&s.push(t.slice(f,m.start)),s.push(b("span",{className:fe("decoration-wavy underline underline-offset-4",m.severity==="error"?"decoration-destructive":"decoration-amber-500"),children:t.slice(m.start,m.end)},`${m.start.toString()}-${p.toString()}`)),f=m.end;s.push(t.slice(f))}e[0]=n,e[1]=t,e[2]=s,e[3]=r}else s=e[2],r=e[3];if(r!==Symbol.for("react.early_return_sentinel"))return r;let c;e[4]===Symbol.for("react.memo_cache_sentinel")?(c=fe("pointer-events-none absolute inset-0 overflow-hidden text-transparent",ut),e[4]=c):c=e[4];let a;return e[5]!==s||e[6]!==o?(a=b("div",{"aria-hidden":"true",className:c,"data-testid":"sql-diagnostics-overlay",ref:o,children:s}),e[5]=s,e[6]=o,e[7]=a):a=e[7],a},Vn={gate:"read-only",plan:"plan",schema:"schema",syntax:"syntax"},Xn=l=>{const e=Y(10),{diagnostics:n,onSelect:t}=l,o=de();if(n.length===0)return null;let s;e[0]!==o?(s=o("SQL problems"),e[0]=o,e[1]=s):s=e[1];let r;if(e[2]!==n||e[3]!==t){let a;e[5]!==t?(a=(i,f)=>b("li",{children:W("button",{className:"flex w-full items-start gap-2 px-3 py-1 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-problem",onClick:()=>{t(i)},type:"button",children:[b("span",{className:fe("mt-px shrink-0 rounded px-1 font-mono text-[10px] uppercase",i.severity==="error"?"bg-destructive/15 text-destructive":"bg-amber-500/15 text-amber-600"),children:Vn[i.source]}),b("span",{className:"min-w-0 text-muted-foreground",children:i.message})]})},`${i.source}-${(i.offset??f).toString()}-${f.toString()}`),e[5]=t,e[6]=a):a=e[6],r=n.map(a),e[2]=n,e[3]=t,e[4]=r}else r=e[4];let c;return e[7]!==s||e[8]!==r?(c=b("ul",{"aria-label":s,className:"max-h-24 shrink-0 overflow-y-auto border-t border-border bg-muted/30","data-testid":"sql-problems",children:r}),e[7]=s,e[8]=r,e[9]=c):c=e[9],c},Zn={minWidth:"2.75rem",paddingInline:"0.5rem"},es=l=>{const e=Y(64),{assistant:n,autocomplete:t,diagnostics:o,draft:s,failed:r,handlers:c,editorRef:a,gutterRef:i,listboxId:f,onGenerated:p,onPickSuggestion:m,onRevealDiagnostic:x,overlayRef:d}=l,S=de();let u,v,g,N,y,h,E,w;if(e[0]!==n||e[1]!==s||e[2]!==r||e[3]!==i||e[4]!==p){const F=s.split(`
|
|
7
|
-
`).length;E="flex min-h-0 min-w-0 flex-1 flex-col",e[13]!==n||e[14]!==r||e[15]!==p?(w=b(Gn,{assistant:n,failed:r,onGenerated:p}),e[13]=n,e[14]=r,e[15]=p,e[16]=w):w=e[16],h="flex min-h-0 min-w-0 flex-1",u="true",v="shrink-0 select-none overflow-hidden border-e border-border bg-muted/30 py-3 text-end font-mono text-xs leading-5 text-muted-foreground/60",g=i,N=Zn,y=Array.from({length:F},ts),e[0]=n,e[1]=s,e[2]=r,e[3]=i,e[4]=p,e[5]=u,e[6]=v,e[7]=g,e[8]=N,e[9]=y,e[10]=h,e[11]=E,e[12]=w}else u=e[5],v=e[6],g=e[7],N=e[8],y=e[9],h=e[10],E=e[11],w=e[12];let R;e[17]!==u||e[18]!==v||e[19]!==g||e[20]!==N||e[21]!==y?(R=b("div",{"aria-hidden":u,className:v,ref:g,style:N,children:y}),e[17]=u,e[18]=v,e[19]=g,e[20]=N,e[21]=y,e[22]=R):R=e[22];let T;e[23]!==o||e[24]!==s||e[25]!==d?(T=b(Jn,{diagnostics:o,draft:s,scrollRef:d}),e[23]=o,e[24]=s,e[25]=d,e[26]=T):T=e[26];let _;e[27]!==t||e[28]!==f?(_=t===null?void 0:`${f}-opt-${t.active.toString()}`,e[27]=t,e[28]=f,e[29]=_):_=e[29];const C=t===null?void 0:f,A=t!==null;let q;e[30]!==S?(q=S("SQL query"),e[30]=S,e[31]=q):q=e[31];let I;e[32]!==s||e[33]!==a||e[34]!==c.onBlur||e[35]!==c.onChange||e[36]!==c.onKeyDown||e[37]!==c.onScroll||e[38]!==c.onSelect||e[39]!==_||e[40]!==C||e[41]!==A||e[42]!==q?(I=b("textarea",{"aria-activedescendant":_,"aria-autocomplete":"list","aria-controls":C,"aria-expanded":A,"aria-label":q,className:`relative size-full resize-none bg-transparent outline-none ${ut}`,"data-testid":"sql-input",onBlur:c.onBlur,onChange:c.onChange,onKeyDown:c.onKeyDown,onScroll:c.onScroll,onSelect:c.onSelect,placeholder:"SELECT * FROM …",ref:a,role:"combobox",spellCheck:!1,value:s}),e[32]=s,e[33]=a,e[34]=c.onBlur,e[35]=c.onChange,e[36]=c.onKeyDown,e[37]=c.onScroll,e[38]=c.onSelect,e[39]=_,e[40]=C,e[41]=A,e[42]=q,e[43]=I):I=e[43];let B;e[44]!==t||e[45]!==f||e[46]!==m?(B=b(Cn,{listboxId:f,onPick:m,state:t}),e[44]=t,e[45]=f,e[46]=m,e[47]=B):B=e[47];let D;e[48]!==T||e[49]!==I||e[50]!==B?(D=W("div",{className:"relative min-w-0 flex-1 bg-background",children:[T,I,B]}),e[48]=T,e[49]=I,e[50]=B,e[51]=D):D=e[51];let P;e[52]!==D||e[53]!==h||e[54]!==R?(P=W("div",{className:h,children:[R,D]}),e[52]=D,e[53]=h,e[54]=R,e[55]=P):P=e[55];let O;e[56]!==o||e[57]!==x?(O=b(Xn,{diagnostics:o,onSelect:x}),e[56]=o,e[57]=x,e[58]=O):O=e[58];let k;return e[59]!==P||e[60]!==O||e[61]!==E||e[62]!==w?(k=W("div",{className:E,children:[w,P,O]}),e[59]=P,e[60]=O,e[61]=E,e[62]=w,e[63]=k):k=e[63],k};function ts(l,e){return b("div",{children:e+1},e)}const ft=[{label:"List tables",sql:"SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name;"},{label:"Table row count",sql:"SELECT COUNT(*) AS rows FROM messages;"},{label:"Recent rows",sql:"SELECT id, _creationTime, __doc__ FROM messages ORDER BY _creationTime DESC LIMIT 50;"},{label:"Index list",sql:"SELECT name, tbl_name FROM sqlite_master WHERE type = 'index' ORDER BY tbl_name;"}],ns=l=>{const e=Y(29),{active:n,onDelete:t,onSelect:o,query:s}=l,r=de();let c;e[0]!==o||e[1]!==s.id?(c=()=>{o(s.id)},e[0]=o,e[1]=s.id,e[2]=c):c=e[2];const a=c;let i;e[3]!==t||e[4]!==s.id?(i=E=>{E.stopPropagation(),t(s.id)},e[3]=t,e[4]=s.id,e[5]=i):i=e[5];const f=i,p=n?"bg-sidebar-accent font-medium text-foreground":"text-muted-foreground";let m;e[6]!==p?(m=fe("flex min-w-0 flex-1 items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] outline-none transition-colors hover:bg-sidebar-accent focus-visible:bg-sidebar-accent",p),e[6]=p,e[7]=m):m=e[7];const x=`sql-query-${s.id}`;let d;e[8]===Symbol.for("react.memo_cache_sentinel")?(d=b("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:b("path",{d:"M4 6h16M4 12h10M4 18h7"})}),e[8]=d):d=e[8];let S;e[9]!==s.name?(S=b("span",{className:"truncate",children:s.name}),e[9]=s.name,e[10]=S):S=e[10];let u;e[11]!==n||e[12]!==a||e[13]!==m||e[14]!==x||e[15]!==S?(u=W("button",{"aria-pressed":n,className:m,"data-testid":x,onClick:a,type:"button",children:[d,S]}),e[11]=n,e[12]=a,e[13]=m,e[14]=x,e[15]=S,e[16]=u):u=e[16];let v;e[17]!==r?(v=r("Delete query"),e[17]=r,e[18]=v):v=e[18];let g;e[19]!==r?(g=r("Delete query"),e[19]=r,e[20]=g):g=e[20];let N;e[21]===Symbol.for("react.memo_cache_sentinel")?(N=b("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:b("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[21]=N):N=e[21];let y;e[22]!==f||e[23]!==g||e[24]!==v?(y=b("button",{"aria-label":v,className:"me-1 hidden size-6 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive group-hover/q:flex",onClick:f,title:g,type:"button",children:N}),e[22]=f,e[23]=g,e[24]=v,e[25]=y):y=e[25];let h;return e[26]!==y||e[27]!==u?(h=W("li",{className:"group/q flex items-center",children:[u,y]}),e[26]=y,e[27]=u,e[28]=h):h=e[28],h},Ze="sql-history-remember",ss=(l,e)=>{const n=e.trim().toLowerCase();return n===""?[...l]:l.filter(t=>t.name.toLowerCase().includes(n))},os=l=>{const e=Y(66),{activeId:n,history:t,listRef:o,onClearHistory:s,onDelete:r,onLoadHistory:c,onLoadTemplate:a,onNew:i,onSearchChange:f,onSelect:p,onToggleRememberHistory:m,queries:x,rememberHistory:d,search:S}=l,u=de();let v,g,N,y,h;if(e[0]!==n||e[1]!==o||e[2]!==r||e[3]!==i||e[4]!==f||e[5]!==p||e[6]!==m||e[7]!==x||e[8]!==S||e[9]!==u){const I=ss(x,S);let B;e[15]!==m?(B=$=>{m($.target.checked)},e[15]=m,e[16]=B):B=e[16],v=B,N="flex h-full w-64 shrink-0 flex-col border-e border-border bg-sidebar";let D;e[17]!==u?(D=u("Search queries…"),e[17]=u,e[18]=D):D=e[18];let P;e[19]!==f||e[20]!==S||e[21]!==D?(P=b("input",{className:"h-8 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"sql-search",onChange:f,placeholder:D,type:"text",value:S}),e[19]=f,e[20]=S,e[21]=D,e[22]=P):P=e[22];let O;e[23]!==u?(O=u("New query"),e[23]=u,e[24]=O):O=e[24];let k;e[25]!==u?(k=u("New query"),e[25]=u,e[26]=k):k=e[26];let F;e[27]===Symbol.for("react.memo_cache_sentinel")?(F=b("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:b("path",{d:"M12 5v14M5 12h14"})}),e[27]=F):F=e[27];let L;e[28]!==i||e[29]!==O||e[30]!==k?(L=b("button",{"aria-label":O,className:"flex size-8 shrink-0 items-center justify-center rounded-md border border-border text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-new",onClick:i,title:k,type:"button",children:F}),e[28]=i,e[29]=O,e[30]=k,e[31]=L):L=e[31],e[32]!==L||e[33]!==P?(y=W("div",{className:"flex shrink-0 items-center gap-2 border-b border-border p-2",children:[P,L]}),e[32]=L,e[33]=P,e[34]=y):y=e[34],g="flex flex-1 flex-col gap-4 overflow-y-auto p-2";let M;e[35]!==u?(M=u("Private"),e[35]=u,e[36]=M):M=e[36];let z;e[37]!==M?(z=b("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:M}),e[37]=M,e[38]=z):z=e[38],h=W("div",{children:[z,I.length===0?b("p",{className:"px-1 py-2 text-xs text-muted-foreground","data-testid":"sql-private-empty",children:u("No saved queries yet — they save to this browser as you type.")}):b("ul",{className:"flex flex-col gap-px","data-testid":"sql-private",ref:o,children:I.map($=>b(ns,{active:n===$.id,onDelete:r,onSelect:p,query:$},$.id))})]}),e[0]=n,e[1]=o,e[2]=r,e[3]=i,e[4]=f,e[5]=p,e[6]=m,e[7]=x,e[8]=S,e[9]=u,e[10]=v,e[11]=g,e[12]=N,e[13]=y,e[14]=h}else v=e[10],g=e[11],N=e[12],y=e[13],h=e[14];let E;e[39]!==u?(E=u("Reference"),e[39]=u,e[40]=E):E=e[40];let w;e[41]!==E?(w=b("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:E}),e[41]=E,e[42]=w):w=e[42];let R;e[43]!==a?(R=ft.map(I=>b("li",{children:W("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":I.sql,onClick:a,type:"button",children:[b("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:b("path",{d:"M7 4h7l4 4v12H7zM14 4v4h4"})}),I.label]})},I.label)),e[43]=a,e[44]=R):R=e[44];let T;e[45]!==R?(T=b("ul",{className:"flex flex-col gap-px",children:R}),e[45]=R,e[46]=T):T=e[46];let _;e[47]!==w||e[48]!==T?(_=W("div",{children:[w,T]}),e[47]=w,e[48]=T,e[49]=_):_=e[49];let C;e[50]!==t||e[51]!==s||e[52]!==c||e[53]!==v||e[54]!==d||e[55]!==u?(C=t.length>0&&W("div",{children:[W("div",{className:"flex items-center justify-between px-1 pb-1",children:[b("p",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:u("History")}),b("button",{className:"rounded px-1 text-[11px] text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:text-foreground","data-testid":"sql-history-clear",onClick:s,type:"button",children:u("Clear history")})]}),W("label",{className:"flex cursor-pointer items-center gap-1.5 px-1 pb-1.5 text-[11px] text-muted-foreground",htmlFor:Ze,children:[b("input",{checked:d,"data-testid":"sql-history-remember",id:Ze,onChange:v,type:"checkbox"}),u("Keep history on this browser")]}),b("ul",{className:"flex flex-col gap-px","data-testid":"sql-history",children:t.map(I=>b("li",{children:W("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":I.sql,"data-testid":"sql-history-item",onClick:c,title:I.sql,type:"button",children:[b("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:b("path",{d:"M12 8v4l3 2M12 21a9 9 0 1 1 0-18 9 9 0 0 1 0 18Z"})}),b("span",{className:"truncate font-mono",children:I.sql})]})},`${I.at.toString()}:${I.sql}`))})]}),e[50]=t,e[51]=s,e[52]=c,e[53]=v,e[54]=d,e[55]=u,e[56]=C):C=e[56];let A;e[57]!==g||e[58]!==C||e[59]!==h||e[60]!==_?(A=W("div",{className:g,children:[h,_,C]}),e[57]=g,e[58]=C,e[59]=h,e[60]=_,e[61]=A):A=e[61];let q;return e[62]!==A||e[63]!==N||e[64]!==y?(q=W("aside",{className:N,children:[y,A]}),e[62]=A,e[63]=N,e[64]=y,e[65]=q):q=e[65],q},Ie=l=>`border-b-2 px-3 py-2 text-sm outline-none transition-colors ${l?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,ls=l=>{const e=Y(96),{assistant:n,chart:t,className:o,error:s,onFormat:r,onInferChart:c,onRun:a,onSelectStatement:i,onShardKeyChange:f,onShowChart:p,onShowExplain:m,onShowResults:x,onToggleSplit:d,pane:S,result:u,running:v,script:g,shardKey:N,splitView:y}=l,h=de(),E=S==="results";let w;e[0]!==E?(w=Ie(E),e[0]=E,e[1]=w):w=e[1];let R;e[2]!==h?(R=h("Results"),e[2]=h,e[3]=R):R=e[3];let T;e[4]!==x||e[5]!==w||e[6]!==R?(T=b("button",{className:w,"data-testid":"sql-tab-results",onClick:x,type:"button",children:R}),e[4]=x,e[5]=w,e[6]=R,e[7]=T):T=e[7];const _=S==="chart";let C;e[8]!==_?(C=Ie(_),e[8]=_,e[9]=C):C=e[9];let A;e[10]!==h?(A=h("Chart"),e[10]=h,e[11]=A):A=e[11];let q;e[12]!==p||e[13]!==C||e[14]!==A?(q=b("button",{className:C,"data-testid":"sql-tab-chart",onClick:p,type:"button",children:A}),e[12]=p,e[13]=C,e[14]=A,e[15]=q):q=e[15];let I;e[16]!==n||e[17]!==c||e[18]!==S||e[19]!==u||e[20]!==h?(I=!n.unavailable&&S==="chart"&&u!==null&&b("button",{className:Ie(!1),"data-testid":"sql-infer-chart",disabled:n.pending("chart"),onClick:c,type:"button",children:n.pending("chart")?h("Thinking…"):h("Suggest chart")}),e[16]=n,e[17]=c,e[18]=S,e[19]=u,e[20]=h,e[21]=I):I=e[21];const B=S==="explain";let D;e[22]!==B?(D=Ie(B),e[22]=B,e[23]=D):D=e[23];let P;e[24]!==h?(P=h("Explain"),e[24]=h,e[25]=P):P=e[25];let O;e[26]!==m||e[27]!==D||e[28]!==P?(O=b("button",{className:D,"data-testid":"sql-tab-explain",onClick:m,type:"button",children:P}),e[26]=m,e[27]=D,e[28]=P,e[29]=O):O=e[29];let k;e[30]!==h?(k=h("Split editor and results"),e[30]=h,e[31]=k):k=e[31];const F=`inline-flex items-center rounded-md border border-border px-2 py-1.5 outline-none transition-colors hover:bg-accent focus-visible:bg-accent ${y?"bg-accent text-foreground":"text-muted-foreground"}`;let L;e[32]!==h?(L=h("Split editor and results"),e[32]=h,e[33]=L):L=e[33];let M;e[34]===Symbol.for("react.memo_cache_sentinel")?(M=W("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:[b("rect",{height:"16",rx:"2",width:"18",x:"3",y:"4"}),b("path",{d:"M12 4v16"})]}),e[34]=M):M=e[34];let z;e[35]!==d||e[36]!==y||e[37]!==k||e[38]!==F||e[39]!==L?(z=b("button",{"aria-label":k,"aria-pressed":y,className:F,"data-testid":"sql-split-toggle",onClick:d,title:L,type:"button",children:M}),e[35]=d,e[36]=y,e[37]=k,e[38]=F,e[39]=L,e[40]=z):z=e[40];let $;e[41]!==u?($=u!==null&&u.columns.length>0&&b(Et,{columns:u.columns,name:"query-result",rows:u.rows}),e[41]=u,e[42]=$):$=e[42];let X;e[43]!==h?(X=h("Format"),e[43]=h,e[44]=X):X=e[44];let Z;e[45]!==r||e[46]!==v||e[47]!==X?(Z=b("button",{className:"inline-flex items-center rounded-md border border-border px-3 py-1.5 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-format",disabled:v,onClick:r,type:"button",children:X}),e[45]=r,e[46]=v,e[47]=X,e[48]=Z):Z=e[48];let ee;e[49]!==f||e[50]!==N?(ee=b(Nt,{onChange:f,testId:"sql-shard-input",value:N}),e[49]=f,e[50]=N,e[51]=ee):ee=e[51];let te;e[52]!==v||e[53]!==h?(te=h(v?"Running…":"Run"),e[52]=v,e[53]=h,e[54]=te):te=e[54];let ae;e[55]===Symbol.for("react.memo_cache_sentinel")?(ae=b("kbd",{className:"rounded border border-primary-foreground/30 px-1 font-sans text-[10px]",children:"⌘↵"}),e[55]=ae):ae=e[55];let G;e[56]!==a||e[57]!==v||e[58]!==te?(G=W("button",{className:"inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground outline-none transition-colors hover:bg-primary/90 focus-visible:bg-primary/90 disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-run",disabled:v,onClick:a,type:"button",children:[te,ae]}),e[56]=a,e[57]=v,e[58]=te,e[59]=G):G=e[59];let Q;e[60]!==z||e[61]!==$||e[62]!==Z||e[63]!==ee||e[64]!==G?(Q=W("div",{className:"ms-auto flex items-center gap-2",children:[z,$,Z,ee,G]}),e[60]=z,e[61]=$,e[62]=Z,e[63]=ee,e[64]=G,e[65]=Q):Q=e[65];let ne;e[66]!==O||e[67]!==Q||e[68]!==T||e[69]!==q||e[70]!==I?(ne=W("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pe-2",children:[T,q,I,O,Q]}),e[66]=O,e[67]=Q,e[68]=T,e[69]=q,e[70]=I,e[71]=ne):ne=e[71];let se;e[72]!==i||e[73]!==g?(se=g!==void 0&&b("div",{className:"flex shrink-0 flex-wrap items-center gap-1 border-b border-border px-3 py-1.5","data-testid":"sql-statements",children:g.runs.map((j,J)=>b("button",{"aria-pressed":J===g.selected,className:`rounded-md border px-2 py-0.5 font-mono text-[11px] outline-none transition-colors ${J===g.selected?"border-foreground text-foreground":"border-border text-muted-foreground hover:text-foreground"} ${j.error===null?"":"border-destructive/50 text-destructive"}`,"data-testid":`sql-statement-${J.toString()}`,onClick:()=>{i(J)},title:j.sql,type:"button",children:J+1},`${J.toString()}:${j.sql}`))}),e[72]=i,e[73]=g,e[74]=se):se=e[74];let oe;e[75]!==s?(oe=s!==null&&b(kt,{className:"m-3 font-mono text-xs",testId:"sql-error",variant:"destructive",children:s}),e[75]=s,e[76]=oe):oe=e[76];let le;e[77]!==s||e[78]!==u||e[79]!==h?(le=s===null&&u===null&&b("p",{className:"p-4 text-sm text-muted-foreground","data-testid":"sql-empty",children:h("Click Run to execute your query.")}),e[77]=s,e[78]=u,e[79]=h,e[80]=le):le=e[80];let re;e[81]!==t||e[82]!==s||e[83]!==S||e[84]!==u||e[85]!==h?(re=s===null&&u!==null&&W("div",{"data-testid":"sql-result",children:[S==="chart"?b(wt,{axes:t,result:u}):b(Ct,{result:u}),b("p",{className:"border-t border-border px-3 py-1.5 text-xs text-muted-foreground","data-testid":"sql-count",children:u.truncated?h("Showing the first {max} of {count} rows.",{count:u.rowCount,max:u.rows.length}):h("{count} rows",{count:u.rowCount})})]}),e[81]=t,e[82]=s,e[83]=S,e[84]=u,e[85]=h,e[86]=re):re=e[86];let H;e[87]!==oe||e[88]!==le||e[89]!==re?(H=W("div",{className:"min-h-0 flex-1 overflow-auto",children:[oe,le,re]}),e[87]=oe,e[88]=le,e[89]=re,e[90]=H):H=e[90];let U;return e[91]!==o||e[92]!==ne||e[93]!==se||e[94]!==H?(U=W("div",{className:o,children:[ne,se,H]}),e[91]=o,e[92]=ne,e[93]=se,e[94]=H,e[95]=U):U=e[95],U},rs=(l,e)=>l.trim()===""?e:(l.split(`
|
|
8
|
-
`)[0]??l).slice(0,24),is=l=>{l?.focus(),l?.select()},as=l=>{const e=Y(14),{initial:n,onCancel:t,onCommit:o,placeholder:s,testId:r}=l,c=de();let a;e[0]!==o?(a=d=>{o(d.currentTarget.value.trim())},e[0]=o,e[1]=a):a=e[1];const i=a;let f;e[2]!==t||e[3]!==o?(f=d=>{d.key==="Enter"?o(d.currentTarget.value.trim()):d.key==="Escape"&&t()},e[2]=t,e[3]=o,e[4]=f):f=e[4];const p=f;let m;e[5]!==c?(m=c("Tab title"),e[5]=c,e[6]=m):m=e[6];let x;return e[7]!==n||e[8]!==i||e[9]!==p||e[10]!==s||e[11]!==m||e[12]!==r?(x=b("input",{"aria-label":m,className:"w-40 rounded border border-ring bg-background px-1 py-0.5 text-xs outline-none","data-testid":r,defaultValue:n,onBlur:i,onKeyDown:p,placeholder:s,ref:is,type:"text"}),e[7]=n,e[8]=i,e[9]=p,e[10]=s,e[11]=m,e[12]=r,e[13]=x):x=e[13],x},cs=l=>{const e=Y(29),{idBase:n,onDiscard:t,onKeep:o}=l,s=de(),r=`sql-tab-close-prompt-${n}`;let c;e[0]!==s?(c=s("Discard?"),e[0]=s,e[1]=c):c=e[1];let a;e[2]!==c?(a=b("span",{className:"text-[11px] text-muted-foreground",children:c}),e[2]=c,e[3]=a):a=e[3];let i;e[4]!==s?(i=s("Discard changes"),e[4]=s,e[5]=i):i=e[5];const f=`sql-tab-close-confirm-${n}`;let p;e[6]!==s?(p=s("Discard changes"),e[6]=s,e[7]=p):p=e[7];let m;e[8]===Symbol.for("react.memo_cache_sentinel")?(m=b("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:b("path",{d:"M5 13l4 4L19 7"})}),e[8]=m):m=e[8];let x;e[9]!==t||e[10]!==i||e[11]!==f||e[12]!==p?(x=b("button",{"aria-label":i,className:"flex size-5 items-center justify-center rounded text-destructive hover:bg-destructive/10","data-testid":f,onClick:t,title:p,type:"button",children:m}),e[9]=t,e[10]=i,e[11]=f,e[12]=p,e[13]=x):x=e[13];let d;e[14]!==s?(d=s("Keep editing"),e[14]=s,e[15]=d):d=e[15];const S=`sql-tab-close-cancel-${n}`;let u;e[16]!==s?(u=s("Keep editing"),e[16]=s,e[17]=u):u=e[17];let v;e[18]===Symbol.for("react.memo_cache_sentinel")?(v=b("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:b("path",{d:"M6 6l12 12M18 6 6 18"})}),e[18]=v):v=e[18];let g;e[19]!==o||e[20]!==S||e[21]!==u||e[22]!==d?(g=b("button",{"aria-label":d,className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:bg-accent","data-testid":S,onClick:o,title:u,type:"button",children:v}),e[19]=o,e[20]=S,e[21]=u,e[22]=d,e[23]=g):g=e[23];let N;return e[24]!==r||e[25]!==g||e[26]!==a||e[27]!==x?(N=W("span",{className:"flex shrink-0 items-center gap-1","data-testid":r,role:"group",children:[a,x,g]}),e[24]=r,e[25]=g,e[26]=a,e[27]=x,e[28]=N):N=e[28],N},ds=l=>{const e=Y(47),{active:n,canClose:t,onClose:o,onMenu:s,onRename:r,onSelect:c,tab:a}=l,i=de(),[f,p]=ie(!1),[m,x]=ie(!1);let d;e[0]!==s||e[1]!==a.id?(d=$=>{s(a.id,$)},e[0]=s,e[1]=a.id,e[2]=d):d=e[2];const S=d;let u;e[3]!==c||e[4]!==a.id?(u=()=>{c(a.id)},e[3]=c,e[4]=a.id,e[5]=u):u=e[5];const v=u;let g;e[6]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{p(!0)},e[6]=g):g=e[6];const N=g;let y;e[7]!==o||e[8]!==a?(y=$=>{$.stopPropagation(),dt(a)?x(!0):o(a.id)},e[7]=o,e[8]=a,e[9]=y):y=e[9];const h=y;let E;e[10]!==o||e[11]!==a.id?(E=$=>{$.stopPropagation(),x(!1),o(a.id)},e[10]=o,e[11]=a.id,e[12]=E):E=e[12];const w=E;let R;e[13]===Symbol.for("react.memo_cache_sentinel")?(R=$=>{$.stopPropagation(),x(!1)},e[13]=R):R=e[13];const T=R;let _;e[14]!==r||e[15]!==a.id?(_=$=>{r(a.id,$),p(!1)},e[14]=r,e[15]=a.id,e[16]=_):_=e[16];const C=_;let A;e[17]===Symbol.for("react.memo_cache_sentinel")?(A=()=>{p(!1)},e[17]=A):A=e[17];const q=A;let I;e[18]!==a.name?(I=a.name.trim(),e[18]=a.name,e[19]=I):I=e[19];const B=I;let D;e[20]!==i||e[21]!==a.sql?(D=rs(a.sql,i("Untitled")),e[20]=i,e[21]=a.sql,e[22]=D):D=e[22];const P=D,O=n?"bg-background text-foreground":"bg-muted/40 text-muted-foreground hover:text-foreground";let k;e[23]!==O?(k=fe("group/tab flex shrink-0 items-center gap-1 border-e border-border ps-3 pe-1.5 text-xs",O),e[23]=O,e[24]=k):k=e[24];const F=`sql-tab-${a.id}`;let L;e[25]!==n||e[26]!==C||e[27]!==B||e[28]!==P||e[29]!==f||e[30]!==v||e[31]!==i||e[32]!==a.id?(L=f?b(as,{initial:B,onCancel:q,onCommit:C,placeholder:P,testId:`sql-tab-rename-${a.id}`}):b("button",{"aria-pressed":n,className:"max-w-40 truncate py-1.5 outline-none","data-testid":`sql-tab-select-${a.id}`,onClick:v,onDoubleClick:N,title:i("Double-click to rename"),type:"button",children:B===""?P:B}),e[25]=n,e[26]=C,e[27]=B,e[28]=P,e[29]=f,e[30]=v,e[31]=i,e[32]=a.id,e[33]=L):L=e[33];let M;e[34]!==t||e[35]!==w||e[36]!==m||e[37]!==h||e[38]!==i||e[39]!==a.id?(M=t&&(m?b(cs,{idBase:a.id,onDiscard:w,onKeep:T}):b("button",{"aria-label":i("Close tab"),className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive","data-testid":`sql-tab-close-${a.id}`,onClick:h,title:i("Close tab"),type:"button",children:b("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",children:b("path",{d:"M6 6l12 12M18 6 6 18"})})})),e[34]=t,e[35]=w,e[36]=m,e[37]=h,e[38]=i,e[39]=a.id,e[40]=M):M=e[40];let z;return e[41]!==S||e[42]!==k||e[43]!==F||e[44]!==L||e[45]!==M?(z=W("div",{className:k,"data-testid":F,onContextMenu:S,children:[L,M]}),e[41]=S,e[42]=k,e[43]=F,e[44]=L,e[45]=M,e[46]=z):z=e[46],z},us=l=>{const e=Y(43),{model:n,onSelect:t}=l,o=de(),{activeTab:s,addEditorTab:r,cancelBulk:c,closeEditorTab:a,closeTabMenu:i,confirmBulk:f,menuStyle:p,onBackdropContextMenu:m,onCloseAll:x,onCloseOthers:d,onCloseToRight:S,openTabMenu:u,pendingBulk:v,renameTab:g,tabMenu:N,tabs:y}=n;let h;if(e[0]!==s||e[1]!==a||e[2]!==t||e[3]!==u||e[4]!==g||e[5]!==y){let I;e[7]!==s||e[8]!==a||e[9]!==t||e[10]!==u||e[11]!==g||e[12]!==y.length?(I=B=>b(ds,{active:B.id===s.id,canClose:y.length>1,onClose:a,onMenu:u,onRename:g,onSelect:t,tab:B},B.id),e[7]=s,e[8]=a,e[9]=t,e[10]=u,e[11]=g,e[12]=y.length,e[13]=I):I=e[13],h=y.map(I),e[0]=s,e[1]=a,e[2]=t,e[3]=u,e[4]=g,e[5]=y,e[6]=h}else h=e[6];let E;e[14]!==o?(E=o("New tab"),e[14]=o,e[15]=E):E=e[15];const w=y.length>=je;let R;e[16]!==o?(R=o("New tab"),e[16]=o,e[17]=R):R=e[17];let T;e[18]===Symbol.for("react.memo_cache_sentinel")?(T=b("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:b("path",{d:"M12 5v14M5 12h14"})}),e[18]=T):T=e[18];let _;e[19]!==r||e[20]!==E||e[21]!==w||e[22]!==R?(_=b("button",{"aria-label":E,className:"flex size-8 shrink-0 items-center justify-center text-muted-foreground outline-none transition-colors hover:bg-accent hover:text-foreground focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-add",disabled:w,onClick:r,title:R,type:"button",children:T}),e[19]=r,e[20]=E,e[21]=w,e[22]=R,e[23]=_):_=e[23];let C;e[24]!==h||e[25]!==_?(C=W("div",{className:"flex shrink-0 items-stretch overflow-x-auto border-b border-border bg-muted/30","data-testid":"sql-tab-strip",role:"tablist",children:[h,_]}),e[24]=h,e[25]=_,e[26]=C):C=e[26];let A;e[27]!==c||e[28]!==i||e[29]!==f||e[30]!==p||e[31]!==m||e[32]!==x||e[33]!==d||e[34]!==S||e[35]!==v||e[36]!==o||e[37]!==N||e[38]!==y?(A=N!==null&&W(He,{children:[b("div",{className:"fixed inset-0 z-40","data-testid":"sql-tab-menu-backdrop",onClick:i,onContextMenu:m,role:"presentation"}),b("div",{className:"fixed z-50 min-w-44 rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-tab-menu",role:"menu",style:p,children:v===null?W(He,{children:[b("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-others",disabled:y.length<=1,onClick:d,role:"menuitem",type:"button",children:o("Close other tabs")}),b("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-right",disabled:y.findIndex(I=>I.id===N.id)>=y.length-1,onClick:S,role:"menuitem",type:"button",children:o("Close tabs to the right")}),b("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-close-all",onClick:x,role:"menuitem",type:"button",children:o("Close all tabs")})]}):W("div",{className:"px-3 py-1.5","data-testid":"sql-tab-menu-confirm",children:[b("p",{className:"pb-1.5 text-xs text-muted-foreground",children:o("Discard unsaved tabs?")}),W("div",{className:"flex items-center gap-1.5",children:[b("button",{className:"rounded px-2 py-1 text-xs font-medium text-destructive outline-none hover:bg-destructive/10 focus-visible:bg-destructive/10","data-testid":"sql-tab-menu-confirm-discard",onClick:f,type:"button",children:o("Discard")}),b("button",{className:"rounded px-2 py-1 text-xs text-muted-foreground outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-confirm-cancel",onClick:c,type:"button",children:o("Cancel")})]})]})})]}),e[27]=c,e[28]=i,e[29]=f,e[30]=p,e[31]=m,e[32]=x,e[33]=d,e[34]=S,e[35]=v,e[36]=o,e[37]=N,e[38]=y,e[39]=A):A=e[39];let q;return e[40]!==C||e[41]!==A?(q=W(He,{children:[C,A]}),e[40]=C,e[41]=A,e[42]=q):q=e[42],q},fs=Oe(qe.runSql),ms="lunora-studio-sql-split-view",hs=()=>we(ft[0]?.sql??""),As=l=>{const e=Y(112),{initialShardKey:n}=l,t=Qe(),o=Pn(hs),{activeTab:s,output:r,patchActiveOutput:c,patchActiveTab:a,setActiveTabId:i,unlinkQuery:f}=o;let p;e[0]!==c||e[1]!==a?(p=(K,ce)=>{a({activeId:ce,sql:K}),c({chart:void 0,error:null,failed:void 0,result:null,script:void 0})},e[0]=c,e[1]=a,e[2]=p):p=e[2];const m=p;let x;e[3]!==m||e[4]!==f?(x={loadIntoActiveTab:m,unlinkQuery:f},e[3]=m,e[4]=f,e[5]=x):x=e[5];const d=jn(x),{recordHistory:S,updateQuerySql:u}=d,v=s.sql,{activeId:g}=s,{chart:N,error:y,failed:h,result:E,running:w}=r,R=r.pane,[T,_]=ie(n??""),[C,A]=ze(ms,!1),{probe:q,schema:I}=En(T);let B;e[6]!==g||e[7]!==a||e[8]!==u?(B=K=>{a({sql:K}),g!==null&&u(g,K)},e[6]=g,e[7]=a,e[8]=u,e[9]=B):B=e[9];const D=B,P=dn(v,I,T),O=vt(T);let k;e[10]!==O||e[11]!==c||e[12]!==E?(k=()=>{if(E===null)return;ue((async()=>{const ce=await O.inferChart({columns:E.columns,rowCount:E.rowCount,types:Object.fromEntries(E.columns.map(V=>[V,typeof(E.rows[0]?.[V]??"")]))});c({chart:ce})})())},e[10]=O,e[11]=c,e[12]=E,e[13]=k):k=e[13];const F=k;let L;e[14]!==t||e[15]!==S||e[16]!==T?(L=async K=>{try{const ce=await t.query(fs,{sql:K},_e(T));return S(K),{error:null,result:ce,sql:K}}catch(ce){return{error:gt(ce),result:null,sql:K}}},e[14]=t,e[15]=S,e[16]=T,e[17]=L):L=e[17];const M=L;let z;e[18]!==v||e[19]!==c||e[20]!==M||e[21]!==T?(z=async K=>{if(v.trim()==="")return;c({running:!0});const ce=K==="explain"?We(Mt(v),0):lt(v),V=[];for(const Te of ce){const mt={error:Te.rejection?.message??"",result:null,sql:Te.sql};V.push(Te.rejection===void 0?await M(Te.sql):mt)}xt(T);const Ye=Math.max(V.length-1,0),ye=V[Ye];c({chart:void 0,error:ye?.error??null,failed:ye?.error===null||ye===void 0?void 0:{error:ye.error,sql:ye.sql},pane:K,result:ye?.result??null,running:!1,script:V.length>1?{runs:V,selected:Ye}:void 0})},e[18]=v,e[19]=c,e[20]=M,e[21]=T,e[22]=z):z=e[22];const $=z;let X;e[23]!==r.script?.runs||e[24]!==c?(X=K=>{const ce=r.script?.runs,V=ce?.[K];ce===void 0||V===void 0||c({chart:void 0,error:V.error,failed:V.error===null?void 0:{error:V.error,sql:V.sql},result:V.result,script:{runs:ce,selected:K}})},e[23]=r.script?.runs,e[24]=c,e[25]=X):X=e[25];const Z=X;let ee;e[26]!==$?(ee=()=>{ue($("results"))},e[26]=$,e[27]=ee):ee=e[27];const te=ee;let ae;e[28]!==r.pane||e[29]!==$?(ae=()=>{ue($(r.pane))},e[28]=r.pane,e[29]=$,e[30]=ae):ae=e[30];let G;e[31]!==q||e[32]!==I||e[33]!==D||e[34]!==ae?(G={onSubmit:ae,probe:q,schema:I,setDraft:D},e[31]=q,e[32]=I,e[33]=D,e[34]=ae,e[35]=G):G=e[35];const Q=Ln(G),{closeAutocomplete:ne}=Q;let se;e[36]!==v||e[37]!==D?(se=()=>{D(Wt(v))},e[36]=v,e[37]=D,e[38]=se):se=e[38];const oe=se;let le;e[39]!==ne||e[40]!==i?(le=K=>{ne(),i(K)},e[39]=ne,e[40]=i,e[41]=le):le=e[41];const re=le;let H;e[42]!==c?(H=()=>{c({pane:"results"})},e[42]=c,e[43]=H):H=e[43];const U=H;let j;e[44]!==$?(j=()=>{ue($("explain"))},e[44]=$,e[45]=j):j=e[45];const J=j;let me;e[46]!==c?(me=()=>{c({pane:"chart"})},e[46]=c,e[47]=me):me=e[47];const De=me;let ke;e[48]!==A||e[49]!==C?(ke=()=>{A(!C)},e[48]=A,e[49]=C,e[50]=ke):ke=e[50];const Me=ke,$e=C?"flex min-h-0 flex-1 flex-row":"flex min-h-0 flex-1 flex-col",Be=C?"flex w-2/5 min-h-0 min-w-0 shrink-0 flex-col border-s border-border":"flex h-2/5 min-h-0 shrink-0 flex-col border-t border-border";let he;e[51]!==g||e[52]!==d.clearHistory||e[53]!==d.deleteQuery||e[54]!==d.history||e[55]!==d.listRef||e[56]!==d.loadFromHistory||e[57]!==d.loadTemplate||e[58]!==d.newQuery||e[59]!==d.onSearchChange||e[60]!==d.queries||e[61]!==d.rememberHistory||e[62]!==d.search||e[63]!==d.selectQuery||e[64]!==d.setRememberHistory?(he=b(os,{activeId:g,history:d.history,listRef:d.listRef,onClearHistory:d.clearHistory,onDelete:d.deleteQuery,onLoadHistory:d.loadFromHistory,onLoadTemplate:d.loadTemplate,onNew:d.newQuery,onSearchChange:d.onSearchChange,onSelect:d.selectQuery,onToggleRememberHistory:d.setRememberHistory,queries:d.queries,rememberHistory:d.rememberHistory,search:d.search}),e[51]=g,e[52]=d.clearHistory,e[53]=d.deleteQuery,e[54]=d.history,e[55]=d.listRef,e[56]=d.loadFromHistory,e[57]=d.loadTemplate,e[58]=d.newQuery,e[59]=d.onSearchChange,e[60]=d.queries,e[61]=d.rememberHistory,e[62]=d.search,e[63]=d.selectQuery,e[64]=d.setRememberHistory,e[65]=he):he=e[65];let pe;e[66]!==o||e[67]!==re?(pe=b(us,{model:o,onSelect:re}),e[66]=o,e[67]=re,e[68]=pe):pe=e[68];let be;e[69]!==O||e[70]!==P||e[71]!==v||e[72]!==h||e[73]!==D||e[74]!==Q.autocompleteState||e[75]!==Q.editorRef||e[76]!==Q.gutterRef||e[77]!==Q.handlers||e[78]!==Q.listboxId||e[79]!==Q.onPickSuggestion||e[80]!==Q.overlayRef||e[81]!==Q.revealDiagnostic?(be=b(es,{assistant:O,autocomplete:Q.autocompleteState,diagnostics:P,draft:v,editorRef:Q.editorRef,failed:h,gutterRef:Q.gutterRef,handlers:Q.handlers,listboxId:Q.listboxId,onGenerated:D,onPickSuggestion:Q.onPickSuggestion,onRevealDiagnostic:Q.revealDiagnostic,overlayRef:Q.overlayRef}),e[69]=O,e[70]=P,e[71]=v,e[72]=h,e[73]=D,e[74]=Q.autocompleteState,e[75]=Q.editorRef,e[76]=Q.gutterRef,e[77]=Q.handlers,e[78]=Q.listboxId,e[79]=Q.onPickSuggestion,e[80]=Q.overlayRef,e[81]=Q.revealDiagnostic,e[82]=be):be=e[82];let ge;e[83]!==O||e[84]!==y||e[85]!==oe||e[86]!==F||e[87]!==N||e[88]!==te||e[89]!==Z||e[90]!==r.script||e[91]!==E||e[92]!==Be||e[93]!==w||e[94]!==T||e[95]!==De||e[96]!==J||e[97]!==U||e[98]!==C||e[99]!==R||e[100]!==Me?(ge=b(ls,{assistant:O,chart:N,className:Be,error:y,onFormat:oe,onInferChart:F,onRun:te,onSelectStatement:Z,onShardKeyChange:_,onShowChart:De,onShowExplain:J,onShowResults:U,onToggleSplit:Me,pane:R,result:E,running:w,script:r.script,shardKey:T,splitView:C}),e[83]=O,e[84]=y,e[85]=oe,e[86]=F,e[87]=N,e[88]=te,e[89]=Z,e[90]=r.script,e[91]=E,e[92]=Be,e[93]=w,e[94]=T,e[95]=De,e[96]=J,e[97]=U,e[98]=C,e[99]=R,e[100]=Me,e[101]=ge):ge=e[101];let xe;e[102]!==be||e[103]!==ge||e[104]!==$e?(xe=W("div",{className:$e,children:[be,ge]}),e[102]=be,e[103]=ge,e[104]=$e,e[105]=xe):xe=e[105];let ve;e[106]!==pe||e[107]!==xe?(ve=W("div",{className:"flex min-w-0 flex-1 flex-col",children:[pe,xe]}),e[106]=pe,e[107]=xe,e[108]=ve):ve=e[108];let Ee;return e[109]!==he||e[110]!==ve?(Ee=W("div",{className:"flex h-full min-w-0","data-testid":"lunora-sql-editor",children:[he,ve]}),e[109]=he,e[110]=ve,e[111]=Ee):Ee=e[111],Ee};export{As as SqlEditorPanel};
|
|
4
|
+
`);return e.join("")},Dt=/^(?:explain\s+(?:query\s+plan\s+)?)?(?:select|with)\b/iu,Ot=/\b(?:alter|attach|create|delete|detach|drop|insert|pragma|reindex|truncate|update|vacuum)\b|\breplace\b(?!\s*\()/iu,Mt=/^\w+/u,$t=/;\s*$/u,Bt=/\s/u,ct=l=>{let e=0;for(;e<l.length;){const n=l[e];if(n!==void 0&&Bt.test(n))e+=1;else if(n==="-"&&l[e+1]==="-")e=rt(l,e);else if(n==="/"&&l[e+1]==="*"){const t=it(l,e);if(t===-1)break;e=t}else break}return e},Ht=l=>{const e=ct(l),n=l.slice(e).trimEnd();if(n==="")return{code:"SQL_EMPTY",message:"the query is empty"};const o=(at(n)??n).replace($t,""),s=n.slice(0,o.length),r=o.indexOf(";");if(r!==-1)return{code:"SQL_MULTIPLE_STATEMENTS",length:1,message:"only a single statement may be run",offset:e+r};const i="the SQL editor is read-only — only SELECT / WITH / EXPLAIN queries are allowed";if(!Dt.test(s))return{code:"SQL_NOT_READONLY",length:Mt.exec(s)?.[0].length??1,message:i,offset:e};const c=Ot.exec(s);if(c!==null)return{code:"SQL_NOT_READONLY",length:c[0].length,message:`${i} (\`${c[0].toUpperCase()}\` is not allowed)`,offset:e+c.index}},Pt=/^explain\b/iu,Ft=l=>Pt.test(l.slice(ct(l)))?l:`EXPLAIN QUERY PLAN ${l}`,ze=(l,e)=>{const n=l.trim();if(n==="")return[];const t=e+l.indexOf(n),o=Ht(n);return o?.code==="SQL_EMPTY"?[]:[o===void 0?{offset:t,sql:n}:{offset:t,rejection:o,sql:n}]},dt=l=>{const e=at(l);if(e===void 0)return ze(l,0);const n=[];let t=0;for(let o=0;o<=e.length;o+=1)o!==e.length&&e[o]!==";"||(n.push(...ze(l.slice(t,o),t)),t=o+1);return n},Wt=["ORDER BY","GROUP BY","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN","EXPLAIN QUERY PLAN","SELECT","DISTINCT","FROM","WHERE","HAVING","LIMIT","OFFSET","JOIN","ON","AND","OR","AS","ASC","DESC","WITH","UNION","EXPLAIN"],Kt=["FROM","WHERE","ORDER BY","GROUP BY","HAVING","LIMIT","OFFSET","UNION","JOIN","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN"],Oe=String.fromCodePoint(0),Qt=new RegExp(`${Oe}${String.raw`(\d+)`}${Oe}`,"gu"),zt=Wt.map(l=>({pattern:new RegExp(String.raw`\b${l.replaceAll(" ",String.raw`\s+`)}\b`,"giu"),replacement:l})),Ut=Kt.map(l=>({pattern:new RegExp(String.raw`\s+${l.replaceAll(" ",String.raw`\s+`)}\b`,"gu"),replacement:`
|
|
5
|
+
${l}`})),jt=l=>{const e=[];let t=l.replaceAll(/'(?:[^']|'')*'/gu,o=>(e.push(o),`${Oe}${(e.length-1).toString()}${Oe}`)).replaceAll(/\s+/gu," ").trim();for(const{pattern:o,replacement:s}of zt)t=t.replaceAll(o,s);for(const{pattern:o,replacement:s}of Ut)t=t.replaceAll(o,s);return t=t.replaceAll(Qt,(o,s)=>e[Number(s)]??""),t},Yt=/\b(?:from|join)\s+([a-z_][\w$]*)(?:\s+(?:as\s+)?([a-z_][\w$]*))?/giu,Gt=/(?:\bwith\s+(?:recursive\s+)?|,\s*)([a-z_][\w$]*)\s+as\s*\(/giu,Jt=new Set(["cross","full","group","having","inner","join","left","limit","offset","on","order","right","union","using","where","window"]),Vt=/[^\n]/gu,Xt=(l,e)=>{const n=l[e];if(n==="'"){let t=e+1;for(;t<l.length&&l[t]!=="'";)t+=1;return Math.min(t+1,l.length)}if(n==="-"&&l[e+1]==="-"){const t=l.indexOf(`
|
|
6
|
+
`,e);return t===-1?l.length:t}if(n==="/"&&l[e+1]==="*"){const t=l.indexOf("*/",e+2);return t===-1?l.length:t+2}return-1},Zt=l=>{let e="",n=0;for(;n<l.length;){const t=Xt(l,n);t===-1?(e+=l.slice(n,n+1),n+=1):(e+=l.slice(n,t).replaceAll(Vt," "),n=t)}return e},en=l=>{const e=new Set;for(const n of l.matchAll(Gt))e.add((n[1]??"").toLowerCase());return e},tn=(l,e)=>{const n=new Map;for(const t of l.matchAll(Yt)){const o=(t[1]??"").toLowerCase(),s=(t[2]??"").toLowerCase();e.has(o)&&(n.set(o,o),s!==""&&!Jt.has(s)&&n.set(s,o))}return n},ut=(l,e)=>{const n=Zt(l),t=new Set(e.map(o=>o.toLowerCase()));return{ctes:en(n),masked:n,targets:tn(n,t)}},nn=/^(?:__lunora|sqlite_)/iu,sn=/\b(?:from|join)\s+([a-z_][\w$]*)/giu,on=/\b([a-z_][\w$]*)\.([a-z_][\w$]*)/giu,ln=new Set(["cross","full","group","having","inner","join","lateral","left","limit","offset","order","right","select","union","where","window"]),rn=(l,e,n)=>{const t=[];for(const o of l.matchAll(sn)){const s=o[1]??"",r=s.toLowerCase();!e.has(r)&&!n.has(r)&&!ln.has(r)&&!nn.test(s)&&t.push({length:s.length,message:`unknown table \`${s}\``,offset:o.index+o[0].length-s.length,severity:"error",source:"schema"})}return t},an=(l,e,n)=>{const t=[],o=new Map;for(const[s,r]of Object.entries(e.columns))o.set(s.toLowerCase(),new Set(r.map(i=>i.toLowerCase())));for(const s of l.matchAll(on)){const r=(s[1]??"").toLowerCase(),i=s[2]??"",c=n.get(r),a=c===void 0?void 0:o.get(c);a!==void 0&&!a.has(i.toLowerCase())&&t.push({length:i.length,message:`\`${c??""}\` has no column \`${i}\``,offset:s.index+s[0].length-i.length,severity:"error",source:"schema"})}return t},cn=/(?<![\w$."])(?:"([a-z_][\w$]*)"|([a-z_][\w$]*))(?![.(])/giu,dn=/\bas\s+"?([a-z_][\w$]*)"?/giu,un=(l,e,n,t)=>{const o=[...new Set(n.values())],s=new Map,r=new Set;for(const a of o){for(const f of e.columns[a]??[])r.add(f.toLowerCase());for(const f of e.docFields?.[a]??[])s.set(f.toLowerCase(),f)}if(s.size===0)return[];const i=new Set([...l.matchAll(dn)].map(a=>(a[1]??"").toLowerCase())),c=[];for(const a of l.matchAll(cn)){const f=a[1],g=f??a[2]??"",u=g.toLowerCase(),x=s.get(u);x===void 0||r.has(u)||i.has(u)||t.has(u)||n.has(u)||c.push({length:g.length,message:`\`${x}\` is a \`__doc__\` field, not a column — use \`json_extract(__doc__, '$.${x}')\``,offset:a.index+(f===void 0?0:1),severity:"error",source:"schema"})}return c},fn=(l,e)=>{if(l.trim()==="")return[];const n=dt(l),t=new Set(e.tables.map(s=>s.toLowerCase())),o=[];for(const s of n){const{offset:r,rejection:i}=s;if(i!==void 0){o.push({length:i.length,message:i.message,offset:i.offset===void 0?r:r+i.offset,severity:"error",source:"gate"});continue}const{ctes:c,masked:a,targets:f}=ut(s.sql,e.tables);o.push(...[...rn(a,t,c),...an(a,e,f),...un(a,e,f,c)].map(g=>({...g,offset:g.offset===void 0?r:r+g.offset})))}return o},mn=$e(Me.lintSql),pn=600,hn=(l,e,n)=>{const t=Ue(),[o,s]=se([]),r=Xe(()=>fn(l,e),[l,e]),i=Nt(l,pn),a=r.some(u=>u.source==="gate")||i.trim()==="",f=yt(async u=>{try{const x=await t.query(mn,{sql:i},De(n));u.cancelled||s(x.diagnostics??[])}catch{u.cancelled||s([])}},[t,i,n]);Ce(()=>{if(a){s([]);return}const u={cancelled:!1};return fe(f(u)),()=>{u.cancelled=!0}},[f,a]);const g=i===l;return Xe(()=>g?[...r,...o]:r,[r,o,g])},_e=8,bn=["AND","ASC","AS","BY","COUNT","DESC","DISTINCT","EXPLAIN","FROM","GROUP","HAVING","INNER","JOIN","LEFT","LIKE","LIMIT","NOT","NULL","OFFSET","ON","ORDER","OR","QUERY","SELECT","WHERE","WITH"],gn=new Set(["AND","BY","HAVING","ON","OR","SELECT","WHERE"]),xn=/[\w$]/,ft=l=>l!==void 0&&xn.test(l),mt=l=>{let e=l.length;for(;e>0&&ft(l[e-1]);)e-=1;return l.slice(e)},pt=(l,e)=>{let n=e;for(;n>0&&ft(l[n-1]);)n-=1;return{end:e,start:n,text:l.slice(n,e)}},et=(l,e)=>{const n=l.slice(0,e).trimEnd();return n.endsWith(".")||gn.has(mt(n).toUpperCase())},yn=(l,e,n)=>{const t=l.slice(0,e);if(!t.endsWith("."))return;const o=mt(t.slice(0,-1));if(o!=="")return ut(l,n).targets.get(o.toLowerCase())??o},Ye=(l,e)=>l.toLowerCase().startsWith(e.toLowerCase()),tt=(l,e,n,t)=>{const o=[];for(const s of l)if(Ye(s,e)&&(o.push(t(s)),o.length>=n))break;return o},vn=(l,e,n)=>{const t=new Map;for(const[o,s]of Object.entries(l.columns))for(const r of s)if(Ye(r,e)&&!t.has(r)&&(t.set(r,o),t.size>=n))return[...t].map(([i,c])=>({detail:c,kind:"column",label:i}));return[...t].map(([o,s])=>({detail:s,kind:"column",label:o}))},Sn=(l,e,n)=>{const t=pt(l,e),o=yn(l,t.start,n.tables);if(o!==void 0){const a=n.columns[o]??n.columns[o.toLowerCase()]??[];return tt(a,t.text,_e,f=>({detail:o,kind:"column",label:f}))}if(t.text===""&&!et(l,t.start))return[];const s=tt(n.tables,t.text,_e,a=>({kind:"table",label:a})),r=vn(n,t.text,_e),i=bn.flatMap(a=>t.text!==""&&Ye(a,t.text)&&a.toLowerCase()!==t.text.toLowerCase()?[{kind:"keyword",label:a}]:[]);return(et(l,t.start)?[...r,...s,...i]:[...s,...r,...i]).slice(0,_e)},wn=(l,e,n)=>{const t=pt(l,e),o=l.slice(0,t.start)+n.label+l.slice(t.end);return{caret:t.start+n.label.length,value:o}},Cn=["boxSizing","borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textTransform","width","wordSpacing"],En=(l,e)=>{const n=globalThis.getComputedStyle(l),t=globalThis.document.createElement("div"),{style:o}=t;o.position="absolute",o.visibility="hidden",o.whiteSpace="pre-wrap",o.overflowWrap="break-word";for(const c of Cn)o[c]=n[c];t.textContent=l.value.slice(0,Math.max(0,e));const s=globalThis.document.createElement("span");s.textContent=l.value.slice(Math.max(0,e))||".",t.append(s),globalThis.document.body.append(t);const r=s.offsetLeft-l.scrollLeft,i=s.offsetTop-l.scrollTop;return t.remove(),{left:r,top:i}},Nn=(l,e,n)=>{const t=X(16),[o,s]=se(null);let r;t[0]!==l||t[1]!==e?(r=(y,b)=>{const C=Sn(y,b,l);if(C.length===0){s(null);return}const v=e.current,{left:p,top:E}=v===null?{left:0,top:0}:En(v,b);s(w=>w!==null&&w.active===0&&w.left===p&&w.top===E&&w.suggestions.length===C.length&&w.suggestions.every((k,R)=>{const S=C.at(R);return k.kind===S?.kind&&k.label===S.label&&k.detail===S.detail})?w:{active:0,left:p,suggestions:C,top:E})},t[0]=l,t[1]=e,t[2]=r):r=t[2];const i=r;let c;t[3]===Symbol.for("react.memo_cache_sentinel")?(c=()=>{s(null)},t[3]=c):c=t[3];const a=c;let f;t[4]===Symbol.for("react.memo_cache_sentinel")?(f=y=>{s(b=>{if(b===null)return b;const C=b.suggestions.length,v=(b.active+y+C)%C;return{...b,active:v}})},t[4]=f):f=t[4];const g=f;let u;t[5]!==n||t[6]!==o||t[7]!==e?(u=y=>{const b=e.current;if(o===null||b===null)return!1;const C=o.suggestions[y??o.active];if(C===void 0)return!1;const v=wn(b.value,b.selectionStart,C);return n(v.value),s(null),requestAnimationFrame(()=>{const p=e.current;p!==null&&(p.focus(),p.setSelectionRange(v.caret,v.caret))}),!0},t[5]=n,t[6]=o,t[7]=e,t[8]=u):u=t[8];const x=u;let d;t[9]!==x?(d=()=>x(),t[9]=x,t[10]=d):d=t[10];const N=d;let m;return t[11]!==N||t[12]!==x||t[13]!==i||t[14]!==o?(m={close:a,commit:N,commitAt:x,move:g,refresh:i,state:o},t[11]=N,t[12]=x,t[13]=i,t[14]=o,t[15]=m):m=t[15],m},kn={column:"column",keyword:"keyword",table:"table"},Tn=20,Rn=l=>{const e=X(17),{listboxId:n,onPick:t,state:o}=l,s=ce();let r;e[0]!==o?(r=o===null?void 0:{left:o.left,top:o.top+Tn},e[0]=o,e[1]=r):r=e[1];const i=r;if(o===null)return null;let c;if(e[2]!==n||e[3]!==t||e[4]!==o.active||e[5]!==o.suggestions||e[6]!==s){let f;e[8]!==n||e[9]!==t||e[10]!==o.active||e[11]!==s?(f=(g,u)=>H("li",{"aria-selected":u===o.active,className:ue("flex cursor-pointer items-center gap-2 px-2 py-1 text-[13px]",u===o.active?"bg-accent text-accent-foreground":"text-foreground"),"data-testid":"sql-autocomplete-item",id:`${n}-opt-${u.toString()}`,onMouseDown:x=>{x.preventDefault(),t(u)},role:"option",children:[h("span",{className:"truncate font-mono",children:g.label}),g.detail!==void 0&&h("span",{className:"ms-auto truncate text-xs text-muted-foreground",children:g.detail}),h("span",{className:"shrink-0 font-mono text-[10px] tracking-wide text-muted-foreground/70 uppercase",children:s(kn[g.kind])})]},`${g.kind}:${g.label}`),e[8]=n,e[9]=t,e[10]=o.active,e[11]=s,e[12]=f):f=e[12],c=o.suggestions.map(f),e[2]=n,e[3]=t,e[4]=o.active,e[5]=o.suggestions,e[6]=s,e[7]=c}else c=e[7];let a;return e[13]!==n||e[14]!==i||e[15]!==c?(a=h("ul",{className:"absolute z-30 max-h-56 w-72 overflow-auto rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-autocomplete",id:n,role:"listbox",style:i,children:c}),e[13]=n,e[14]=i,e[15]=c,e[16]=a):a=e[16],a},In=$e(Me.listTables),Ln=$e(Me.readTablePage),_n=l=>{const e=X(18),n=Ue();let t;e[0]===Symbol.for("react.memo_cache_sentinel")?(t=[],e[0]=t):t=e[0];const[o,s]=se(t);let r;e[1]===Symbol.for("react.memo_cache_sentinel")?(r={},e[1]=r):r=e[1];const[i,c]=se(r);let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a={},e[2]=a):a=e[2];const[f,g]=se(a);let u;e[3]===Symbol.for("react.memo_cache_sentinel")?(u=new Set,e[3]=u):u=e[3];const x=me(u);let d,N;e[4]!==n||e[5]!==l?(d=()=>{const p={cancelled:!1};return fe((async()=>{try{const w=await n.query(In,{},De(l));p.cancelled||(s(w.map(qn)),c({}),g({}),x.current=new Set)}catch{p.cancelled||(s([]),c({}),g({}),x.current=new Set)}})()),()=>{p.cancelled=!0}},N=[n,l],e[4]=n,e[5]=l,e[6]=d,e[7]=N):(d=e[6],N=e[7]),Ce(d,N);let m;e[8]!==n||e[9]!==l?(m=p=>{if(x.current.has(p))return;x.current.add(p),fe((async()=>{try{const w=await n.query(Ln,{limit:1,offset:0,table:p},De(l)),{sqlColumns:T}=w;if(T===void 0){x.current.delete(p);return}const k=new Set(T),R=w.columns.filter(S=>!k.has(S));c(S=>({...S,[p]:T})),g(S=>({...S,[p]:R}))}catch{x.current.delete(p)}})())},e[8]=n,e[9]=l,e[10]=m):m=e[10];const y=m;let b;e[11]!==i||e[12]!==f||e[13]!==o?(b={columns:i,docFields:f,tables:o},e[11]=i,e[12]=f,e[13]=o,e[14]=b):b=e[14];const C=b;let v;return e[15]!==y||e[16]!==C?(v={probe:y,schema:C},e[15]=y,e[16]=C,e[17]=v):v=e[17],v},Ke=/\b(?:from|join|update|into)\s+([a-z_][\w$]*)|\b([a-z_][\w$]*)\s*\./gi,An=l=>{const e=new Set;Ke.lastIndex=0;let n=Ke.exec(l);for(;n!==null;)e.add(n[1]??n[2]),n=Ke.exec(l);return[...e]};function qn(l){return l.name}const Dn=l=>(l.metaKey||l.ctrlKey)&&!l.shiftKey&&!l.altKey&&l.key.toLowerCase()==="i",On=l=>{const e=X(44),{inlineEditEnabled:n,onSubmit:t,probe:o,schema:s,setDraft:r}=l,i=vt(),[c,a]=se(null),f=me(null),g=me(null),u=me(null),x=Nn(s,u,r),{close:d,commit:N,commitAt:m,move:y,refresh:b,state:C}=x;let v;e[0]!==m?(v=q=>{m(q)},e[0]=m,e[1]=v):v=e[1];const p=v;let E;e[2]!==b?(E=()=>{const q=u.current;q!==null&&q===document.activeElement&&b(q.value,q.selectionStart)},e[2]=b,e[3]=E):E=e[3];let w;e[4]!==b||e[5]!==s?(w=[b,s],e[4]=b,e[5]=s,e[6]=w):w=e[6],Ce(E,w);let T;e[7]!==o||e[8]!==b||e[9]!==r?(T=q=>{const{selectionStart:U,value:j}=q.target;r(j),a(null);for(const G of An(j))o(G);b(j,U)},e[7]=o,e[8]=b,e[9]=r,e[10]=T):T=e[10];const k=T;let R;e[11]!==b?(R=q=>{const U=q.currentTarget;b(U.value,U.selectionStart)},e[11]=b,e[12]=R):R=e[12];const S=R;let _;e[13]!==d||e[14]!==N||e[15]!==y?(_=q=>q.key==="ArrowDown"?(q.preventDefault(),y(1),!0):q.key==="ArrowUp"?(q.preventDefault(),y(-1),!0):q.key==="Escape"?(q.preventDefault(),d(),!0):(q.key==="Enter"||q.key==="Tab")&&!q.metaKey&&!q.ctrlKey&&N()?(q.preventDefault(),!0):!1,e[13]=d,e[14]=N,e[15]=y,e[16]=_):_=e[16];const A=_;let L;e[17]!==C||e[18]!==d||e[19]!==n||e[20]!==A||e[21]!==t?(L=q=>{if(!(C!==null&&A(q))){if((q.metaKey||q.ctrlKey)&&q.key==="Enter"){q.preventDefault(),t();return}if(n&&Dn(q)){q.preventDefault(),d();const{selectionEnd:U,selectionStart:j,value:G}=q.currentTarget,[O,ne]=j===U?[0,G.length]:[j,U];a({end:ne,start:O,text:G.slice(O,ne)})}}},e[17]=C,e[18]=d,e[19]=n,e[20]=A,e[21]=t,e[22]=L):L=e[22];const F=L;let B;e[23]!==d?(B=()=>{requestAnimationFrame(()=>{d()})},e[23]=d,e[24]=B):B=e[24];const z=B;let M;e[25]===Symbol.for("react.memo_cache_sentinel")?(M=q=>{const{scrollLeft:U,scrollTop:j}=q.currentTarget;f.current!==null&&(f.current.scrollTop=j),g.current!==null&&(g.current.scrollTop=j,g.current.scrollLeft=U)},e[25]=M):M=e[25];const W=M;let Q;e[26]===Symbol.for("react.memo_cache_sentinel")?(Q=q=>{const U=u.current;U===null||q.offset===void 0||(U.focus(),U.setSelectionRange(q.offset,q.offset+(q.length??0)))},e[26]=Q):Q=e[26];const I=Q;let D;e[27]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{a(null),u.current?.focus()},e[27]=D):D=e[27];const K=D;let $;e[28]!==c||e[29]!==r?($=q=>{const U=u.current;if(c===null||U===null)return;const{end:j,start:G,text:O}=c;if(U.value.slice(G,j)!==O){K();return}r(U.value.slice(0,G)+q+U.value.slice(j)),a(null),U.focus(),requestAnimationFrame(()=>{U.setSelectionRange(G,G+q.length)})},e[28]=c,e[29]=r,e[30]=$):$=e[30];const ee=$;let J;e[31]!==k||e[32]!==z||e[33]!==F||e[34]!==S?(J={onBlur:z,onChange:k,onKeyDown:F,onScroll:W,onSelect:S},e[31]=k,e[32]=z,e[33]=F,e[34]=S,e[35]=J):J=e[35];let Z;return e[36]!==ee||e[37]!==C||e[38]!==d||e[39]!==c||e[40]!==i||e[41]!==p||e[42]!==J?(Z={acceptInlineEdit:ee,autocompleteState:C,closeAutocomplete:d,closeInlineEdit:K,inlineEdit:c,handlers:J,listboxId:i,onPickSuggestion:p,editorRef:u,gutterRef:f,overlayRef:g,revealDiagnostic:I},e[36]=ee,e[37]=C,e[38]=d,e[39]=c,e[40]=i,e[41]=p,e[42]=J,e[43]=Z):Z=e[43],Z},Mn="lunora-studio-sql-tabs",$n="lunora-studio-sql-active-tab",Ge=12,Ee=(l="",e="")=>({activeId:null,id:ot("tab"),name:e,sql:l}),Bn=()=>je($n,""),Hn=l=>{const e=X(16),[n,t]=Qe(Mn),[o,s]=Bn(),[r]=se(l);let i,c;e[0]!==r||e[1]!==t||e[2]!==n.length?(i=()=>{n.length===0&&t([r])},c=[r,t,n.length],e[0]=r,e[1]=t,e[2]=n.length,e[3]=i,e[4]=c):(i=e[3],c=e[4]),Ce(i,c);let a;e[5]!==r||e[6]!==n?(a=n.length===0?[r]:n,e[5]=r,e[6]=n,e[7]=a):a=e[7];const f=a;let g;e[8]!==o||e[9]!==f?(g=f.some(d=>d.id===o)?o:f[0]?.id??"",e[8]=o,e[9]=f,e[10]=g):g=e[10];const u=g;let x;return e[11]!==u||e[12]!==s||e[13]!==t||e[14]!==f?(x={activeId:u,setActiveId:s,setTabs:t,tabs:f},e[11]=u,e[12]=s,e[13]=t,e[14]=f,e[15]=x):x=e[15],x},ht=l=>l.activeId===null&&l.sql.trim()!=="",Pn=(l,e)=>[...l,e].slice(-Ge),Fn=(l,e,n)=>{const t=l.findIndex(r=>r.id===e);if(t===-1)return{activeId:l[0]?.id??"",tabs:[...l]};const o=l.filter(r=>r.id!==e);if(o.length===0){const r=n();return{activeId:r.id,tabs:[r]}}return{activeId:o[Math.min(t,o.length-1)].id,tabs:o}},Wn=(l,e)=>{const n=l.filter(t=>t.id===e);return n.length===0?{activeId:l[0]?.id??"",tabs:[...l]}:{activeId:e,tabs:n}},Kn=(l,e,n)=>{const t=l.findIndex(s=>s.id===e);if(t===-1)return{activeId:n,tabs:[...l]};const o=l.slice(0,t+1);return{activeId:o.some(s=>s.id===n)?n:e,tabs:o}},Qn=l=>{const e=l();return{activeId:e.id,tabs:[e]}},zn=(l,e,n)=>{if(l==="others")return e.filter(t=>t.id!==n);if(l==="right"){const t=e.findIndex(o=>o.id===n);return t===-1?[]:e.slice(t+1)}return[...e]},nt={error:null,pane:"results",result:null,running:!1},Un=l=>{const e=X(66),{activeId:n,setActiveId:t,setTabs:o,tabs:s}=Hn(l);let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={},e[0]=r):r=e[0];const[i,c]=se(r),[a,f]=se(null),[g,u]=se(null);let x;e[1]!==n||e[2]!==s?(x=s.find(P=>P.id===n)??s[0]??Ee(),e[1]=n,e[2]=s,e[3]=x):x=e[3];const d=x,N=i[d.id]??nt;let m;e[4]!==d.id||e[5]!==o?(m=P=>{o(Y=>Y.map(V=>V.id===d.id?{...V,...P}:V))},e[4]=d.id,e[5]=o,e[6]=m):m=e[6];const y=m;let b;e[7]!==d.id?(b=P=>{c(Y=>{const V=Y[d.id]??nt;return{...Y,[d.id]:{...V,...P}}})},e[7]=d.id,e[8]=b):b=e[8];const C=b;let v;e[9]!==t||e[10]!==o||e[11]!==s.length?(v=()=>{if(s.length>=Ge)return;const P=Ee();o(Y=>Pn(Y,P)),t(P.id)},e[9]=t,e[10]=o,e[11]=s.length,e[12]=v):v=e[12];const p=v;let E;e[13]!==t||e[14]!==o?(E=P=>{f(null),u(null),o(P.tabs),t(P.activeId);const Y=new Set(P.tabs.map(jn));c(V=>Object.fromEntries(Object.entries(V).filter(oe=>{const[pe]=oe;return Y.has(pe)})))},e[13]=t,e[14]=o,e[15]=E):E=e[15];const w=E;let T;e[16]!==w||e[17]!==s?(T=P=>{w(Fn(s,P,Ee))},e[16]=w,e[17]=s,e[18]=T):T=e[18];const k=T;let R;e[19]!==n||e[20]!==w||e[21]!==s?(R=(P,Y)=>{w(P==="others"?Wn(s,Y):P==="right"?Kn(s,Y,n):Qn(Ee))},e[19]=n,e[20]=w,e[21]=s,e[22]=R):R=e[22];const S=R;let _;e[23]!==S||e[24]!==a||e[25]!==s?(_=P=>{a!==null&&(zn(P,s,a.id).some(Yn)?u(P):S(P,a.id))},e[23]=S,e[24]=a,e[25]=s,e[26]=_):_=e[26];const A=_;let L;e[27]===Symbol.for("react.memo_cache_sentinel")?(L=(P,Y)=>{Y.preventDefault(),u(null),f({id:P,x:Y.clientX,y:Y.clientY})},e[27]=L):L=e[27];const F=L;let B;e[28]===Symbol.for("react.memo_cache_sentinel")?(B=()=>{f(null),u(null)},e[28]=B):B=e[28];const z=B;let M;e[29]===Symbol.for("react.memo_cache_sentinel")?(M=P=>{P.preventDefault(),f(null),u(null)},e[29]=M):M=e[29];const W=M;let Q;e[30]!==A?(Q=()=>{A("others")},e[30]=A,e[31]=Q):Q=e[31];const I=Q;let D;e[32]!==A?(D=()=>{A("right")},e[32]=A,e[33]=D):D=e[33];const K=D;let $;e[34]!==A?($=()=>{A("all")},e[34]=A,e[35]=$):$=e[35];const ee=$;let J;e[36]!==S||e[37]!==g||e[38]!==a?(J=()=>{a!==null&&g!==null&&S(g,a.id),u(null)},e[36]=S,e[37]=g,e[38]=a,e[39]=J):J=e[39];const Z=J;let q;e[40]===Symbol.for("react.memo_cache_sentinel")?(q=()=>{u(null)},e[40]=q):q=e[40];const U=q;let j;e[41]!==a?(j=a===null?void 0:{left:a.x,top:a.y},e[41]=a,e[42]=j):j=e[42];const G=j;let O;e[43]!==o?(O=P=>{o(Y=>Y.map(V=>V.activeId===P?{...V,activeId:null}:V))},e[43]=o,e[44]=O):O=e[44];const ne=O;let re;e[45]!==o?(re=(P,Y)=>{o(V=>V.map(oe=>oe.id===P?{...oe,name:Y}:oe))},e[45]=o,e[46]=re):re=e[46];const ie=re;let ae;return e[47]!==d||e[48]!==n||e[49]!==p||e[50]!==k||e[51]!==Z||e[52]!==ee||e[53]!==I||e[54]!==K||e[55]!==N||e[56]!==C||e[57]!==y||e[58]!==g||e[59]!==ie||e[60]!==t||e[61]!==a||e[62]!==G||e[63]!==s||e[64]!==ne?(ae={activeTab:d,activeTabId:n,addEditorTab:p,cancelBulk:U,closeEditorTab:k,closeTabMenu:z,confirmBulk:Z,menuStyle:G,onBackdropContextMenu:W,onCloseAll:ee,onCloseOthers:I,onCloseToRight:K,openTabMenu:F,output:N,patchActiveOutput:C,patchActiveTab:y,pendingBulk:g,renameTab:ie,setActiveTabId:t,tabMenu:a,tabs:s,unlinkQuery:ne},e[47]=d,e[48]=n,e[49]=p,e[50]=k,e[51]=Z,e[52]=ee,e[53]=I,e[54]=K,e[55]=N,e[56]=C,e[57]=y,e[58]=g,e[59]=ie,e[60]=t,e[61]=a,e[62]=G,e[63]=s,e[64]=ne,e[65]=ae):ae=e[65],ae};function jn(l){return l.id}function Yn(l){return ht(l)}const Gn="lunora-studio-sql-queries",we="lunora-studio-sql-history",Jn="lunora-studio-sql-remember-history",Vn=25,Xn=l=>{const e=X(41),{loadIntoActiveTab:n,unlinkQuery:t}=l,o=ce(),[s,r]=Qe(Gn),[i,c]=je(Jn,!1),[a,f]=Qe(we,i?"local":"session");let g,u;e[0]!==i?(g=()=>{i||Le(we,"local")},u=[i],e[0]=i,e[1]=g,e[2]=u):(g=e[1],u=e[2]),Ce(g,u);const[x,d]=se(""),N=me(null);let m;e[3]!==f?(m=I=>{f(D=>D[0]?.sql===I?D:[{at:Date.now(),sql:I},...D.filter($=>$.sql!==I)].slice(0,Vn))},e[3]=f,e[4]=m):m=e[4];const y=m;let b;e[5]!==n||e[6]!==r||e[7]!==o?(b=()=>{const I={id:ot("q"),name:o("Untitled query"),sql:""};r(D=>[I,...D]),n("",I.id)},e[5]=n,e[6]=r,e[7]=o,e[8]=b):b=e[8];const C=b;let v;e[9]!==n||e[10]!==s?(v=I=>{const D=s.find(K=>K.id===I);D!==void 0&&(n(D.sql,I),N.current?.querySelector(`[data-testid="sql-query-${I}"]`)?.scrollIntoView({block:"nearest"}))},e[9]=n,e[10]=s,e[11]=v):v=e[11];const p=v;let E;e[12]!==r||e[13]!==t?(E=I=>{r(D=>D.filter(K=>K.id!==I)),t(I)},e[12]=r,e[13]=t,e[14]=E):E=e[14];const w=E;let T;e[15]!==n?(T=I=>{n(I.currentTarget.dataset.sql??"",null)},e[15]=n,e[16]=T):T=e[16];const k=T;let R;e[17]!==n?(R=I=>{n(I.currentTarget.dataset.sql??"",null)},e[17]=n,e[18]=R):R=e[18];const S=R;let _;e[19]!==f?(_=()=>{f([]),Le(we,"local"),Le(we,"session")},e[19]=f,e[20]=_):_=e[20];const A=_;let L;e[21]!==a||e[22]!==c?(L=I=>{St(we,a,I?"local":"session"),I||Le(we,"local"),c(I)},e[21]=a,e[22]=c,e[23]=L):L=e[23];const F=L;let B;e[24]===Symbol.for("react.memo_cache_sentinel")?(B=I=>{d(I.target.value)},e[24]=B):B=e[24];const z=B;let M;e[25]!==r?(M=(I,D)=>{r(K=>K.map($=>$.id===I?{...$,sql:D}:$))},e[25]=r,e[26]=M):M=e[26];const W=M;let Q;return e[27]!==A||e[28]!==w||e[29]!==a||e[30]!==S||e[31]!==k||e[32]!==C||e[33]!==s||e[34]!==y||e[35]!==i||e[36]!==x||e[37]!==p||e[38]!==F||e[39]!==W?(Q={clearHistory:A,deleteQuery:w,history:a,listRef:N,loadFromHistory:S,loadTemplate:k,newQuery:C,onSearchChange:z,queries:s,recordHistory:y,rememberHistory:i,search:x,selectQuery:p,setRememberHistory:F,updateQuerySql:W},e[27]=A,e[28]=w,e[29]=a,e[30]=S,e[31]=k,e[32]=C,e[33]=s,e[34]=y,e[35]=i,e[36]=x,e[37]=p,e[38]=F,e[39]=W,e[40]=Q):Q=e[40],Q},Je="p-3 font-mono text-xs leading-5 whitespace-pre-wrap break-words",Zn=(l,e)=>{const n=[];for(const o of l){if(o.offset===void 0||o.length===void 0||o.length<=0)continue;const s=Math.max(0,Math.min(o.offset,e)),r=Math.max(s,Math.min(o.offset+o.length,e));s!==r&&n.push({end:r,severity:o.severity,start:s})}n.sort((o,s)=>o.start-s.start);const t=[];for(const o of n)o.start>=(t.at(-1)?.end??0)&&t.push(o);return t},bt=(l,e)=>e(l==="unsafe-response"?"The model returned a statement that is not read-only, so it was discarded.":l==="too-long"?"The statement is too long to rewrite. Select a shorter part of it.":l==="empty-response"?"The model returned nothing usable.":"The model could not be reached."),es=l=>{const e=X(51),{assistant:n,failed:t,onGenerated:o}=l,s=ce(),[r,i]=se("");if(n.unavailable)return null;let c;e[0]!==n?(c=n.pending("sql"),e[0]=n,e[1]=c):c=e[1];const a=c;let f;if(e[2]!==n||e[3]!==t||e[4]!==o||e[5]!==a||e[6]!==r||e[7]!==s){const g=n.reason("sql");let u;e[9]!==n||e[10]!==t||e[11]!==o||e[12]!==r?(u=S=>{const _=r.trim();if(_===""&&!S)return;fe((async()=>{const L=await n.generate(_===""?"fix the failing statement":_,S?t:void 0);L!==void 0&&o(L)})())},e[9]=n,e[10]=t,e[11]=o,e[12]=r,e[13]=u):u=e[13];const x=u;let d;e[14]!==s?(d=s("Describe the query you want"),e[14]=s,e[15]=d):d=e[15];let N;e[16]===Symbol.for("react.memo_cache_sentinel")?(N=S=>{i(S.target.value)},e[16]=N):N=e[16];let m;e[17]!==x?(m=S=>{S.key==="Enter"&&(S.preventDefault(),x(!1))},e[17]=x,e[18]=m):m=e[18];let y;e[19]!==s?(y=s("Describe the query you want"),e[19]=s,e[20]=y):y=e[20];let b;e[21]!==a||e[22]!==r||e[23]!==d||e[24]!==m||e[25]!==y?(b=h(lt,{"aria-label":d,className:"h-7 flex-1 text-xs","data-testid":"sql-assistant-prompt",disabled:a,onChange:N,onKeyDown:m,placeholder:y,value:r}),e[21]=a,e[22]=r,e[23]=d,e[24]=m,e[25]=y,e[26]=b):b=e[26];const C=a&&"opacity-60";let v;e[27]!==C?(v=ue("rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",C),e[27]=C,e[28]=v):v=e[28];let p;e[29]!==a||e[30]!==r?(p=a||r.trim()==="",e[29]=a,e[30]=r,e[31]=p):p=e[31];let E;e[32]!==x?(E=()=>{x(!1)},e[32]=x,e[33]=E):E=e[33];let w;e[34]!==a||e[35]!==s?(w=s(a?"Thinking…":"Draft SQL"),e[34]=a,e[35]=s,e[36]=w):w=e[36];let T;e[37]!==v||e[38]!==p||e[39]!==E||e[40]!==w?(T=h("button",{className:v,"data-testid":"sql-assistant-generate",disabled:p,onClick:E,type:"button",children:w}),e[37]=v,e[38]=p,e[39]=E,e[40]=w,e[41]=T):T=e[41];let k;e[42]!==t||e[43]!==a||e[44]!==x||e[45]!==s?(k=t!==void 0&&h("button",{className:"rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-assistant-fix",disabled:a,onClick:()=>{x(!0)},type:"button",children:s("Fix this")}),e[42]=t,e[43]=a,e[44]=x,e[45]=s,e[46]=k):k=e[46];let R;e[47]!==T||e[48]!==k||e[49]!==b?(R=H("div",{className:"flex items-center gap-2",children:[b,T,k]}),e[47]=T,e[48]=k,e[49]=b,e[50]=R):R=e[50],f=H("div",{className:"flex flex-col gap-1 border-b border-border px-3 py-2","data-testid":"sql-assistant",children:[R,g!==void 0&&h("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-assistant-reason",role:"status",children:bt(g,s)})]}),e[2]=n,e[3]=t,e[4]=o,e[5]=a,e[6]=r,e[7]=s,e[8]=f}else f=e[8];return f},ts=l=>{const e=X(8),{diagnostics:n,draft:t,scrollRef:o}=l;let s,r;if(e[0]!==n||e[1]!==t){r=Symbol.for("react.early_return_sentinel");e:{const a=Zn(n,t.length);if(a.length===0){r=null;break e}s=[];let f=0;for(const[g,u]of a.entries())u.start>f&&s.push(t.slice(f,u.start)),s.push(h("span",{className:ue("decoration-wavy underline underline-offset-4",u.severity==="error"?"decoration-destructive":"decoration-amber-500"),children:t.slice(u.start,u.end)},`${u.start.toString()}-${g.toString()}`)),f=u.end;s.push(t.slice(f))}e[0]=n,e[1]=t,e[2]=s,e[3]=r}else s=e[2],r=e[3];if(r!==Symbol.for("react.early_return_sentinel"))return r;let i;e[4]===Symbol.for("react.memo_cache_sentinel")?(i=ue("pointer-events-none absolute inset-0 overflow-hidden text-transparent",Je),e[4]=i):i=e[4];let c;return e[5]!==s||e[6]!==o?(c=h("div",{"aria-hidden":"true",className:i,"data-testid":"sql-diagnostics-overlay",ref:o,children:s}),e[5]=s,e[6]=o,e[7]=c):c=e[7],c},ns={gate:"read-only",plan:"plan",schema:"schema",syntax:"syntax"},ss=l=>{const e=X(10),{diagnostics:n,onSelect:t}=l,o=ce();if(n.length===0)return null;let s;e[0]!==o?(s=o("SQL problems"),e[0]=o,e[1]=s):s=e[1];let r;if(e[2]!==n||e[3]!==t){let c;e[5]!==t?(c=(a,f)=>h("li",{children:H("button",{className:"flex w-full items-start gap-2 px-3 py-1 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-problem",onClick:()=>{t(a)},type:"button",children:[h("span",{className:ue("mt-px shrink-0 rounded px-1 font-mono text-[10px] uppercase",a.severity==="error"?"bg-destructive/15 text-destructive":"bg-amber-500/15 text-amber-600"),children:ns[a.source]}),h("span",{className:"min-w-0 text-muted-foreground",children:a.message})]})},`${a.source}-${(a.offset??f).toString()}-${f.toString()}`),e[5]=t,e[6]=c):c=e[6],r=n.map(c),e[2]=n,e[3]=t,e[4]=r}else r=e[4];let i;return e[7]!==s||e[8]!==r?(i=h("ul",{"aria-label":s,className:"max-h-24 shrink-0 overflow-y-auto border-t border-border bg-muted/30","data-testid":"sql-problems",children:r}),e[7]=s,e[8]=r,e[9]=i):i=e[9],i},os=l=>(l.endsWith(`
|
|
7
|
+
`)?l.slice(0,-1):l).split(`
|
|
8
|
+
`),ls=(l,e)=>{const n=[];let t=1,o=1;for(const s of kt(l,e,{ignoreNewlineAtEof:!0}))for(const r of os(s.value))s.added?(n.push({after:o,kind:"added",text:r}),o+=1):s.removed?(n.push({before:t,kind:"removed",text:r}),t+=1):(n.push({after:o,before:t,kind:"context",text:r}),t+=1,o+=1);return n},rs={added:"bg-emerald-500/10 text-emerald-700 dark:text-emerald-400",context:"text-muted-foreground",removed:"bg-destructive/10 text-destructive"},is={added:"+",context:" ",removed:"-"},as=l=>{const e=X(11),{lines:n}=l,t=ce();let o;e[0]!==t?(o=t("Proposed edit"),e[0]=t,e[1]=o):o=e[1];let s;e[2]===Symbol.for("react.memo_cache_sentinel")?(s=ue("max-h-48 overflow-auto rounded-md border border-border bg-background",Je),e[2]=s):s=e[2];let r;if(e[3]!==n||e[4]!==t){let c;e[6]!==t?(c=a=>H("li",{className:ue("flex gap-2",rs[a.kind]),"data-kind":a.kind,children:[h("span",{"aria-hidden":"true",className:"shrink-0 select-none opacity-60",children:is[a.kind]}),a.kind!=="context"&&h("span",{className:"sr-only",children:a.kind==="added"?t("Added"):t("Removed")}),h("span",{className:"min-w-0",children:a.text===""?" ":a.text})]},`${String(a.before)}:${String(a.after)}`),e[6]=t,e[7]=c):c=e[7],r=n.map(c),e[3]=n,e[4]=t,e[5]=r}else r=e[5];let i;return e[8]!==o||e[9]!==r?(i=h("ul",{"aria-label":o,className:s,"data-testid":"sql-inline-diff",children:r}),e[8]=o,e[9]=r,e[10]=i):i=e[10],i},Ae="rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",cs=l=>{const e=X(41),{onAccept:n,onCancel:t,rpc:o,source:s,whole:r}=l,i=ce(),c=me(null),a=me(null),[f,g]=se(""),[u,x]=se(null);let d,N;if(e[0]!==u?(d=()=>{u===null?c.current?.focus():a.current?.focus()},N=[u],e[0]=u,e[1]=d,e[2]=N):(d=e[1],N=e[2]),Ce(d,N),o.unavailable)return null;let m;e[3]!==o?(m=o.pending("sql"),e[3]=o,e[4]=m):m=e[4];const y=m;let b;if(e[5]!==f||e[6]!==n||e[7]!==t||e[8]!==y||e[9]!==u||e[10]!==o||e[11]!==s||e[12]!==i||e[13]!==r){const C=o.reason("sql");let v;e[15]!==f||e[16]!==o||e[17]!==s?(v=()=>{const A=f.trim();if(A===""||s.trim()==="")return;fe((async()=>{const F=await o.rewrite(A,s);F!==void 0&&x(F)})())},e[15]=f,e[16]=o,e[17]=s,e[18]=v):v=e[18];const p=v;let E;e[19]!==t?(E=A=>{A.key==="Escape"&&(A.preventDefault(),t())},e[19]=t,e[20]=E):E=e[20];const w=E;let T;e[21]!==i||e[22]!==r?(T=i(r?"Whole query":"Selection"),e[21]=i,e[22]=r,e[23]=T):T=e[23];let k;e[24]!==T?(k=h("span",{className:"shrink-0 rounded bg-muted px-1 font-mono text-[10px] uppercase text-muted-foreground","data-testid":"sql-inline-edit-scope",children:T}),e[24]=T,e[25]=k):k=e[25];let R;e[26]!==f||e[27]!==n||e[28]!==t||e[29]!==w||e[30]!==y||e[31]!==u||e[32]!==p||e[33]!==i?(R=u===null?H(Ne,{children:[h(lt,{"aria-label":i("Tell the model what to change"),className:"h-7 flex-1 text-xs","data-testid":"sql-inline-edit-prompt",disabled:y,onChange:A=>{g(A.target.value)},onKeyDown:A=>{if(A.key==="Enter"){A.preventDefault(),p();return}w(A)},placeholder:i("Tell the model what to change"),ref:c,value:f}),h("button",{className:ue(Ae,y&&"opacity-60"),"data-testid":"sql-inline-edit-submit",disabled:y||f.trim()==="",onClick:p,onKeyDown:w,type:"button",children:i(y?"Thinking…":"Rewrite")}),h("button",{className:Ae,"data-testid":"sql-inline-edit-cancel",onClick:t,onKeyDown:w,type:"button",children:i("Cancel")})]}):H(Ne,{children:[h("span",{className:"flex-1 text-xs text-muted-foreground",children:i("Proposed edit")}),h("button",{className:Ae,"data-testid":"sql-inline-edit-accept",onClick:()=>{n(u)},onKeyDown:w,ref:a,type:"button",children:i("Accept")}),h("button",{className:Ae,"data-testid":"sql-inline-edit-reject",onClick:()=>{x(null)},onKeyDown:w,type:"button",children:i("Reject")})]}),e[26]=f,e[27]=n,e[28]=t,e[29]=w,e[30]=y,e[31]=u,e[32]=p,e[33]=i,e[34]=R):R=e[34];let S;e[35]!==k||e[36]!==R?(S=H("div",{className:"flex items-center gap-2",children:[k,R]}),e[35]=k,e[36]=R,e[37]=S):S=e[37];let _;e[38]!==u||e[39]!==s?(_=u!==null&&h(as,{lines:ls(s,u)}),e[38]=u,e[39]=s,e[40]=_):_=e[40],b=H("div",{className:"flex flex-col gap-1 border-b border-border bg-muted/20 px-3 py-2","data-testid":"sql-inline-edit",children:[S,_,C!==void 0&&h("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-inline-edit-reason",role:"status",children:bt(C,i)})]}),e[5]=f,e[6]=n,e[7]=t,e[8]=y,e[9]=u,e[10]=o,e[11]=s,e[12]=i,e[13]=r,e[14]=b}else b=e[14];return b},ds={minWidth:"2.75rem",paddingInline:"0.5rem"},us=l=>{const e=X(75),{assistant:n,autocomplete:t,diagnostics:o,draft:s,failed:r,handlers:i,editorRef:c,gutterRef:a,inlineEdit:f,listboxId:g,onAcceptInlineEdit:u,onCancelInlineEdit:x,onGenerated:d,onPickSuggestion:N,onRevealDiagnostic:m,overlayRef:y}=l,b=ce();let C,v,p,E,w,T,k,R,S;if(e[0]!==n||e[1]!==s||e[2]!==r||e[3]!==a||e[4]!==f||e[5]!==u||e[6]!==x||e[7]!==d){const $=s.split(`
|
|
9
|
+
`).length;k="flex min-h-0 min-w-0 flex-1 flex-col",e[17]!==n||e[18]!==r||e[19]!==d?(R=h(es,{assistant:n,failed:r,onGenerated:d}),e[17]=n,e[18]=r,e[19]=d,e[20]=R):R=e[20],e[21]!==n||e[22]!==s.length||e[23]!==f||e[24]!==u||e[25]!==x?(S=f!==null&&h(cs,{onAccept:u,onCancel:x,rpc:n,source:f.text,whole:f.start===0&&f.end===s.length},`${f.start.toString()}-${f.end.toString()}`),e[21]=n,e[22]=s.length,e[23]=f,e[24]=u,e[25]=x,e[26]=S):S=e[26],T="flex min-h-0 min-w-0 flex-1",C="true",v="shrink-0 select-none overflow-hidden border-e border-border bg-muted/30 py-3 text-end font-mono text-xs leading-5 text-muted-foreground/60",p=a,E=ds,w=Array.from({length:$},fs),e[0]=n,e[1]=s,e[2]=r,e[3]=a,e[4]=f,e[5]=u,e[6]=x,e[7]=d,e[8]=C,e[9]=v,e[10]=p,e[11]=E,e[12]=w,e[13]=T,e[14]=k,e[15]=R,e[16]=S}else C=e[8],v=e[9],p=e[10],E=e[11],w=e[12],T=e[13],k=e[14],R=e[15],S=e[16];let _;e[27]!==C||e[28]!==v||e[29]!==p||e[30]!==E||e[31]!==w?(_=h("div",{"aria-hidden":C,className:v,ref:p,style:E,children:w}),e[27]=C,e[28]=v,e[29]=p,e[30]=E,e[31]=w,e[32]=_):_=e[32];let A;e[33]!==o||e[34]!==s||e[35]!==y?(A=h(ts,{diagnostics:o,draft:s,scrollRef:y}),e[33]=o,e[34]=s,e[35]=y,e[36]=A):A=e[36];let L;e[37]!==t||e[38]!==g?(L=t===null?void 0:`${g}-opt-${t.active.toString()}`,e[37]=t,e[38]=g,e[39]=L):L=e[39];const F=t===null?void 0:g,B=t!==null;let z;e[40]!==b?(z=b("SQL query"),e[40]=b,e[41]=z):z=e[41];let M;e[42]!==s||e[43]!==c||e[44]!==i.onBlur||e[45]!==i.onChange||e[46]!==i.onKeyDown||e[47]!==i.onScroll||e[48]!==i.onSelect||e[49]!==L||e[50]!==F||e[51]!==B||e[52]!==z?(M=h("textarea",{"aria-activedescendant":L,"aria-autocomplete":"list","aria-controls":F,"aria-expanded":B,"aria-label":z,className:`relative size-full resize-none bg-transparent outline-none ${Je}`,"data-testid":"sql-input",onBlur:i.onBlur,onChange:i.onChange,onKeyDown:i.onKeyDown,onScroll:i.onScroll,onSelect:i.onSelect,placeholder:"SELECT * FROM …",ref:c,role:"combobox",spellCheck:!1,value:s}),e[42]=s,e[43]=c,e[44]=i.onBlur,e[45]=i.onChange,e[46]=i.onKeyDown,e[47]=i.onScroll,e[48]=i.onSelect,e[49]=L,e[50]=F,e[51]=B,e[52]=z,e[53]=M):M=e[53];let W;e[54]!==t||e[55]!==g||e[56]!==N?(W=h(Rn,{listboxId:g,onPick:N,state:t}),e[54]=t,e[55]=g,e[56]=N,e[57]=W):W=e[57];let Q;e[58]!==A||e[59]!==M||e[60]!==W?(Q=H("div",{className:"relative min-w-0 flex-1 bg-background",children:[A,M,W]}),e[58]=A,e[59]=M,e[60]=W,e[61]=Q):Q=e[61];let I;e[62]!==_||e[63]!==Q||e[64]!==T?(I=H("div",{className:T,children:[_,Q]}),e[62]=_,e[63]=Q,e[64]=T,e[65]=I):I=e[65];let D;e[66]!==o||e[67]!==m?(D=h(ss,{diagnostics:o,onSelect:m}),e[66]=o,e[67]=m,e[68]=D):D=e[68];let K;return e[69]!==I||e[70]!==D||e[71]!==k||e[72]!==R||e[73]!==S?(K=H("div",{className:k,children:[R,S,I,D]}),e[69]=I,e[70]=D,e[71]=k,e[72]=R,e[73]=S,e[74]=K):K=e[74],K};function fs(l,e){return h("div",{children:e+1},e)}const gt=[{label:"List tables",sql:"SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name;"},{label:"Table row count",sql:"SELECT COUNT(*) AS rows FROM messages;"},{label:"Recent rows",sql:"SELECT id, _creationTime, __doc__ FROM messages ORDER BY _creationTime DESC LIMIT 50;"},{label:"Index list",sql:"SELECT name, tbl_name FROM sqlite_master WHERE type = 'index' ORDER BY tbl_name;"}],ms=l=>{const e=X(29),{active:n,onDelete:t,onSelect:o,query:s}=l,r=ce();let i;e[0]!==o||e[1]!==s.id?(i=()=>{o(s.id)},e[0]=o,e[1]=s.id,e[2]=i):i=e[2];const c=i;let a;e[3]!==t||e[4]!==s.id?(a=E=>{E.stopPropagation(),t(s.id)},e[3]=t,e[4]=s.id,e[5]=a):a=e[5];const f=a,g=n?"bg-sidebar-accent font-medium text-foreground":"text-muted-foreground";let u;e[6]!==g?(u=ue("flex min-w-0 flex-1 items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] outline-none transition-colors hover:bg-sidebar-accent focus-visible:bg-sidebar-accent",g),e[6]=g,e[7]=u):u=e[7];const x=`sql-query-${s.id}`;let d;e[8]===Symbol.for("react.memo_cache_sentinel")?(d=h("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:h("path",{d:"M4 6h16M4 12h10M4 18h7"})}),e[8]=d):d=e[8];let N;e[9]!==s.name?(N=h("span",{className:"truncate",children:s.name}),e[9]=s.name,e[10]=N):N=e[10];let m;e[11]!==n||e[12]!==c||e[13]!==u||e[14]!==x||e[15]!==N?(m=H("button",{"aria-pressed":n,className:u,"data-testid":x,onClick:c,type:"button",children:[d,N]}),e[11]=n,e[12]=c,e[13]=u,e[14]=x,e[15]=N,e[16]=m):m=e[16];let y;e[17]!==r?(y=r("Delete query"),e[17]=r,e[18]=y):y=e[18];let b;e[19]!==r?(b=r("Delete query"),e[19]=r,e[20]=b):b=e[20];let C;e[21]===Symbol.for("react.memo_cache_sentinel")?(C=h("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:h("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[21]=C):C=e[21];let v;e[22]!==f||e[23]!==b||e[24]!==y?(v=h("button",{"aria-label":y,className:"me-1 hidden size-6 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive group-hover/q:flex",onClick:f,title:b,type:"button",children:C}),e[22]=f,e[23]=b,e[24]=y,e[25]=v):v=e[25];let p;return e[26]!==v||e[27]!==m?(p=H("li",{className:"group/q flex items-center",children:[m,v]}),e[26]=v,e[27]=m,e[28]=p):p=e[28],p},st="sql-history-remember",ps=(l,e)=>{const n=e.trim().toLowerCase();return n===""?[...l]:l.filter(t=>t.name.toLowerCase().includes(n))},hs=l=>{const e=X(66),{activeId:n,history:t,listRef:o,onClearHistory:s,onDelete:r,onLoadHistory:i,onLoadTemplate:c,onNew:a,onSearchChange:f,onSelect:g,onToggleRememberHistory:u,queries:x,rememberHistory:d,search:N}=l,m=ce();let y,b,C,v,p;if(e[0]!==n||e[1]!==o||e[2]!==r||e[3]!==a||e[4]!==f||e[5]!==g||e[6]!==u||e[7]!==x||e[8]!==N||e[9]!==m){const L=ps(x,N);let F;e[15]!==u?(F=$=>{u($.target.checked)},e[15]=u,e[16]=F):F=e[16],y=F,C="flex h-full w-64 shrink-0 flex-col border-e border-border bg-sidebar";let B;e[17]!==m?(B=m("Search queries…"),e[17]=m,e[18]=B):B=e[18];let z;e[19]!==f||e[20]!==N||e[21]!==B?(z=h("input",{className:"h-8 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"sql-search",onChange:f,placeholder:B,type:"text",value:N}),e[19]=f,e[20]=N,e[21]=B,e[22]=z):z=e[22];let M;e[23]!==m?(M=m("New query"),e[23]=m,e[24]=M):M=e[24];let W;e[25]!==m?(W=m("New query"),e[25]=m,e[26]=W):W=e[26];let Q;e[27]===Symbol.for("react.memo_cache_sentinel")?(Q=h("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:h("path",{d:"M12 5v14M5 12h14"})}),e[27]=Q):Q=e[27];let I;e[28]!==a||e[29]!==M||e[30]!==W?(I=h("button",{"aria-label":M,className:"flex size-8 shrink-0 items-center justify-center rounded-md border border-border text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-new",onClick:a,title:W,type:"button",children:Q}),e[28]=a,e[29]=M,e[30]=W,e[31]=I):I=e[31],e[32]!==I||e[33]!==z?(v=H("div",{className:"flex shrink-0 items-center gap-2 border-b border-border p-2",children:[z,I]}),e[32]=I,e[33]=z,e[34]=v):v=e[34],b="flex flex-1 flex-col gap-4 overflow-y-auto p-2";let D;e[35]!==m?(D=m("Private"),e[35]=m,e[36]=D):D=e[36];let K;e[37]!==D?(K=h("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:D}),e[37]=D,e[38]=K):K=e[38],p=H("div",{children:[K,L.length===0?h("p",{className:"px-1 py-2 text-xs text-muted-foreground","data-testid":"sql-private-empty",children:m("No saved queries yet — they save to this browser as you type.")}):h("ul",{className:"flex flex-col gap-px","data-testid":"sql-private",ref:o,children:L.map($=>h(ms,{active:n===$.id,onDelete:r,onSelect:g,query:$},$.id))})]}),e[0]=n,e[1]=o,e[2]=r,e[3]=a,e[4]=f,e[5]=g,e[6]=u,e[7]=x,e[8]=N,e[9]=m,e[10]=y,e[11]=b,e[12]=C,e[13]=v,e[14]=p}else y=e[10],b=e[11],C=e[12],v=e[13],p=e[14];let E;e[39]!==m?(E=m("Reference"),e[39]=m,e[40]=E):E=e[40];let w;e[41]!==E?(w=h("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:E}),e[41]=E,e[42]=w):w=e[42];let T;e[43]!==c?(T=gt.map(L=>h("li",{children:H("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":L.sql,onClick:c,type:"button",children:[h("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:h("path",{d:"M7 4h7l4 4v12H7zM14 4v4h4"})}),L.label]})},L.label)),e[43]=c,e[44]=T):T=e[44];let k;e[45]!==T?(k=h("ul",{className:"flex flex-col gap-px",children:T}),e[45]=T,e[46]=k):k=e[46];let R;e[47]!==w||e[48]!==k?(R=H("div",{children:[w,k]}),e[47]=w,e[48]=k,e[49]=R):R=e[49];let S;e[50]!==t||e[51]!==s||e[52]!==i||e[53]!==y||e[54]!==d||e[55]!==m?(S=t.length>0&&H("div",{children:[H("div",{className:"flex items-center justify-between px-1 pb-1",children:[h("p",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:m("History")}),h("button",{className:"rounded px-1 text-[11px] text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:text-foreground","data-testid":"sql-history-clear",onClick:s,type:"button",children:m("Clear history")})]}),H("label",{className:"flex cursor-pointer items-center gap-1.5 px-1 pb-1.5 text-[11px] text-muted-foreground",htmlFor:st,children:[h("input",{checked:d,"data-testid":"sql-history-remember",id:st,onChange:y,type:"checkbox"}),m("Keep history on this browser")]}),h("ul",{className:"flex flex-col gap-px","data-testid":"sql-history",children:t.map(L=>h("li",{children:H("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":L.sql,"data-testid":"sql-history-item",onClick:i,title:L.sql,type:"button",children:[h("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:h("path",{d:"M12 8v4l3 2M12 21a9 9 0 1 1 0-18 9 9 0 0 1 0 18Z"})}),h("span",{className:"truncate font-mono",children:L.sql})]})},`${L.at.toString()}:${L.sql}`))})]}),e[50]=t,e[51]=s,e[52]=i,e[53]=y,e[54]=d,e[55]=m,e[56]=S):S=e[56];let _;e[57]!==b||e[58]!==S||e[59]!==p||e[60]!==R?(_=H("div",{className:b,children:[p,R,S]}),e[57]=b,e[58]=S,e[59]=p,e[60]=R,e[61]=_):_=e[61];let A;return e[62]!==_||e[63]!==C||e[64]!==v?(A=H("aside",{className:C,children:[v,_]}),e[62]=_,e[63]=C,e[64]=v,e[65]=A):A=e[65],A},qe=l=>`border-b-2 px-3 py-2 text-sm outline-none transition-colors ${l?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,bs=l=>{const e=X(96),{assistant:n,chart:t,className:o,error:s,onFormat:r,onInferChart:i,onRun:c,onSelectStatement:a,onShardKeyChange:f,onShowChart:g,onShowExplain:u,onShowResults:x,onToggleSplit:d,pane:N,result:m,running:y,script:b,shardKey:C,splitView:v}=l,p=ce(),E=N==="results";let w;e[0]!==E?(w=qe(E),e[0]=E,e[1]=w):w=e[1];let T;e[2]!==p?(T=p("Results"),e[2]=p,e[3]=T):T=e[3];let k;e[4]!==x||e[5]!==w||e[6]!==T?(k=h("button",{className:w,"data-testid":"sql-tab-results",onClick:x,type:"button",children:T}),e[4]=x,e[5]=w,e[6]=T,e[7]=k):k=e[7];const R=N==="chart";let S;e[8]!==R?(S=qe(R),e[8]=R,e[9]=S):S=e[9];let _;e[10]!==p?(_=p("Chart"),e[10]=p,e[11]=_):_=e[11];let A;e[12]!==g||e[13]!==S||e[14]!==_?(A=h("button",{className:S,"data-testid":"sql-tab-chart",onClick:g,type:"button",children:_}),e[12]=g,e[13]=S,e[14]=_,e[15]=A):A=e[15];let L;e[16]!==n||e[17]!==i||e[18]!==N||e[19]!==m||e[20]!==p?(L=!n.unavailable&&N==="chart"&&m!==null&&h("button",{className:qe(!1),"data-testid":"sql-infer-chart",disabled:n.pending("chart"),onClick:i,type:"button",children:n.pending("chart")?p("Thinking…"):p("Suggest chart")}),e[16]=n,e[17]=i,e[18]=N,e[19]=m,e[20]=p,e[21]=L):L=e[21];const F=N==="explain";let B;e[22]!==F?(B=qe(F),e[22]=F,e[23]=B):B=e[23];let z;e[24]!==p?(z=p("Explain"),e[24]=p,e[25]=z):z=e[25];let M;e[26]!==u||e[27]!==B||e[28]!==z?(M=h("button",{className:B,"data-testid":"sql-tab-explain",onClick:u,type:"button",children:z}),e[26]=u,e[27]=B,e[28]=z,e[29]=M):M=e[29];let W;e[30]!==p?(W=p("Split editor and results"),e[30]=p,e[31]=W):W=e[31];const Q=`inline-flex items-center rounded-md border border-border px-2 py-1.5 outline-none transition-colors hover:bg-accent focus-visible:bg-accent ${v?"bg-accent text-foreground":"text-muted-foreground"}`;let I;e[32]!==p?(I=p("Split editor and results"),e[32]=p,e[33]=I):I=e[33];let D;e[34]===Symbol.for("react.memo_cache_sentinel")?(D=H("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:[h("rect",{height:"16",rx:"2",width:"18",x:"3",y:"4"}),h("path",{d:"M12 4v16"})]}),e[34]=D):D=e[34];let K;e[35]!==d||e[36]!==v||e[37]!==W||e[38]!==Q||e[39]!==I?(K=h("button",{"aria-label":W,"aria-pressed":v,className:Q,"data-testid":"sql-split-toggle",onClick:d,title:I,type:"button",children:D}),e[35]=d,e[36]=v,e[37]=W,e[38]=Q,e[39]=I,e[40]=K):K=e[40];let $;e[41]!==m?($=m!==null&&m.columns.length>0&&h(_t,{columns:m.columns,name:"query-result",rows:m.rows}),e[41]=m,e[42]=$):$=e[42];let ee;e[43]!==p?(ee=p("Format"),e[43]=p,e[44]=ee):ee=e[44];let J;e[45]!==r||e[46]!==y||e[47]!==ee?(J=h("button",{className:"inline-flex items-center rounded-md border border-border px-3 py-1.5 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-format",disabled:y,onClick:r,type:"button",children:ee}),e[45]=r,e[46]=y,e[47]=ee,e[48]=J):J=e[48];let Z;e[49]!==f||e[50]!==C?(Z=h(It,{onChange:f,testId:"sql-shard-input",value:C}),e[49]=f,e[50]=C,e[51]=Z):Z=e[51];let q;e[52]!==y||e[53]!==p?(q=p(y?"Running…":"Run"),e[52]=y,e[53]=p,e[54]=q):q=e[54];let U;e[55]===Symbol.for("react.memo_cache_sentinel")?(U=h("kbd",{className:"rounded border border-primary-foreground/30 px-1 font-sans text-[10px]",children:"⌘↵"}),e[55]=U):U=e[55];let j;e[56]!==c||e[57]!==y||e[58]!==q?(j=H("button",{className:"inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground outline-none transition-colors hover:bg-primary/90 focus-visible:bg-primary/90 disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-run",disabled:y,onClick:c,type:"button",children:[q,U]}),e[56]=c,e[57]=y,e[58]=q,e[59]=j):j=e[59];let G;e[60]!==K||e[61]!==$||e[62]!==J||e[63]!==Z||e[64]!==j?(G=H("div",{className:"ms-auto flex items-center gap-2",children:[K,$,J,Z,j]}),e[60]=K,e[61]=$,e[62]=J,e[63]=Z,e[64]=j,e[65]=G):G=e[65];let O;e[66]!==M||e[67]!==G||e[68]!==k||e[69]!==A||e[70]!==L?(O=H("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pe-2",children:[k,A,L,M,G]}),e[66]=M,e[67]=G,e[68]=k,e[69]=A,e[70]=L,e[71]=O):O=e[71];let ne;e[72]!==a||e[73]!==b?(ne=b!==void 0&&h("div",{className:"flex shrink-0 flex-wrap items-center gap-1 border-b border-border px-3 py-1.5","data-testid":"sql-statements",children:b.runs.map((V,oe)=>h("button",{"aria-pressed":oe===b.selected,className:`rounded-md border px-2 py-0.5 font-mono text-[11px] outline-none transition-colors ${oe===b.selected?"border-foreground text-foreground":"border-border text-muted-foreground hover:text-foreground"} ${V.error===null?"":"border-destructive/50 text-destructive"}`,"data-testid":`sql-statement-${oe.toString()}`,onClick:()=>{a(oe)},title:V.sql,type:"button",children:oe+1},`${oe.toString()}:${V.sql}`))}),e[72]=a,e[73]=b,e[74]=ne):ne=e[74];let re;e[75]!==s?(re=s!==null&&h(Lt,{className:"m-3 font-mono text-xs",testId:"sql-error",variant:"destructive",children:s}),e[75]=s,e[76]=re):re=e[76];let ie;e[77]!==s||e[78]!==m||e[79]!==p?(ie=s===null&&m===null&&h("p",{className:"p-4 text-sm text-muted-foreground","data-testid":"sql-empty",children:p("Click Run to execute your query.")}),e[77]=s,e[78]=m,e[79]=p,e[80]=ie):ie=e[80];let ae;e[81]!==t||e[82]!==s||e[83]!==N||e[84]!==m||e[85]!==p?(ae=s===null&&m!==null&&H("div",{"data-testid":"sql-result",children:[N==="chart"?h(Tt,{axes:t,result:m}):h(Rt,{result:m}),h("p",{className:"border-t border-border px-3 py-1.5 text-xs text-muted-foreground","data-testid":"sql-count",children:m.truncated?p("Showing the first {max} of {count} rows.",{count:m.rowCount,max:m.rows.length}):p("{count} rows",{count:m.rowCount})})]}),e[81]=t,e[82]=s,e[83]=N,e[84]=m,e[85]=p,e[86]=ae):ae=e[86];let P;e[87]!==re||e[88]!==ie||e[89]!==ae?(P=H("div",{className:"min-h-0 flex-1 overflow-auto",children:[re,ie,ae]}),e[87]=re,e[88]=ie,e[89]=ae,e[90]=P):P=e[90];let Y;return e[91]!==o||e[92]!==O||e[93]!==ne||e[94]!==P?(Y=H("div",{className:o,children:[O,ne,P]}),e[91]=o,e[92]=O,e[93]=ne,e[94]=P,e[95]=Y):Y=e[95],Y},gs=(l,e)=>l.trim()===""?e:(l.split(`
|
|
10
|
+
`)[0]??l).slice(0,24),xs=l=>{l?.focus(),l?.select()},ys=l=>{const e=X(14),{initial:n,onCancel:t,onCommit:o,placeholder:s,testId:r}=l,i=ce();let c;e[0]!==o?(c=d=>{o(d.currentTarget.value.trim())},e[0]=o,e[1]=c):c=e[1];const a=c;let f;e[2]!==t||e[3]!==o?(f=d=>{d.key==="Enter"?o(d.currentTarget.value.trim()):d.key==="Escape"&&t()},e[2]=t,e[3]=o,e[4]=f):f=e[4];const g=f;let u;e[5]!==i?(u=i("Tab title"),e[5]=i,e[6]=u):u=e[6];let x;return e[7]!==n||e[8]!==a||e[9]!==g||e[10]!==s||e[11]!==u||e[12]!==r?(x=h("input",{"aria-label":u,className:"w-40 rounded border border-ring bg-background px-1 py-0.5 text-xs outline-none","data-testid":r,defaultValue:n,onBlur:a,onKeyDown:g,placeholder:s,ref:xs,type:"text"}),e[7]=n,e[8]=a,e[9]=g,e[10]=s,e[11]=u,e[12]=r,e[13]=x):x=e[13],x},vs=l=>{const e=X(29),{idBase:n,onDiscard:t,onKeep:o}=l,s=ce(),r=`sql-tab-close-prompt-${n}`;let i;e[0]!==s?(i=s("Discard?"),e[0]=s,e[1]=i):i=e[1];let c;e[2]!==i?(c=h("span",{className:"text-[11px] text-muted-foreground",children:i}),e[2]=i,e[3]=c):c=e[3];let a;e[4]!==s?(a=s("Discard changes"),e[4]=s,e[5]=a):a=e[5];const f=`sql-tab-close-confirm-${n}`;let g;e[6]!==s?(g=s("Discard changes"),e[6]=s,e[7]=g):g=e[7];let u;e[8]===Symbol.for("react.memo_cache_sentinel")?(u=h("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:h("path",{d:"M5 13l4 4L19 7"})}),e[8]=u):u=e[8];let x;e[9]!==t||e[10]!==a||e[11]!==f||e[12]!==g?(x=h("button",{"aria-label":a,className:"flex size-5 items-center justify-center rounded text-destructive hover:bg-destructive/10","data-testid":f,onClick:t,title:g,type:"button",children:u}),e[9]=t,e[10]=a,e[11]=f,e[12]=g,e[13]=x):x=e[13];let d;e[14]!==s?(d=s("Keep editing"),e[14]=s,e[15]=d):d=e[15];const N=`sql-tab-close-cancel-${n}`;let m;e[16]!==s?(m=s("Keep editing"),e[16]=s,e[17]=m):m=e[17];let y;e[18]===Symbol.for("react.memo_cache_sentinel")?(y=h("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:h("path",{d:"M6 6l12 12M18 6 6 18"})}),e[18]=y):y=e[18];let b;e[19]!==o||e[20]!==N||e[21]!==m||e[22]!==d?(b=h("button",{"aria-label":d,className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:bg-accent","data-testid":N,onClick:o,title:m,type:"button",children:y}),e[19]=o,e[20]=N,e[21]=m,e[22]=d,e[23]=b):b=e[23];let C;return e[24]!==r||e[25]!==b||e[26]!==c||e[27]!==x?(C=H("span",{className:"flex shrink-0 items-center gap-1","data-testid":r,role:"group",children:[c,x,b]}),e[24]=r,e[25]=b,e[26]=c,e[27]=x,e[28]=C):C=e[28],C},Ss=l=>{const e=X(47),{active:n,canClose:t,onClose:o,onMenu:s,onRename:r,onSelect:i,tab:c}=l,a=ce(),[f,g]=se(!1),[u,x]=se(!1);let d;e[0]!==s||e[1]!==c.id?(d=$=>{s(c.id,$)},e[0]=s,e[1]=c.id,e[2]=d):d=e[2];const N=d;let m;e[3]!==i||e[4]!==c.id?(m=()=>{i(c.id)},e[3]=i,e[4]=c.id,e[5]=m):m=e[5];const y=m;let b;e[6]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{g(!0)},e[6]=b):b=e[6];const C=b;let v;e[7]!==o||e[8]!==c?(v=$=>{$.stopPropagation(),ht(c)?x(!0):o(c.id)},e[7]=o,e[8]=c,e[9]=v):v=e[9];const p=v;let E;e[10]!==o||e[11]!==c.id?(E=$=>{$.stopPropagation(),x(!1),o(c.id)},e[10]=o,e[11]=c.id,e[12]=E):E=e[12];const w=E;let T;e[13]===Symbol.for("react.memo_cache_sentinel")?(T=$=>{$.stopPropagation(),x(!1)},e[13]=T):T=e[13];const k=T;let R;e[14]!==r||e[15]!==c.id?(R=$=>{r(c.id,$),g(!1)},e[14]=r,e[15]=c.id,e[16]=R):R=e[16];const S=R;let _;e[17]===Symbol.for("react.memo_cache_sentinel")?(_=()=>{g(!1)},e[17]=_):_=e[17];const A=_;let L;e[18]!==c.name?(L=c.name.trim(),e[18]=c.name,e[19]=L):L=e[19];const F=L;let B;e[20]!==a||e[21]!==c.sql?(B=gs(c.sql,a("Untitled")),e[20]=a,e[21]=c.sql,e[22]=B):B=e[22];const z=B,M=n?"bg-background text-foreground":"bg-muted/40 text-muted-foreground hover:text-foreground";let W;e[23]!==M?(W=ue("group/tab flex shrink-0 items-center gap-1 border-e border-border ps-3 pe-1.5 text-xs",M),e[23]=M,e[24]=W):W=e[24];const Q=`sql-tab-${c.id}`;let I;e[25]!==n||e[26]!==S||e[27]!==F||e[28]!==z||e[29]!==f||e[30]!==y||e[31]!==a||e[32]!==c.id?(I=f?h(ys,{initial:F,onCancel:A,onCommit:S,placeholder:z,testId:`sql-tab-rename-${c.id}`}):h("button",{"aria-pressed":n,className:"max-w-40 truncate py-1.5 outline-none","data-testid":`sql-tab-select-${c.id}`,onClick:y,onDoubleClick:C,title:a("Double-click to rename"),type:"button",children:F===""?z:F}),e[25]=n,e[26]=S,e[27]=F,e[28]=z,e[29]=f,e[30]=y,e[31]=a,e[32]=c.id,e[33]=I):I=e[33];let D;e[34]!==t||e[35]!==w||e[36]!==u||e[37]!==p||e[38]!==a||e[39]!==c.id?(D=t&&(u?h(vs,{idBase:c.id,onDiscard:w,onKeep:k}):h("button",{"aria-label":a("Close tab"),className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive","data-testid":`sql-tab-close-${c.id}`,onClick:p,title:a("Close tab"),type:"button",children:h("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",children:h("path",{d:"M6 6l12 12M18 6 6 18"})})})),e[34]=t,e[35]=w,e[36]=u,e[37]=p,e[38]=a,e[39]=c.id,e[40]=D):D=e[40];let K;return e[41]!==N||e[42]!==W||e[43]!==Q||e[44]!==I||e[45]!==D?(K=H("div",{className:W,"data-testid":Q,onContextMenu:N,children:[I,D]}),e[41]=N,e[42]=W,e[43]=Q,e[44]=I,e[45]=D,e[46]=K):K=e[46],K},ws=l=>{const e=X(43),{model:n,onSelect:t}=l,o=ce(),{activeTab:s,addEditorTab:r,cancelBulk:i,closeEditorTab:c,closeTabMenu:a,confirmBulk:f,menuStyle:g,onBackdropContextMenu:u,onCloseAll:x,onCloseOthers:d,onCloseToRight:N,openTabMenu:m,pendingBulk:y,renameTab:b,tabMenu:C,tabs:v}=n;let p;if(e[0]!==s||e[1]!==c||e[2]!==t||e[3]!==m||e[4]!==b||e[5]!==v){let L;e[7]!==s||e[8]!==c||e[9]!==t||e[10]!==m||e[11]!==b||e[12]!==v.length?(L=F=>h(Ss,{active:F.id===s.id,canClose:v.length>1,onClose:c,onMenu:m,onRename:b,onSelect:t,tab:F},F.id),e[7]=s,e[8]=c,e[9]=t,e[10]=m,e[11]=b,e[12]=v.length,e[13]=L):L=e[13],p=v.map(L),e[0]=s,e[1]=c,e[2]=t,e[3]=m,e[4]=b,e[5]=v,e[6]=p}else p=e[6];let E;e[14]!==o?(E=o("New tab"),e[14]=o,e[15]=E):E=e[15];const w=v.length>=Ge;let T;e[16]!==o?(T=o("New tab"),e[16]=o,e[17]=T):T=e[17];let k;e[18]===Symbol.for("react.memo_cache_sentinel")?(k=h("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:h("path",{d:"M12 5v14M5 12h14"})}),e[18]=k):k=e[18];let R;e[19]!==r||e[20]!==E||e[21]!==w||e[22]!==T?(R=h("button",{"aria-label":E,className:"flex size-8 shrink-0 items-center justify-center text-muted-foreground outline-none transition-colors hover:bg-accent hover:text-foreground focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-add",disabled:w,onClick:r,title:T,type:"button",children:k}),e[19]=r,e[20]=E,e[21]=w,e[22]=T,e[23]=R):R=e[23];let S;e[24]!==p||e[25]!==R?(S=H("div",{className:"flex shrink-0 items-stretch overflow-x-auto border-b border-border bg-muted/30","data-testid":"sql-tab-strip",role:"tablist",children:[p,R]}),e[24]=p,e[25]=R,e[26]=S):S=e[26];let _;e[27]!==i||e[28]!==a||e[29]!==f||e[30]!==g||e[31]!==u||e[32]!==x||e[33]!==d||e[34]!==N||e[35]!==y||e[36]!==o||e[37]!==C||e[38]!==v?(_=C!==null&&H(Ne,{children:[h("div",{className:"fixed inset-0 z-40","data-testid":"sql-tab-menu-backdrop",onClick:a,onContextMenu:u,role:"presentation"}),h("div",{className:"fixed z-50 min-w-44 rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-tab-menu",role:"menu",style:g,children:y===null?H(Ne,{children:[h("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-others",disabled:v.length<=1,onClick:d,role:"menuitem",type:"button",children:o("Close other tabs")}),h("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-right",disabled:v.findIndex(L=>L.id===C.id)>=v.length-1,onClick:N,role:"menuitem",type:"button",children:o("Close tabs to the right")}),h("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-close-all",onClick:x,role:"menuitem",type:"button",children:o("Close all tabs")})]}):H("div",{className:"px-3 py-1.5","data-testid":"sql-tab-menu-confirm",children:[h("p",{className:"pb-1.5 text-xs text-muted-foreground",children:o("Discard unsaved tabs?")}),H("div",{className:"flex items-center gap-1.5",children:[h("button",{className:"rounded px-2 py-1 text-xs font-medium text-destructive outline-none hover:bg-destructive/10 focus-visible:bg-destructive/10","data-testid":"sql-tab-menu-confirm-discard",onClick:f,type:"button",children:o("Discard")}),h("button",{className:"rounded px-2 py-1 text-xs text-muted-foreground outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-confirm-cancel",onClick:i,type:"button",children:o("Cancel")})]})]})})]}),e[27]=i,e[28]=a,e[29]=f,e[30]=g,e[31]=u,e[32]=x,e[33]=d,e[34]=N,e[35]=y,e[36]=o,e[37]=C,e[38]=v,e[39]=_):_=e[39];let A;return e[40]!==S||e[41]!==_?(A=H(Ne,{children:[S,_]}),e[40]=S,e[41]=_,e[42]=A):A=e[42],A},Cs=$e(Me.runSql),Es="lunora-studio-sql-split-view",Ns=()=>Ee(gt[0]?.sql??""),Qs=l=>{const e=X(117),{initialShardKey:n}=l,t=Ue(),o=Un(Ns),{activeTab:s,output:r,patchActiveOutput:i,patchActiveTab:c,setActiveTabId:a,unlinkQuery:f}=o;let g;e[0]!==i||e[1]!==c?(g=(te,de)=>{c({activeId:de,sql:te}),i({chart:void 0,error:null,failed:void 0,result:null,script:void 0})},e[0]=i,e[1]=c,e[2]=g):g=e[2];const u=g;let x;e[3]!==u||e[4]!==f?(x={loadIntoActiveTab:u,unlinkQuery:f},e[3]=u,e[4]=f,e[5]=x):x=e[5];const d=Xn(x),{recordHistory:N,updateQuerySql:m}=d,y=s.sql,{activeId:b}=s,{chart:C,error:v,failed:p,result:E,running:w}=r,T=r.pane,[k,R]=se(n??""),[S,_]=je(Es,!1),{probe:A,schema:L}=_n(k);let F;e[6]!==b||e[7]!==c||e[8]!==m?(F=te=>{c({sql:te}),b!==null&&m(b,te)},e[6]=b,e[7]=c,e[8]=m,e[9]=F):F=e[9];const B=F,z=hn(y,L,k),M=Et(k);let W;e[10]!==M||e[11]!==i||e[12]!==E?(W=()=>{if(E===null)return;fe((async()=>{const de=await M.inferChart({columns:E.columns,rowCount:E.rowCount,types:Object.fromEntries(E.columns.map(le=>[le,typeof(E.rows[0]?.[le]??"")]))});i({chart:de})})())},e[10]=M,e[11]=i,e[12]=E,e[13]=W):W=e[13];const Q=W;let I;e[14]!==t||e[15]!==N||e[16]!==k?(I=async te=>{try{const de=await t.query(Cs,{sql:te},De(k));return N(te),{error:null,result:de,sql:te}}catch(de){return{error:wt(de),result:null,sql:te}}},e[14]=t,e[15]=N,e[16]=k,e[17]=I):I=e[17];const D=I;let K;e[18]!==y||e[19]!==i||e[20]!==D||e[21]!==k?(K=async te=>{if(y.trim()==="")return;i({running:!0});const de=te==="explain"?ze(Ft(y),0):dt(y),le=[];for(const Ie of de){const xt={error:Ie.rejection?.message??"",result:null,sql:Ie.sql};le.push(Ie.rejection===void 0?await D(Ie.sql):xt)}Ct(k);const Ve=Math.max(le.length-1,0),Se=le[Ve];i({chart:void 0,error:Se?.error??null,failed:Se?.error===null||Se===void 0?void 0:{error:Se.error,sql:Se.sql},pane:te,result:Se?.result??null,running:!1,script:le.length>1?{runs:le,selected:Ve}:void 0})},e[18]=y,e[19]=i,e[20]=D,e[21]=k,e[22]=K):K=e[22];const $=K;let ee;e[23]!==r.script?.runs||e[24]!==i?(ee=te=>{const de=r.script?.runs,le=de?.[te];de===void 0||le===void 0||i({chart:void 0,error:le.error,failed:le.error===null?void 0:{error:le.error,sql:le.sql},result:le.result,script:{runs:de,selected:te}})},e[23]=r.script?.runs,e[24]=i,e[25]=ee):ee=e[25];const J=ee;let Z;e[26]!==$?(Z=()=>{fe($("results"))},e[26]=$,e[27]=Z):Z=e[27];const q=Z,U=!M.unavailable;let j;e[28]!==r.pane||e[29]!==$?(j=()=>{fe($(r.pane))},e[28]=r.pane,e[29]=$,e[30]=j):j=e[30];let G;e[31]!==A||e[32]!==L||e[33]!==B||e[34]!==j||e[35]!==U?(G={inlineEditEnabled:U,onSubmit:j,probe:A,schema:L,setDraft:B},e[31]=A,e[32]=L,e[33]=B,e[34]=j,e[35]=U,e[36]=G):G=e[36];const O=On(G),{closeAutocomplete:ne,closeInlineEdit:re}=O;let ie;e[37]!==y||e[38]!==B?(ie=()=>{B(jt(y))},e[37]=y,e[38]=B,e[39]=ie):ie=e[39];const ae=ie;let P;e[40]!==ne||e[41]!==re||e[42]!==a?(P=te=>{ne(),re(),a(te)},e[40]=ne,e[41]=re,e[42]=a,e[43]=P):P=e[43];const Y=P;let V;e[44]!==i?(V=()=>{i({pane:"results"})},e[44]=i,e[45]=V):V=e[45];const oe=V;let pe;e[46]!==$?(pe=()=>{fe($("explain"))},e[46]=$,e[47]=pe):pe=e[47];const Be=pe;let ke;e[48]!==i?(ke=()=>{i({pane:"chart"})},e[48]=i,e[49]=ke):ke=e[49];const He=ke;let Te;e[50]!==_||e[51]!==S?(Te=()=>{_(!S)},e[50]=_,e[51]=S,e[52]=Te):Te=e[52];const Pe=Te,Fe=S?"flex min-h-0 flex-1 flex-row":"flex min-h-0 flex-1 flex-col",We=S?"flex w-2/5 min-h-0 min-w-0 shrink-0 flex-col border-s border-border":"flex h-2/5 min-h-0 shrink-0 flex-col border-t border-border";let he;e[53]!==b||e[54]!==d.clearHistory||e[55]!==d.deleteQuery||e[56]!==d.history||e[57]!==d.listRef||e[58]!==d.loadFromHistory||e[59]!==d.loadTemplate||e[60]!==d.newQuery||e[61]!==d.onSearchChange||e[62]!==d.queries||e[63]!==d.rememberHistory||e[64]!==d.search||e[65]!==d.selectQuery||e[66]!==d.setRememberHistory?(he=h(hs,{activeId:b,history:d.history,listRef:d.listRef,onClearHistory:d.clearHistory,onDelete:d.deleteQuery,onLoadHistory:d.loadFromHistory,onLoadTemplate:d.loadTemplate,onNew:d.newQuery,onSearchChange:d.onSearchChange,onSelect:d.selectQuery,onToggleRememberHistory:d.setRememberHistory,queries:d.queries,rememberHistory:d.rememberHistory,search:d.search}),e[53]=b,e[54]=d.clearHistory,e[55]=d.deleteQuery,e[56]=d.history,e[57]=d.listRef,e[58]=d.loadFromHistory,e[59]=d.loadTemplate,e[60]=d.newQuery,e[61]=d.onSearchChange,e[62]=d.queries,e[63]=d.rememberHistory,e[64]=d.search,e[65]=d.selectQuery,e[66]=d.setRememberHistory,e[67]=he):he=e[67];let be;e[68]!==o||e[69]!==Y?(be=h(ws,{model:o,onSelect:Y}),e[68]=o,e[69]=Y,e[70]=be):be=e[70];let ge;e[71]!==M||e[72]!==z||e[73]!==y||e[74]!==p||e[75]!==B||e[76]!==O.acceptInlineEdit||e[77]!==O.autocompleteState||e[78]!==O.closeInlineEdit||e[79]!==O.editorRef||e[80]!==O.gutterRef||e[81]!==O.handlers||e[82]!==O.inlineEdit||e[83]!==O.listboxId||e[84]!==O.onPickSuggestion||e[85]!==O.overlayRef||e[86]!==O.revealDiagnostic?(ge=h(us,{assistant:M,autocomplete:O.autocompleteState,diagnostics:z,draft:y,editorRef:O.editorRef,failed:p,gutterRef:O.gutterRef,handlers:O.handlers,inlineEdit:O.inlineEdit,listboxId:O.listboxId,onAcceptInlineEdit:O.acceptInlineEdit,onCancelInlineEdit:O.closeInlineEdit,onGenerated:B,onPickSuggestion:O.onPickSuggestion,onRevealDiagnostic:O.revealDiagnostic,overlayRef:O.overlayRef}),e[71]=M,e[72]=z,e[73]=y,e[74]=p,e[75]=B,e[76]=O.acceptInlineEdit,e[77]=O.autocompleteState,e[78]=O.closeInlineEdit,e[79]=O.editorRef,e[80]=O.gutterRef,e[81]=O.handlers,e[82]=O.inlineEdit,e[83]=O.listboxId,e[84]=O.onPickSuggestion,e[85]=O.overlayRef,e[86]=O.revealDiagnostic,e[87]=ge):ge=e[87];let xe;e[88]!==M||e[89]!==v||e[90]!==ae||e[91]!==Q||e[92]!==C||e[93]!==q||e[94]!==J||e[95]!==r.script||e[96]!==E||e[97]!==We||e[98]!==w||e[99]!==k||e[100]!==He||e[101]!==Be||e[102]!==oe||e[103]!==S||e[104]!==T||e[105]!==Pe?(xe=h(bs,{assistant:M,chart:C,className:We,error:v,onFormat:ae,onInferChart:Q,onRun:q,onSelectStatement:J,onShardKeyChange:R,onShowChart:He,onShowExplain:Be,onShowResults:oe,onToggleSplit:Pe,pane:T,result:E,running:w,script:r.script,shardKey:k,splitView:S}),e[88]=M,e[89]=v,e[90]=ae,e[91]=Q,e[92]=C,e[93]=q,e[94]=J,e[95]=r.script,e[96]=E,e[97]=We,e[98]=w,e[99]=k,e[100]=He,e[101]=Be,e[102]=oe,e[103]=S,e[104]=T,e[105]=Pe,e[106]=xe):xe=e[106];let ye;e[107]!==ge||e[108]!==xe||e[109]!==Fe?(ye=H("div",{className:Fe,children:[ge,xe]}),e[107]=ge,e[108]=xe,e[109]=Fe,e[110]=ye):ye=e[110];let ve;e[111]!==be||e[112]!==ye?(ve=H("div",{className:"flex min-w-0 flex-1 flex-col",children:[be,ye]}),e[111]=be,e[112]=ye,e[113]=ve):ve=e[113];let Re;return e[114]!==he||e[115]!==ve?(Re=H("div",{className:"flex h-full min-w-0","data-testid":"lunora-sql-editor",children:[he,ve]}),e[114]=he,e[115]=ve,e[116]=Re):Re=e[116],Re};export{Qs as SqlEditorPanel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as k}from"react/compiler-runtime";import{useLunora as F}from"@lunora/react";import{useNavigate as L,useRouter as M,useSearch as P}from"@tanstack/react-router";import{useState as Q,useEffect as A}from"react";import{T as w}from"../packem_shared/storage-tier-C2mKwYRj.mjs";import{u as q}from"../packem_shared/use-mirrored-ref-CVDf2z1M.mjs";import{useT as J}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{s as K,d as D}from"../packem_shared/data-view-params-DhYmAkcj.mjs";import{f as m}from"../packem_shared/internal-Df43vQI0.mjs";import{l as O,s as I}from"../packem_shared/browser-storage-BH1MxLZs.mjs";import{DataBrowser as X}from"../packem_shared/DataBrowser-
|
|
1
|
+
import{c as k}from"react/compiler-runtime";import{useLunora as F}from"@lunora/react";import{useNavigate as L,useRouter as M,useSearch as P}from"@tanstack/react-router";import{useState as Q,useEffect as A}from"react";import{T as w}from"../packem_shared/storage-tier-C2mKwYRj.mjs";import{u as q}from"../packem_shared/use-mirrored-ref-CVDf2z1M.mjs";import{useT as J}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{s as K,d as D}from"../packem_shared/data-view-params-DhYmAkcj.mjs";import{f as m}from"../packem_shared/internal-Df43vQI0.mjs";import{l as O,s as I}from"../packem_shared/browser-storage-BH1MxLZs.mjs";import{DataBrowser as X}from"../packem_shared/DataBrowser-B-jVLGCS.mjs";import{GlobalDataBrowser as Y}from"../packem_shared/GlobalDataBrowser-DhObcZDY.mjs";import{jsx as v,jsxs as E}from"react/jsx-runtime";const N="lunora-studio-saved-queries",$=50,z=r=>r!==null&&typeof r=="object"&&typeof r.name=="string"&&typeof r.view=="object"&&r.view!==null,y=()=>O(N).filter(z),B=r=>{I(N,r)},H=(r,e)=>{const l=r.trim();if(l==="")return y();const n=[{name:l,view:e},...y().filter(o=>o.name!==l)].slice(0,$);return B(n),n},U=r=>{const e=y().filter(l=>l.name!==r);return B(e),e},W=r=>{const e=k(15),{onChange:l,tier:n}=r,o=J();let p;e[0]!==l?(p=S=>{l(S.target.value)},e[0]=l,e[1]=p):p=e[1];const u=p;let s;e[2]!==o?(s=o("Storage tier"),e[2]=o,e[3]=s):s=e[3];let d;e[4]!==s?(d=v("span",{className:"font-mono text-[11px] tracking-wide uppercase text-muted-foreground",children:s}),e[4]=s,e[5]=d):d=e[5];const g=w[n];let c,i;e[6]===Symbol.for("react.memo_cache_sentinel")?(c=v("option",{value:"shard",children:w.shard.label}),i=v("option",{value:"global",children:w.global.label}),e[6]=c,e[7]=i):(c=e[6],i=e[7]);let h;e[8]!==u||e[9]!==g.title||e[10]!==n?(h=E("select",{className:"h-8 w-full rounded-md border border-border bg-background px-2 text-sm outline-none focus-visible:border-ring","data-testid":"table-editor-schema",id:"table-editor-schema",onChange:u,title:g.title,value:n,children:[c,i]}),e[8]=u,e[9]=g.title,e[10]=n,e[11]=h):h=e[11];let f;return e[12]!==d||e[13]!==h?(f=E("label",{className:"flex w-full flex-col gap-1",htmlFor:"table-editor-schema",children:[d,h]}),e[12]=d,e[13]=h,e[14]=f):f=e[14],f},Z=()=>{try{m(globalThis.navigator.clipboard.writeText(globalThis.location.href))}catch{}},ge=({canGenerateRows:r=!1,editable:e=!1,initialShardKey:l})=>{const n=F(),o=L(),p=M(),u=P({strict:!1}),s=K(u),d=q(u),g=()=>p.state.location.pathname.split("/").findLast(Boolean)==="data",c=s.tier??"shard",i=s.table,[h,f]=Q(()=>y()),[S,R]=Q(()=>new Set);A(()=>{m((async()=>{try{const a=await n.listGlobalTables();R(new Set(a.map(t=>t.name)))}catch{}})())},[n]),A(()=>{c==="shard"&&i!==void 0&&S.has(i)&&m(o({replace:!0,search:a=>({...a,schema:"global"}),to:"/data"}))},[S,o,i,c]);const C=a=>{m(o({search:t=>({...t,schema:a==="global"?"global":void 0,table:void 0}),to:"/data"}))},T=(a,t)=>{g()&&m(o({search:b=>({schema:b.schema,search:t?.search,shard:b.shard,table:a}),to:"/data"}))},G=a=>{m(o({search:t=>({...t,schema:"global",table:a}),to:"/data"}))},_=a=>{const t=D(a),{current:b}=d;(b.filters??void 0)===t.filters&&(b.order??void 0)===t.order&&(b.search??void 0)===t.search&&(b.shard??void 0)===t.shard||!g()||m(o({replace:!0,search:V=>({...V,filters:t.filters,order:t.order,search:t.search,shard:t.shard}),to:"/data"}))},j={onApplyQuery:a=>{const t=D(a.view);m(o({search:()=>({filters:t.filters,order:t.order,schema:t.schema,search:t.search,shard:t.shard,table:t.table}),to:"/data"}))},onCopyLink:Z,onDeleteQuery:a=>{f(U(a))},onSaveQuery:(a,t)=>{f(H(a,t))},saved:h},x=v(W,{onChange:C,tier:c});return c==="global"?v(Y,{initialTable:i,onSelectTable:T,schemaSwitch:x}):v(X,{canGenerateRows:r,editable:e,globalTableNames:S,initialFilters:s.filters,initialOrderBy:s.orderBy,initialPins:u.pins,initialSearch:s.search,initialShardKey:s.shard??l,onNavigateToGlobal:G,onSelectTable:T,onViewChange:_,queryBar:j,schemaSwitch:x,tableParam:i})};export{ge as TableEditor};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as J}from"react/compiler-runtime";import{useState as X,useEffect as fe,useRef as ue}from"react";import{A as ne}from"../packem_shared/alert-PB5W11MM.mjs";import{B as Y}from"../packem_shared/button-q0UYSmrn.mjs";import{b as he,c as ge,a as re,C as ae}from"../packem_shared/card--2hKx4L2.mjs";import{E as me}from"../packem_shared/empty-state-D7jEML_T.mjs";import{useT as te}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{u as be,n as ve}from"../packem_shared/browser-storage-BH1MxLZs.mjs";import{c as pe,d as xe,b as Ce,f as de,k as ke}from"../packem_shared/internal-Df43vQI0.mjs";import{u as ye}from"../packem_shared/use-sql-assistant-pjfGp-Ol.mjs";import{S as we,a as Se}from"../packem_shared/sql-result-table-DyK762_A.mjs";import{useLunora as Ne}from"@lunora/react";import{ADMIN_FUNCTIONS as Ke}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{jsx as d,jsxs as Z}from"react/jsx-runtime";const Re=pe(Ke.runSql),Le=(b,e)=>{const t=J(11),n=Ne(),[r,s]=X(void 0),[a,o]=X(void 0),[c,v]=X(!0);let h;t[0]!==n||t[1]!==e||t[2]!==b?(h=async f=>{v(!0);try{const y=await n.query(Re,{sql:b},xe(e));f.cancelled||(s(y),o(void 0))}catch(y){const x=y;f.cancelled||(s(void 0),o(Ce(x)))}f.cancelled||v(!1)},t[0]=n,t[1]=e,t[2]=b,t[3]=h):h=t[3];const i=h;let l,g;t[4]!==i?(l=()=>{const f={cancelled:!1};return de(i(f)),()=>{f.cancelled=!0}},g=[i],t[4]=i,t[5]=l,t[6]=g):(l=t[5],g=t[6]),fe(l,g);let N;return t[7]!==a||t[8]!==c||t[9]!==r?(N={error:a,loading:c,result:r},t[7]=a,t[8]=c,t[9]=r,t[10]=N):N=t[10],N},Me=b=>{b.preventDefault()},le=b=>b.kind??"chart",ce=b=>{const e=J(80),{actions:t,children:n,draggedRef:r,first:s,last:a,onEdit:o,onMove:c,onRemove:v,onReorder:h,widget:i}=b,l=te();let g;e[0]!==c||e[1]!==i.id?(g=()=>{c(i.id,-1)},e[0]=c,e[1]=i.id,e[2]=g):g=e[2];const N=g;let f;e[3]!==c||e[4]!==i.id?(f=()=>{c(i.id,1)},e[3]=c,e[4]=i.id,e[5]=f):f=e[5];const y=f;let x;e[6]!==o||e[7]!==i.id?(x=()=>{o(i.id)},e[6]=o,e[7]=i.id,e[8]=x):x=e[8];const q=x;let O;e[9]!==v||e[10]!==i.id?(O=()=>{v(i.id)},e[9]=v,e[10]=i.id,e[11]=O):O=e[11];const E=O;let z;e[12]!==r||e[13]!==i.id?(z=()=>{r.current=i.id},e[12]=r,e[13]=i.id,e[14]=z):z=e[14];const C=z;let K;e[15]!==r||e[16]!==h||e[17]!==i.id?(K=()=>{const se=r.current;r.current=null,se!==null&&se!==i.id&&h(se,i.id)},e[15]=r,e[16]=h,e[17]=i.id,e[18]=K):K=e[18];const W=K,S=`dashboards-widget-${i.id}`;let k;e[19]!==i.title?(k=d(he,{className:"min-w-0 cursor-grab truncate",title:i.title,children:i.title}),e[19]=i.title,e[20]=k):k=e[20];let w;e[21]!==l?(w=l("Move widget up"),e[21]=l,e[22]=w):w=e[22];const _=`dashboards-move-up-${i.id}`;let Q;e[23]!==l?(Q=l("Move widget up"),e[23]=l,e[24]=Q):Q=e[24];let B;e[25]===Symbol.for("react.memo_cache_sentinel")?(B=d("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:d("path",{d:"m6 15 6-6 6 6"})}),e[25]=B):B=e[25];let I;e[26]!==s||e[27]!==N||e[28]!==_||e[29]!==Q||e[30]!==w?(I=d(Y,{"aria-label":w,"data-testid":_,disabled:s,onClick:N,size:"icon-xs",title:Q,type:"button",variant:"ghost",children:B}),e[26]=s,e[27]=N,e[28]=_,e[29]=Q,e[30]=w,e[31]=I):I=e[31];let R;e[32]!==l?(R=l("Move widget down"),e[32]=l,e[33]=R):R=e[33];const $=`dashboards-move-down-${i.id}`;let L;e[34]!==l?(L=l("Move widget down"),e[34]=l,e[35]=L):L=e[35];let A;e[36]===Symbol.for("react.memo_cache_sentinel")?(A=d("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:d("path",{d:"m6 9 6 6 6-6"})}),e[36]=A):A=e[36];let M;e[37]!==a||e[38]!==y||e[39]!==R||e[40]!==$||e[41]!==L?(M=d(Y,{"aria-label":R,"data-testid":$,disabled:a,onClick:y,size:"icon-xs",title:L,type:"button",variant:"ghost",children:A}),e[37]=a,e[38]=y,e[39]=R,e[40]=$,e[41]=L,e[42]=M):M=e[42];let D;e[43]!==l?(D=l("Edit widget"),e[43]=l,e[44]=D):D=e[44];const j=`dashboards-widget-edit-${i.id}`;let T;e[45]!==l?(T=l("Edit widget"),e[45]=l,e[46]=T):T=e[46];let p;e[47]===Symbol.for("react.memo_cache_sentinel")?(p=d("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:d("path",{d:"M4 20h4L18 10l-4-4L4 16v4ZM14 6l4 4"})}),e[47]=p):p=e[47];let m;e[48]!==q||e[49]!==D||e[50]!==j||e[51]!==T?(m=d(Y,{"aria-label":D,"data-testid":j,onClick:q,size:"icon-xs",title:T,type:"button",variant:"ghost",children:p}),e[48]=q,e[49]=D,e[50]=j,e[51]=T,e[52]=m):m=e[52];let u;e[53]!==l?(u=l("Remove widget"),e[53]=l,e[54]=u):u=e[54];const F=`dashboards-widget-remove-${i.id}`;let U;e[55]!==l?(U=l("Remove widget"),e[55]=l,e[56]=U):U=e[56];let V;e[57]===Symbol.for("react.memo_cache_sentinel")?(V=d("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:d("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[57]=V):V=e[57];let H;e[58]!==E||e[59]!==u||e[60]!==F||e[61]!==U?(H=d(Y,{"aria-label":u,"data-testid":F,onClick:E,size:"icon-xs",title:U,type:"button",variant:"ghost",children:V}),e[58]=E,e[59]=u,e[60]=F,e[61]=U,e[62]=H):H=e[62];let P;e[63]!==t||e[64]!==I||e[65]!==M||e[66]!==m||e[67]!==H?(P=Z("div",{className:"flex shrink-0 items-center gap-1",children:[t,I,M,m,H]}),e[63]=t,e[64]=I,e[65]=M,e[66]=m,e[67]=H,e[68]=P):P=e[68];let G;e[69]!==P||e[70]!==k?(G=Z(ge,{className:"flex flex-row items-start justify-between gap-2 border-b pb-3",children:[k,P]}),e[69]=P,e[70]=k,e[71]=G):G=e[71];let ee;e[72]!==n?(ee=d(re,{className:"min-h-32 py-2",children:n}),e[72]=n,e[73]=ee):ee=e[73];let ie;return e[74]!==C||e[75]!==W||e[76]!==G||e[77]!==ee||e[78]!==S?(ie=Z(ae,{"data-testid":S,draggable:!0,onDragOver:Me,onDragStart:C,onDrop:W,children:[G,ee]}),e[74]=C,e[75]=W,e[76]=G,e[77]=ee,e[78]=S,e[79]=ie):ie=e[79],ie},qe=b=>{const e=J(10),{result:t}=b,n=te(),r=t.columns[0],s=r===void 0?void 0:t.rows[0]?.[r];let a;e[0]!==s||e[1]!==n?(a=s===void 0?n("—"):ke(s),e[0]=s,e[1]=n,e[2]=a):a=e[2];let o;e[3]!==a?(o=d("p",{className:"truncate font-mono text-3xl font-semibold text-foreground",children:a}),e[3]=a,e[4]=o):o=e[4];let c;e[5]!==r?(c=r!==void 0&&d("p",{className:"truncate text-xs text-muted-foreground",children:r}),e[5]=r,e[6]=c):c=e[6];let v;return e[7]!==o||e[8]!==c?(v=Z("div",{className:"flex h-full flex-col justify-center gap-1 p-4","data-testid":"dashboards-kpi",children:[o,c]}),e[7]=o,e[8]=c,e[9]=v):v=e[9],v},Ee=b=>{const e=J(12),{draggedRef:t,first:n,last:r,onEdit:s,onMove:a,onRemove:o,onReorder:c,widget:v}=b,h=v.text??"";let i;e[0]!==h?(i=d("p",{className:"p-2 text-sm whitespace-pre-wrap text-muted-foreground","data-testid":"dashboards-text",children:h}),e[0]=h,e[1]=i):i=e[1];let l;return e[2]!==t||e[3]!==n||e[4]!==r||e[5]!==s||e[6]!==a||e[7]!==o||e[8]!==c||e[9]!==i||e[10]!==v?(l=d(ce,{draggedRef:t,first:n,last:r,onEdit:s,onMove:a,onRemove:o,onReorder:c,widget:v,children:i}),e[2]=t,e[3]=n,e[4]=r,e[5]=s,e[6]=a,e[7]=o,e[8]=c,e[9]=i,e[10]=v,e[11]=l):l=e[11],l},Ae=b=>{const e=J(52),{draggedRef:t,first:n,inferring:r,last:s,onEdit:a,onMove:o,onRemove:c,onReorder:v,onSuggest:h,widget:i}=b,l=te(),{error:g,loading:N,result:f}=Le(i.sql,i.shardKey??"");let y;e[0]!==i?(y=le(i),e[0]=i,e[1]=y):y=e[1];const x=y;let q;e[2]!==h||e[3]!==f||e[4]!==i.id?(q=()=>{f!==void 0&&h?.(i.id,f)},e[2]=h,e[3]=f,e[4]=i.id,e[5]=q):q=e[5];const O=q;let E;e[6]!==r||e[7]!==x||e[8]!==h||e[9]!==O||e[10]!==f||e[11]!==l||e[12]!==i.id?(E=x==="chart"&&h!==void 0&&f!==void 0?d(Y,{"aria-label":l("Suggest chart"),"data-testid":`dashboards-widget-suggest-${i.id}`,disabled:r,onClick:O,size:"icon-xs",title:l(r?"Suggesting…":"Suggest chart"),type:"button",variant:"ghost",children:d("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:d("path",{d:"m12 3 1.9 4.6L18.5 9.5 13.9 11.4 12 16l-1.9-4.6L5.5 9.5l4.6-1.9L12 3ZM18 15l.9 2.1 2.1.9-2.1.9L18 21l-.9-2.1-2.1-.9 2.1-.9L18 15Z"})})}):void 0,e[6]=r,e[7]=x,e[8]=h,e[9]=O,e[10]=f,e[11]=l,e[12]=i.id,e[13]=E):E=e[13];const z=E;let C;e[14]!==g||e[15]!==i.id?(C=g!==void 0&&d(ne,{className:"font-mono text-xs",testId:`dashboards-widget-error-${i.id}`,variant:"destructive",children:g}),e[14]=g,e[15]=i.id,e[16]=C):C=e[16];let K;e[17]!==g||e[18]!==N||e[19]!==f||e[20]!==l||e[21]!==i.id?(K=g===void 0&&N&&f===void 0&&d("p",{className:"p-4 text-sm text-muted-foreground","data-testid":`dashboards-widget-loading-${i.id}`,children:l("Running…")}),e[17]=g,e[18]=N,e[19]=f,e[20]=l,e[21]=i.id,e[22]=K):K=e[22];let W;e[23]!==g||e[24]!==x||e[25]!==f||e[26]!==i.chartAxes||e[27]!==i.chartKind?(W=g===void 0&&f!==void 0&&x==="chart"&&d(we,{axes:i.chartAxes,kind:i.chartKind,result:f}),e[23]=g,e[24]=x,e[25]=f,e[26]=i.chartAxes,e[27]=i.chartKind,e[28]=W):W=e[28];let S;e[29]!==g||e[30]!==x||e[31]!==f?(S=g===void 0&&f!==void 0&&x==="kpi"&&d(qe,{result:f}),e[29]=g,e[30]=x,e[31]=f,e[32]=S):S=e[32];let k;e[33]!==g||e[34]!==x||e[35]!==f?(k=g===void 0&&f!==void 0&&x==="table"&&d("div",{className:"max-h-72 overflow-auto",children:d(Se,{result:f})}),e[33]=g,e[34]=x,e[35]=f,e[36]=k):k=e[36];let w;return e[37]!==t||e[38]!==n||e[39]!==s||e[40]!==a||e[41]!==o||e[42]!==c||e[43]!==v||e[44]!==z||e[45]!==C||e[46]!==K||e[47]!==W||e[48]!==S||e[49]!==k||e[50]!==i?(w=Z(ce,{actions:z,draggedRef:t,first:n,last:s,onEdit:a,onMove:o,onRemove:c,onReorder:v,widget:i,children:[C,K,W,S,k]}),e[37]=t,e[38]=n,e[39]=s,e[40]=a,e[41]=o,e[42]=c,e[43]=v,e[44]=z,e[45]=C,e[46]=K,e[47]=W,e[48]=S,e[49]=k,e[50]=i,e[51]=w):w=e[51],w},Te=b=>{const e=J(11),{draggedRef:t,first:n,inferring:r,last:s,onEdit:a,onMove:o,onRemove:c,onReorder:v,onSuggest:h,widget:i}=b;let l;return e[0]!==t||e[1]!==n||e[2]!==r||e[3]!==s||e[4]!==a||e[5]!==o||e[6]!==c||e[7]!==v||e[8]!==h||e[9]!==i?(l=le(i)==="text"?d(Ee,{draggedRef:t,first:n,last:s,onEdit:a,onMove:o,onRemove:c,onReorder:v,widget:i}):d(Ae,{draggedRef:t,first:n,inferring:r,last:s,onEdit:a,onMove:o,onRemove:c,onReorder:v,onSuggest:h,widget:i}),e[0]=t,e[1]=n,e[2]=r,e[3]=s,e[4]=a,e[5]=o,e[6]=c,e[7]=v,e[8]=h,e[9]=i,e[10]=l):l=e[10],l},We=["bar","line","area"],Ie=["chart","kpi","table","text"],$e="lunora-studio-dashboards",oe={chartKind:"bar",kind:"chart",shardKey:"",sql:"",text:"",title:""},De=(b,e)=>t=>t.map(n=>n.id===b?{...n,chartAxes:e,chartKind:e.kind}:n),je=(b,e)=>t=>{const n=t.find(a=>a.id===b),r=t.filter(a=>a.id!==b),s=r.findIndex(a=>a.id===e);return n===void 0||s===-1?t:[...r.slice(0,s),n,...r.slice(s)]},ze=(b,e)=>e(b==="line"?"Line":b==="area"?"Area":"Bar"),Be=(b,e)=>e(b==="kpi"?"Single value":b==="table"?"Table":b==="text"?"Text":"Chart"),Fe=b=>{const e=J(82),{draft:t,editing:n,onCancel:r,onChange:s,onSubmit:a}=b,o=te();let c;e[0]!==t||e[1]!==s?(c=u=>{s({...t,title:u.target.value})},e[0]=t,e[1]=s,e[2]=c):c=e[2];const v=c;let h;e[3]!==t||e[4]!==s?(h=u=>{s({...t,sql:u.target.value})},e[3]=t,e[4]=s,e[5]=h):h=e[5];const i=h;let l;e[6]!==t||e[7]!==s?(l=u=>{s({...t,text:u.target.value})},e[6]=t,e[7]=s,e[8]=l):l=e[8];const g=l;let N;e[9]!==t||e[10]!==s?(N=u=>{s({...t,shardKey:u.target.value})},e[9]=t,e[10]=s,e[11]=N):N=e[11];const f=N;let y;e[12]!==t||e[13]!==s?(y=u=>{s({...t,chartKind:u.target.value})},e[12]=t,e[13]=s,e[14]=y):y=e[14];const x=y;let q;e[15]!==t||e[16]!==s?(q=u=>{s({...t,kind:u.target.value})},e[15]=t,e[16]=s,e[17]=q):q=e[17];const O=q;let E;e[18]!==a?(E=()=>{a()},e[18]=a,e[19]=E):E=e[19];const z=E,C=t.kind==="text";let K;e[20]!==t.sql||e[21]!==t.text||e[22]!==t.title||e[23]!==C?(K=t.title.trim()!==""&&(C?t.text.trim()!=="":t.sql.trim()!==""),e[20]=t.sql,e[21]=t.text,e[22]=t.title,e[23]=C,e[24]=K):K=e[24];const W=K;let S;e[25]!==o?(S=o("Widget title"),e[25]=o,e[26]=S):S=e[26];let k;e[27]!==o?(k=o("Widget title"),e[27]=o,e[28]=k):k=e[28];let w;e[29]!==t.title||e[30]!==v||e[31]!==k||e[32]!==S?(w=d("input",{"aria-label":S,className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-title",onChange:v,placeholder:k,type:"text",value:t.title}),e[29]=t.title,e[30]=v,e[31]=k,e[32]=S,e[33]=w):w=e[33];let _;e[34]!==o?(_=o("Widget type"),e[34]=o,e[35]=_):_=e[35];const Q=t.kind;let B;e[36]!==o?(B=Ie.map(u=>d("option",{value:u,children:Be(u,o)},u)),e[36]=o,e[37]=B):B=e[37];let I;e[38]!==t.kind||e[39]!==O||e[40]!==_||e[41]!==B?(I=d("select",{"aria-label":_,className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-widget-kind",onChange:O,value:Q,children:B}),e[38]=t.kind,e[39]=O,e[40]=_,e[41]=B,e[42]=I):I=e[42];let R;e[43]!==t.sql||e[44]!==t.text||e[45]!==C||e[46]!==i||e[47]!==g||e[48]!==o?(R=C?d("textarea",{"aria-label":o("Text"),className:"min-h-24 resize-y rounded-md border border-border bg-background p-2 text-xs leading-5 outline-none focus-visible:border-ring","data-testid":"dashboards-form-text",onChange:g,placeholder:o("Notes for whoever reads this dashboard."),value:t.text}):d("textarea",{"aria-label":o("SQL query"),className:"min-h-24 resize-y rounded-md border border-border bg-background p-2 font-mono text-xs leading-5 outline-none focus-visible:border-ring","data-testid":"dashboards-form-sql",onChange:i,placeholder:"SELECT author, COUNT(*) AS messages FROM …",spellCheck:!1,value:t.sql}),e[43]=t.sql,e[44]=t.text,e[45]=C,e[46]=i,e[47]=g,e[48]=o,e[49]=R):R=e[49];let $;e[50]!==t.chartKind||e[51]!==t.kind||e[52]!==x||e[53]!==o?($=t.kind==="chart"&&d("select",{"aria-label":o("Chart type"),className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-kind",onChange:x,value:t.chartKind,children:We.map(u=>d("option",{value:u,children:ze(u,o)},u))}),e[50]=t.chartKind,e[51]=t.kind,e[52]=x,e[53]=o,e[54]=$):$=e[54];let L;e[55]!==t.shardKey||e[56]!==C||e[57]!==f||e[58]!==o?(L=!C&&d("input",{"aria-label":o("Shard key (optional)"),className:"h-8 rounded-md border border-border bg-background px-2 font-mono text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-shard",onChange:f,placeholder:o("Shard key (optional)"),type:"text",value:t.shardKey}),e[55]=t.shardKey,e[56]=C,e[57]=f,e[58]=o,e[59]=L):L=e[59];let A;e[60]!==o?(A=o("Cancel"),e[60]=o,e[61]=A):A=e[61];let M;e[62]!==r||e[63]!==A?(M=d(Y,{"data-testid":"dashboards-form-cancel",onClick:r,size:"sm",type:"button",variant:"outline",children:A}),e[62]=r,e[63]=A,e[64]=M):M=e[64];const D=!W;let j;e[65]!==n||e[66]!==o?(j=o(n?"Save widget":"Add widget"),e[65]=n,e[66]=o,e[67]=j):j=e[67];let T;e[68]!==z||e[69]!==D||e[70]!==j?(T=d(Y,{"data-testid":"dashboards-form-save",disabled:D,onClick:z,size:"sm",type:"button",children:j}),e[68]=z,e[69]=D,e[70]=j,e[71]=T):T=e[71];let p;e[72]!==M||e[73]!==T?(p=Z("div",{className:"flex items-center justify-end gap-2",children:[M,T]}),e[72]=M,e[73]=T,e[74]=p):p=e[74];let m;return e[75]!==w||e[76]!==I||e[77]!==R||e[78]!==$||e[79]!==L||e[80]!==p?(m=d(ae,{"data-testid":"dashboards-form",children:Z(re,{className:"flex flex-col gap-3 py-4",children:[w,I,R,$,L,p]})}),e[75]=w,e[76]=I,e[77]=R,e[78]=$,e[79]=L,e[80]=p,e[81]=m):m=e[81],m},it=b=>{const e=J(53),{initialShardKey:t}=b,n=te(),[r,s]=be($e),[a,o]=X(oe),[c,v]=X(null),[h,i]=X(!1),l=ye(t??""),[g,N]=X(null),f=ue(null);let y;e[0]!==t?(y=()=>{v(null),o({...oe,shardKey:t??""}),i(!0)},e[0]=t,e[1]=y):y=e[1];const x=y;let q;e[2]===Symbol.for("react.memo_cache_sentinel")?(q=()=>{i(!1),v(null),o(oe)},e[2]=q):q=e[2];const O=q;let E;e[3]!==r?(E=p=>{const m=r.find(u=>u.id===p);m!==void 0&&(v(p),o({chartKind:m.chartKind??"bar",kind:le(m),shardKey:m.shardKey??"",sql:m.sql,text:m.text??"",title:m.title}),i(!0))},e[3]=r,e[4]=E):E=e[4];const z=E;let C;e[5]!==l||e[6]!==s?(C=(p,m)=>{N(p),de((async()=>{const F=await l.inferChart({columns:m.columns,rowCount:m.rowCount});F!==void 0&&s(De(p,F))})().finally(()=>{N(F=>F===p?null:F)}))},e[5]=l,e[6]=s,e[7]=C):C=e[7];const K=C;let W;e[8]!==s?(W=p=>{s(m=>m.filter(u=>u.id!==p))},e[8]=s,e[9]=W):W=e[9];const S=W;let k;e[10]!==s?(k=(p,m)=>{s(je(p,m))},e[10]=s,e[11]=k):k=e[11];const w=k;let _;e[12]!==s?(_=(p,m)=>{s(u=>{const F=u.findIndex(G=>G.id===p),U=F+m;if(F===-1||U<0||U>=u.length)return u;const V=[...u],H=V[F],P=V[U];return H===void 0||P===void 0?u:(V[F]=P,V[U]=H,V)})},e[12]=s,e[13]=_):_=e[13];const Q=_;let B;e[14]!==a||e[15]!==c||e[16]!==s?(B=()=>{const p=a.title.trim(),m=a.sql.trim(),u=a.text.trim(),{chartKind:F,kind:U}=a;if(p===""||(U==="text"?u==="":m===""))return;const V={chartKind:F,kind:U,shardKey:a.shardKey.trim(),sql:m,text:u,title:p};s(c===null?H=>[...H,{...V,id:ve("w")}]:H=>H.map(P=>P.id===c?{...P,...V}:P)),O()},e[14]=a,e[15]=c,e[16]=s,e[17]=B):B=e[17];const I=B;let R;e[18]!==n?(R=n("Charts, values, tables, and notes. Drag a tile to reorder."),e[18]=n,e[19]=R):R=e[19];let $;e[20]!==R?($=d("p",{className:"text-sm text-muted-foreground",children:R}),e[20]=R,e[21]=$):$=e[21];let L;e[22]!==h||e[23]!==x||e[24]!==n?(L=!h&&d(Y,{"data-testid":"dashboards-add",onClick:x,size:"sm",type:"button",children:n("Add widget")}),e[22]=h,e[23]=x,e[24]=n,e[25]=L):L=e[25];let A;e[26]!==$||e[27]!==L?(A=Z("div",{className:"flex items-center justify-between",children:[$,L]}),e[26]=$,e[27]=L,e[28]=A):A=e[28];let M;e[29]!==l||e[30]!==n?(M=l.reason("chart")!==void 0&&d(ne,{className:"text-xs",testId:"dashboards-suggest-error",variant:"destructive",children:n("Could not suggest a chart for that result.")}),e[29]=l,e[30]=n,e[31]=M):M=e[31];let D;e[32]!==a||e[33]!==c||e[34]!==h||e[35]!==I?(D=h&&d(Fe,{draft:a,editing:c!==null,onCancel:O,onChange:o,onSubmit:I}),e[32]=a,e[33]=c,e[34]=h,e[35]=I,e[36]=D):D=e[36];let j;e[37]!==l.unavailable||e[38]!==h||e[39]!==g||e[40]!==z||e[41]!==Q||e[42]!==S||e[43]!==w||e[44]!==K||e[45]!==n||e[46]!==r?(j=r.length===0&&!h?d(me,{description:n("Add a chart, a single value, a table, or a note. Everything is saved on this browser."),testId:"dashboards-empty",title:n("No widgets yet")}):d("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3","data-testid":"dashboards-grid",children:r.map((p,m)=>d(Te,{draggedRef:f,first:m===0,inferring:g===p.id,last:m===r.length-1,onEdit:z,onMove:Q,onRemove:S,onReorder:w,onSuggest:l.unavailable?void 0:K,widget:p},p.id))}),e[37]=l.unavailable,e[38]=h,e[39]=g,e[40]=z,e[41]=Q,e[42]=S,e[43]=w,e[44]=K,e[45]=n,e[46]=r,e[47]=j):j=e[47];let T;return e[48]!==A||e[49]!==M||e[50]!==D||e[51]!==j?(T=Z("div",{className:"flex flex-col gap-4","data-testid":"lunora-dashboards",children:[A,M,D,j]}),e[48]=A,e[49]=M,e[50]=D,e[51]=j,e[52]=T):T=e[52],T};export{it as default};
|
|
1
|
+
import{c as J}from"react/compiler-runtime";import{useState as X,useEffect as fe,useRef as ue}from"react";import{A as ne}from"../packem_shared/alert-PB5W11MM.mjs";import{B as Y}from"../packem_shared/button-q0UYSmrn.mjs";import{b as he,c as ge,a as re,C as ae}from"../packem_shared/card--2hKx4L2.mjs";import{E as me}from"../packem_shared/empty-state-D7jEML_T.mjs";import{useT as te}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{u as be,n as ve}from"../packem_shared/browser-storage-BH1MxLZs.mjs";import{c as pe,d as xe,b as Ce,f as de,k as ke}from"../packem_shared/internal-Df43vQI0.mjs";import{u as ye}from"../packem_shared/use-sql-assistant-CZydTzd5.mjs";import{S as we,a as Se}from"../packem_shared/sql-result-table-DyK762_A.mjs";import{useLunora as Ne}from"@lunora/react";import{ADMIN_FUNCTIONS as Ke}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{jsx as d,jsxs as Z}from"react/jsx-runtime";const Re=pe(Ke.runSql),Le=(b,e)=>{const t=J(11),n=Ne(),[r,s]=X(void 0),[a,o]=X(void 0),[c,v]=X(!0);let h;t[0]!==n||t[1]!==e||t[2]!==b?(h=async f=>{v(!0);try{const y=await n.query(Re,{sql:b},xe(e));f.cancelled||(s(y),o(void 0))}catch(y){const x=y;f.cancelled||(s(void 0),o(Ce(x)))}f.cancelled||v(!1)},t[0]=n,t[1]=e,t[2]=b,t[3]=h):h=t[3];const i=h;let l,g;t[4]!==i?(l=()=>{const f={cancelled:!1};return de(i(f)),()=>{f.cancelled=!0}},g=[i],t[4]=i,t[5]=l,t[6]=g):(l=t[5],g=t[6]),fe(l,g);let N;return t[7]!==a||t[8]!==c||t[9]!==r?(N={error:a,loading:c,result:r},t[7]=a,t[8]=c,t[9]=r,t[10]=N):N=t[10],N},Me=b=>{b.preventDefault()},le=b=>b.kind??"chart",ce=b=>{const e=J(80),{actions:t,children:n,draggedRef:r,first:s,last:a,onEdit:o,onMove:c,onRemove:v,onReorder:h,widget:i}=b,l=te();let g;e[0]!==c||e[1]!==i.id?(g=()=>{c(i.id,-1)},e[0]=c,e[1]=i.id,e[2]=g):g=e[2];const N=g;let f;e[3]!==c||e[4]!==i.id?(f=()=>{c(i.id,1)},e[3]=c,e[4]=i.id,e[5]=f):f=e[5];const y=f;let x;e[6]!==o||e[7]!==i.id?(x=()=>{o(i.id)},e[6]=o,e[7]=i.id,e[8]=x):x=e[8];const q=x;let O;e[9]!==v||e[10]!==i.id?(O=()=>{v(i.id)},e[9]=v,e[10]=i.id,e[11]=O):O=e[11];const E=O;let z;e[12]!==r||e[13]!==i.id?(z=()=>{r.current=i.id},e[12]=r,e[13]=i.id,e[14]=z):z=e[14];const C=z;let K;e[15]!==r||e[16]!==h||e[17]!==i.id?(K=()=>{const se=r.current;r.current=null,se!==null&&se!==i.id&&h(se,i.id)},e[15]=r,e[16]=h,e[17]=i.id,e[18]=K):K=e[18];const W=K,S=`dashboards-widget-${i.id}`;let k;e[19]!==i.title?(k=d(he,{className:"min-w-0 cursor-grab truncate",title:i.title,children:i.title}),e[19]=i.title,e[20]=k):k=e[20];let w;e[21]!==l?(w=l("Move widget up"),e[21]=l,e[22]=w):w=e[22];const _=`dashboards-move-up-${i.id}`;let Q;e[23]!==l?(Q=l("Move widget up"),e[23]=l,e[24]=Q):Q=e[24];let B;e[25]===Symbol.for("react.memo_cache_sentinel")?(B=d("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:d("path",{d:"m6 15 6-6 6 6"})}),e[25]=B):B=e[25];let I;e[26]!==s||e[27]!==N||e[28]!==_||e[29]!==Q||e[30]!==w?(I=d(Y,{"aria-label":w,"data-testid":_,disabled:s,onClick:N,size:"icon-xs",title:Q,type:"button",variant:"ghost",children:B}),e[26]=s,e[27]=N,e[28]=_,e[29]=Q,e[30]=w,e[31]=I):I=e[31];let R;e[32]!==l?(R=l("Move widget down"),e[32]=l,e[33]=R):R=e[33];const $=`dashboards-move-down-${i.id}`;let L;e[34]!==l?(L=l("Move widget down"),e[34]=l,e[35]=L):L=e[35];let A;e[36]===Symbol.for("react.memo_cache_sentinel")?(A=d("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:d("path",{d:"m6 9 6 6 6-6"})}),e[36]=A):A=e[36];let M;e[37]!==a||e[38]!==y||e[39]!==R||e[40]!==$||e[41]!==L?(M=d(Y,{"aria-label":R,"data-testid":$,disabled:a,onClick:y,size:"icon-xs",title:L,type:"button",variant:"ghost",children:A}),e[37]=a,e[38]=y,e[39]=R,e[40]=$,e[41]=L,e[42]=M):M=e[42];let D;e[43]!==l?(D=l("Edit widget"),e[43]=l,e[44]=D):D=e[44];const j=`dashboards-widget-edit-${i.id}`;let T;e[45]!==l?(T=l("Edit widget"),e[45]=l,e[46]=T):T=e[46];let p;e[47]===Symbol.for("react.memo_cache_sentinel")?(p=d("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:d("path",{d:"M4 20h4L18 10l-4-4L4 16v4ZM14 6l4 4"})}),e[47]=p):p=e[47];let m;e[48]!==q||e[49]!==D||e[50]!==j||e[51]!==T?(m=d(Y,{"aria-label":D,"data-testid":j,onClick:q,size:"icon-xs",title:T,type:"button",variant:"ghost",children:p}),e[48]=q,e[49]=D,e[50]=j,e[51]=T,e[52]=m):m=e[52];let u;e[53]!==l?(u=l("Remove widget"),e[53]=l,e[54]=u):u=e[54];const F=`dashboards-widget-remove-${i.id}`;let U;e[55]!==l?(U=l("Remove widget"),e[55]=l,e[56]=U):U=e[56];let V;e[57]===Symbol.for("react.memo_cache_sentinel")?(V=d("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:d("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[57]=V):V=e[57];let H;e[58]!==E||e[59]!==u||e[60]!==F||e[61]!==U?(H=d(Y,{"aria-label":u,"data-testid":F,onClick:E,size:"icon-xs",title:U,type:"button",variant:"ghost",children:V}),e[58]=E,e[59]=u,e[60]=F,e[61]=U,e[62]=H):H=e[62];let P;e[63]!==t||e[64]!==I||e[65]!==M||e[66]!==m||e[67]!==H?(P=Z("div",{className:"flex shrink-0 items-center gap-1",children:[t,I,M,m,H]}),e[63]=t,e[64]=I,e[65]=M,e[66]=m,e[67]=H,e[68]=P):P=e[68];let G;e[69]!==P||e[70]!==k?(G=Z(ge,{className:"flex flex-row items-start justify-between gap-2 border-b pb-3",children:[k,P]}),e[69]=P,e[70]=k,e[71]=G):G=e[71];let ee;e[72]!==n?(ee=d(re,{className:"min-h-32 py-2",children:n}),e[72]=n,e[73]=ee):ee=e[73];let ie;return e[74]!==C||e[75]!==W||e[76]!==G||e[77]!==ee||e[78]!==S?(ie=Z(ae,{"data-testid":S,draggable:!0,onDragOver:Me,onDragStart:C,onDrop:W,children:[G,ee]}),e[74]=C,e[75]=W,e[76]=G,e[77]=ee,e[78]=S,e[79]=ie):ie=e[79],ie},qe=b=>{const e=J(10),{result:t}=b,n=te(),r=t.columns[0],s=r===void 0?void 0:t.rows[0]?.[r];let a;e[0]!==s||e[1]!==n?(a=s===void 0?n("—"):ke(s),e[0]=s,e[1]=n,e[2]=a):a=e[2];let o;e[3]!==a?(o=d("p",{className:"truncate font-mono text-3xl font-semibold text-foreground",children:a}),e[3]=a,e[4]=o):o=e[4];let c;e[5]!==r?(c=r!==void 0&&d("p",{className:"truncate text-xs text-muted-foreground",children:r}),e[5]=r,e[6]=c):c=e[6];let v;return e[7]!==o||e[8]!==c?(v=Z("div",{className:"flex h-full flex-col justify-center gap-1 p-4","data-testid":"dashboards-kpi",children:[o,c]}),e[7]=o,e[8]=c,e[9]=v):v=e[9],v},Ee=b=>{const e=J(12),{draggedRef:t,first:n,last:r,onEdit:s,onMove:a,onRemove:o,onReorder:c,widget:v}=b,h=v.text??"";let i;e[0]!==h?(i=d("p",{className:"p-2 text-sm whitespace-pre-wrap text-muted-foreground","data-testid":"dashboards-text",children:h}),e[0]=h,e[1]=i):i=e[1];let l;return e[2]!==t||e[3]!==n||e[4]!==r||e[5]!==s||e[6]!==a||e[7]!==o||e[8]!==c||e[9]!==i||e[10]!==v?(l=d(ce,{draggedRef:t,first:n,last:r,onEdit:s,onMove:a,onRemove:o,onReorder:c,widget:v,children:i}),e[2]=t,e[3]=n,e[4]=r,e[5]=s,e[6]=a,e[7]=o,e[8]=c,e[9]=i,e[10]=v,e[11]=l):l=e[11],l},Ae=b=>{const e=J(52),{draggedRef:t,first:n,inferring:r,last:s,onEdit:a,onMove:o,onRemove:c,onReorder:v,onSuggest:h,widget:i}=b,l=te(),{error:g,loading:N,result:f}=Le(i.sql,i.shardKey??"");let y;e[0]!==i?(y=le(i),e[0]=i,e[1]=y):y=e[1];const x=y;let q;e[2]!==h||e[3]!==f||e[4]!==i.id?(q=()=>{f!==void 0&&h?.(i.id,f)},e[2]=h,e[3]=f,e[4]=i.id,e[5]=q):q=e[5];const O=q;let E;e[6]!==r||e[7]!==x||e[8]!==h||e[9]!==O||e[10]!==f||e[11]!==l||e[12]!==i.id?(E=x==="chart"&&h!==void 0&&f!==void 0?d(Y,{"aria-label":l("Suggest chart"),"data-testid":`dashboards-widget-suggest-${i.id}`,disabled:r,onClick:O,size:"icon-xs",title:l(r?"Suggesting…":"Suggest chart"),type:"button",variant:"ghost",children:d("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:d("path",{d:"m12 3 1.9 4.6L18.5 9.5 13.9 11.4 12 16l-1.9-4.6L5.5 9.5l4.6-1.9L12 3ZM18 15l.9 2.1 2.1.9-2.1.9L18 21l-.9-2.1-2.1-.9 2.1-.9L18 15Z"})})}):void 0,e[6]=r,e[7]=x,e[8]=h,e[9]=O,e[10]=f,e[11]=l,e[12]=i.id,e[13]=E):E=e[13];const z=E;let C;e[14]!==g||e[15]!==i.id?(C=g!==void 0&&d(ne,{className:"font-mono text-xs",testId:`dashboards-widget-error-${i.id}`,variant:"destructive",children:g}),e[14]=g,e[15]=i.id,e[16]=C):C=e[16];let K;e[17]!==g||e[18]!==N||e[19]!==f||e[20]!==l||e[21]!==i.id?(K=g===void 0&&N&&f===void 0&&d("p",{className:"p-4 text-sm text-muted-foreground","data-testid":`dashboards-widget-loading-${i.id}`,children:l("Running…")}),e[17]=g,e[18]=N,e[19]=f,e[20]=l,e[21]=i.id,e[22]=K):K=e[22];let W;e[23]!==g||e[24]!==x||e[25]!==f||e[26]!==i.chartAxes||e[27]!==i.chartKind?(W=g===void 0&&f!==void 0&&x==="chart"&&d(we,{axes:i.chartAxes,kind:i.chartKind,result:f}),e[23]=g,e[24]=x,e[25]=f,e[26]=i.chartAxes,e[27]=i.chartKind,e[28]=W):W=e[28];let S;e[29]!==g||e[30]!==x||e[31]!==f?(S=g===void 0&&f!==void 0&&x==="kpi"&&d(qe,{result:f}),e[29]=g,e[30]=x,e[31]=f,e[32]=S):S=e[32];let k;e[33]!==g||e[34]!==x||e[35]!==f?(k=g===void 0&&f!==void 0&&x==="table"&&d("div",{className:"max-h-72 overflow-auto",children:d(Se,{result:f})}),e[33]=g,e[34]=x,e[35]=f,e[36]=k):k=e[36];let w;return e[37]!==t||e[38]!==n||e[39]!==s||e[40]!==a||e[41]!==o||e[42]!==c||e[43]!==v||e[44]!==z||e[45]!==C||e[46]!==K||e[47]!==W||e[48]!==S||e[49]!==k||e[50]!==i?(w=Z(ce,{actions:z,draggedRef:t,first:n,last:s,onEdit:a,onMove:o,onRemove:c,onReorder:v,widget:i,children:[C,K,W,S,k]}),e[37]=t,e[38]=n,e[39]=s,e[40]=a,e[41]=o,e[42]=c,e[43]=v,e[44]=z,e[45]=C,e[46]=K,e[47]=W,e[48]=S,e[49]=k,e[50]=i,e[51]=w):w=e[51],w},Te=b=>{const e=J(11),{draggedRef:t,first:n,inferring:r,last:s,onEdit:a,onMove:o,onRemove:c,onReorder:v,onSuggest:h,widget:i}=b;let l;return e[0]!==t||e[1]!==n||e[2]!==r||e[3]!==s||e[4]!==a||e[5]!==o||e[6]!==c||e[7]!==v||e[8]!==h||e[9]!==i?(l=le(i)==="text"?d(Ee,{draggedRef:t,first:n,last:s,onEdit:a,onMove:o,onRemove:c,onReorder:v,widget:i}):d(Ae,{draggedRef:t,first:n,inferring:r,last:s,onEdit:a,onMove:o,onRemove:c,onReorder:v,onSuggest:h,widget:i}),e[0]=t,e[1]=n,e[2]=r,e[3]=s,e[4]=a,e[5]=o,e[6]=c,e[7]=v,e[8]=h,e[9]=i,e[10]=l):l=e[10],l},We=["bar","line","area"],Ie=["chart","kpi","table","text"],$e="lunora-studio-dashboards",oe={chartKind:"bar",kind:"chart",shardKey:"",sql:"",text:"",title:""},De=(b,e)=>t=>t.map(n=>n.id===b?{...n,chartAxes:e,chartKind:e.kind}:n),je=(b,e)=>t=>{const n=t.find(a=>a.id===b),r=t.filter(a=>a.id!==b),s=r.findIndex(a=>a.id===e);return n===void 0||s===-1?t:[...r.slice(0,s),n,...r.slice(s)]},ze=(b,e)=>e(b==="line"?"Line":b==="area"?"Area":"Bar"),Be=(b,e)=>e(b==="kpi"?"Single value":b==="table"?"Table":b==="text"?"Text":"Chart"),Fe=b=>{const e=J(82),{draft:t,editing:n,onCancel:r,onChange:s,onSubmit:a}=b,o=te();let c;e[0]!==t||e[1]!==s?(c=u=>{s({...t,title:u.target.value})},e[0]=t,e[1]=s,e[2]=c):c=e[2];const v=c;let h;e[3]!==t||e[4]!==s?(h=u=>{s({...t,sql:u.target.value})},e[3]=t,e[4]=s,e[5]=h):h=e[5];const i=h;let l;e[6]!==t||e[7]!==s?(l=u=>{s({...t,text:u.target.value})},e[6]=t,e[7]=s,e[8]=l):l=e[8];const g=l;let N;e[9]!==t||e[10]!==s?(N=u=>{s({...t,shardKey:u.target.value})},e[9]=t,e[10]=s,e[11]=N):N=e[11];const f=N;let y;e[12]!==t||e[13]!==s?(y=u=>{s({...t,chartKind:u.target.value})},e[12]=t,e[13]=s,e[14]=y):y=e[14];const x=y;let q;e[15]!==t||e[16]!==s?(q=u=>{s({...t,kind:u.target.value})},e[15]=t,e[16]=s,e[17]=q):q=e[17];const O=q;let E;e[18]!==a?(E=()=>{a()},e[18]=a,e[19]=E):E=e[19];const z=E,C=t.kind==="text";let K;e[20]!==t.sql||e[21]!==t.text||e[22]!==t.title||e[23]!==C?(K=t.title.trim()!==""&&(C?t.text.trim()!=="":t.sql.trim()!==""),e[20]=t.sql,e[21]=t.text,e[22]=t.title,e[23]=C,e[24]=K):K=e[24];const W=K;let S;e[25]!==o?(S=o("Widget title"),e[25]=o,e[26]=S):S=e[26];let k;e[27]!==o?(k=o("Widget title"),e[27]=o,e[28]=k):k=e[28];let w;e[29]!==t.title||e[30]!==v||e[31]!==k||e[32]!==S?(w=d("input",{"aria-label":S,className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-title",onChange:v,placeholder:k,type:"text",value:t.title}),e[29]=t.title,e[30]=v,e[31]=k,e[32]=S,e[33]=w):w=e[33];let _;e[34]!==o?(_=o("Widget type"),e[34]=o,e[35]=_):_=e[35];const Q=t.kind;let B;e[36]!==o?(B=Ie.map(u=>d("option",{value:u,children:Be(u,o)},u)),e[36]=o,e[37]=B):B=e[37];let I;e[38]!==t.kind||e[39]!==O||e[40]!==_||e[41]!==B?(I=d("select",{"aria-label":_,className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-widget-kind",onChange:O,value:Q,children:B}),e[38]=t.kind,e[39]=O,e[40]=_,e[41]=B,e[42]=I):I=e[42];let R;e[43]!==t.sql||e[44]!==t.text||e[45]!==C||e[46]!==i||e[47]!==g||e[48]!==o?(R=C?d("textarea",{"aria-label":o("Text"),className:"min-h-24 resize-y rounded-md border border-border bg-background p-2 text-xs leading-5 outline-none focus-visible:border-ring","data-testid":"dashboards-form-text",onChange:g,placeholder:o("Notes for whoever reads this dashboard."),value:t.text}):d("textarea",{"aria-label":o("SQL query"),className:"min-h-24 resize-y rounded-md border border-border bg-background p-2 font-mono text-xs leading-5 outline-none focus-visible:border-ring","data-testid":"dashboards-form-sql",onChange:i,placeholder:"SELECT author, COUNT(*) AS messages FROM …",spellCheck:!1,value:t.sql}),e[43]=t.sql,e[44]=t.text,e[45]=C,e[46]=i,e[47]=g,e[48]=o,e[49]=R):R=e[49];let $;e[50]!==t.chartKind||e[51]!==t.kind||e[52]!==x||e[53]!==o?($=t.kind==="chart"&&d("select",{"aria-label":o("Chart type"),className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-kind",onChange:x,value:t.chartKind,children:We.map(u=>d("option",{value:u,children:ze(u,o)},u))}),e[50]=t.chartKind,e[51]=t.kind,e[52]=x,e[53]=o,e[54]=$):$=e[54];let L;e[55]!==t.shardKey||e[56]!==C||e[57]!==f||e[58]!==o?(L=!C&&d("input",{"aria-label":o("Shard key (optional)"),className:"h-8 rounded-md border border-border bg-background px-2 font-mono text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-shard",onChange:f,placeholder:o("Shard key (optional)"),type:"text",value:t.shardKey}),e[55]=t.shardKey,e[56]=C,e[57]=f,e[58]=o,e[59]=L):L=e[59];let A;e[60]!==o?(A=o("Cancel"),e[60]=o,e[61]=A):A=e[61];let M;e[62]!==r||e[63]!==A?(M=d(Y,{"data-testid":"dashboards-form-cancel",onClick:r,size:"sm",type:"button",variant:"outline",children:A}),e[62]=r,e[63]=A,e[64]=M):M=e[64];const D=!W;let j;e[65]!==n||e[66]!==o?(j=o(n?"Save widget":"Add widget"),e[65]=n,e[66]=o,e[67]=j):j=e[67];let T;e[68]!==z||e[69]!==D||e[70]!==j?(T=d(Y,{"data-testid":"dashboards-form-save",disabled:D,onClick:z,size:"sm",type:"button",children:j}),e[68]=z,e[69]=D,e[70]=j,e[71]=T):T=e[71];let p;e[72]!==M||e[73]!==T?(p=Z("div",{className:"flex items-center justify-end gap-2",children:[M,T]}),e[72]=M,e[73]=T,e[74]=p):p=e[74];let m;return e[75]!==w||e[76]!==I||e[77]!==R||e[78]!==$||e[79]!==L||e[80]!==p?(m=d(ae,{"data-testid":"dashboards-form",children:Z(re,{className:"flex flex-col gap-3 py-4",children:[w,I,R,$,L,p]})}),e[75]=w,e[76]=I,e[77]=R,e[78]=$,e[79]=L,e[80]=p,e[81]=m):m=e[81],m},it=b=>{const e=J(53),{initialShardKey:t}=b,n=te(),[r,s]=be($e),[a,o]=X(oe),[c,v]=X(null),[h,i]=X(!1),l=ye(t??""),[g,N]=X(null),f=ue(null);let y;e[0]!==t?(y=()=>{v(null),o({...oe,shardKey:t??""}),i(!0)},e[0]=t,e[1]=y):y=e[1];const x=y;let q;e[2]===Symbol.for("react.memo_cache_sentinel")?(q=()=>{i(!1),v(null),o(oe)},e[2]=q):q=e[2];const O=q;let E;e[3]!==r?(E=p=>{const m=r.find(u=>u.id===p);m!==void 0&&(v(p),o({chartKind:m.chartKind??"bar",kind:le(m),shardKey:m.shardKey??"",sql:m.sql,text:m.text??"",title:m.title}),i(!0))},e[3]=r,e[4]=E):E=e[4];const z=E;let C;e[5]!==l||e[6]!==s?(C=(p,m)=>{N(p),de((async()=>{const F=await l.inferChart({columns:m.columns,rowCount:m.rowCount});F!==void 0&&s(De(p,F))})().finally(()=>{N(F=>F===p?null:F)}))},e[5]=l,e[6]=s,e[7]=C):C=e[7];const K=C;let W;e[8]!==s?(W=p=>{s(m=>m.filter(u=>u.id!==p))},e[8]=s,e[9]=W):W=e[9];const S=W;let k;e[10]!==s?(k=(p,m)=>{s(je(p,m))},e[10]=s,e[11]=k):k=e[11];const w=k;let _;e[12]!==s?(_=(p,m)=>{s(u=>{const F=u.findIndex(G=>G.id===p),U=F+m;if(F===-1||U<0||U>=u.length)return u;const V=[...u],H=V[F],P=V[U];return H===void 0||P===void 0?u:(V[F]=P,V[U]=H,V)})},e[12]=s,e[13]=_):_=e[13];const Q=_;let B;e[14]!==a||e[15]!==c||e[16]!==s?(B=()=>{const p=a.title.trim(),m=a.sql.trim(),u=a.text.trim(),{chartKind:F,kind:U}=a;if(p===""||(U==="text"?u==="":m===""))return;const V={chartKind:F,kind:U,shardKey:a.shardKey.trim(),sql:m,text:u,title:p};s(c===null?H=>[...H,{...V,id:ve("w")}]:H=>H.map(P=>P.id===c?{...P,...V}:P)),O()},e[14]=a,e[15]=c,e[16]=s,e[17]=B):B=e[17];const I=B;let R;e[18]!==n?(R=n("Charts, values, tables, and notes. Drag a tile to reorder."),e[18]=n,e[19]=R):R=e[19];let $;e[20]!==R?($=d("p",{className:"text-sm text-muted-foreground",children:R}),e[20]=R,e[21]=$):$=e[21];let L;e[22]!==h||e[23]!==x||e[24]!==n?(L=!h&&d(Y,{"data-testid":"dashboards-add",onClick:x,size:"sm",type:"button",children:n("Add widget")}),e[22]=h,e[23]=x,e[24]=n,e[25]=L):L=e[25];let A;e[26]!==$||e[27]!==L?(A=Z("div",{className:"flex items-center justify-between",children:[$,L]}),e[26]=$,e[27]=L,e[28]=A):A=e[28];let M;e[29]!==l||e[30]!==n?(M=l.reason("chart")!==void 0&&d(ne,{className:"text-xs",testId:"dashboards-suggest-error",variant:"destructive",children:n("Could not suggest a chart for that result.")}),e[29]=l,e[30]=n,e[31]=M):M=e[31];let D;e[32]!==a||e[33]!==c||e[34]!==h||e[35]!==I?(D=h&&d(Fe,{draft:a,editing:c!==null,onCancel:O,onChange:o,onSubmit:I}),e[32]=a,e[33]=c,e[34]=h,e[35]=I,e[36]=D):D=e[36];let j;e[37]!==l.unavailable||e[38]!==h||e[39]!==g||e[40]!==z||e[41]!==Q||e[42]!==S||e[43]!==w||e[44]!==K||e[45]!==n||e[46]!==r?(j=r.length===0&&!h?d(me,{description:n("Add a chart, a single value, a table, or a note. Everything is saved on this browser."),testId:"dashboards-empty",title:n("No widgets yet")}):d("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3","data-testid":"dashboards-grid",children:r.map((p,m)=>d(Te,{draggedRef:f,first:m===0,inferring:g===p.id,last:m===r.length-1,onEdit:z,onMove:Q,onRemove:S,onReorder:w,onSuggest:l.unavailable?void 0:K,widget:p},p.id))}),e[37]=l.unavailable,e[38]=h,e[39]=g,e[40]=z,e[41]=Q,e[42]=S,e[43]=w,e[44]=K,e[45]=n,e[46]=r,e[47]=j):j=e[47];let T;return e[48]!==A||e[49]!==M||e[50]!==D||e[51]!==j?(T=Z("div",{className:"flex flex-col gap-4","data-testid":"lunora-dashboards",children:[A,M,D,j]}),e[48]=A,e[49]=M,e[50]=D,e[51]=j,e[52]=T):T=e[52],T};export{it as default};
|