const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TableSchemaView-pRJlVnGW.js","assets/vendor-codemirror-CudAmtoj.js","assets/vendor-ui-E37q2bOV.js","assets/vendor-ag-grid-BoAOEhzw.js","assets/ExportDialog-bc6i1d15.js"])))=>i.map(i=>d[i]);
import{j as e,s as Je,M as xe,a as yt,P as Ve,k as Ke,R as Ge,o as Xe,E as wt}from"./vendor-codemirror-CudAmtoj.js";import{r as i,g as St,R as Ye,c as ue,X as ye,C as Ze,a as Nt,L as le,b as je,D as et,W as Ct,E as kt,T as ie,S as Et,d as Le,e as we,U as ce,f as Pe,h as tt,i as $e,j as st,k as qe,l as Tt,P as at,m as $t,n as _t,o as Dt,p as It,q as nt,s as rt,B as Rt,t as zt,H as Lt,F as Pt,u as Ot,v as Mt}from"./vendor-ui-E37q2bOV.js";import{r as ot,t as Ft,A as qt}from"./vendor-ag-grid-BoAOEhzw.js";(function(){const a=document.createElement("link").relList;if(a&&a.supports&&a.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))n(r);new MutationObserver(r=>{for(const o of r)if(o.type==="childList")for(const l of o.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&n(l)}).observe(document,{childList:!0,subtree:!0});function s(r){const o={};return r.integrity&&(o.integrity=r.integrity),r.referrerPolicy&&(o.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?o.credentials="include":r.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function n(r){if(r.ep)return;r.ep=!0;const o=s(r);fetch(r.href,o)}})();var Ie={},Ae=ot;Ie.createRoot=Ae.createRoot,Ie.hydrateRoot=Ae.hydrateRoot;const At={},Be=t=>{let a;const s=new Set,n=(d,b)=>{const v=typeof d=="function"?d(a):d;if(!Object.is(v,a)){const y=a;a=b??(typeof v!="object"||v===null)?v:Object.assign({},a,v),s.forEach(S=>S(a,y))}},r=()=>a,x={setState:n,getState:r,getInitialState:()=>f,subscribe:d=>(s.add(d),()=>s.delete(d)),destroy:()=>{(At?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),s.clear()}},f=a=t(n,r,x);return x},Bt=t=>t?Be(t):Be;var lt={exports:{}},it={},ct={exports:{}},dt={};/**
 * @license React
 * use-sync-external-store-shim.production.js
 *
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */var de=i;function Qt(t,a){return t===a&&(t!==0||1/t===1/a)||t!==t&&a!==a}var Wt=typeof Object.is=="function"?Object.is:Qt,Ut=de.useState,Ht=de.useEffect,Jt=de.useLayoutEffect,Vt=de.useDebugValue;function Kt(t,a){var s=a(),n=Ut({inst:{value:s,getSnapshot:a}}),r=n[0].inst,o=n[1];return Jt(function(){r.value=s,r.getSnapshot=a,_e(r)&&o({inst:r})},[t,s,a]),Ht(function(){return _e(r)&&o({inst:r}),t(function(){_e(r)&&o({inst:r})})},[t]),Vt(s),s}function _e(t){var a=t.getSnapshot;t=t.value;try{var s=a();return!Wt(t,s)}catch{return!0}}function Gt(t,a){return a()}var Xt=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?Gt:Kt;dt.useSyncExternalStore=de.useSyncExternalStore!==void 0?de.useSyncExternalStore:Xt;ct.exports=dt;var Yt=ct.exports;/**
 * @license React
 * use-sync-external-store-shim/with-selector.production.js
 *
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */var Se=i,Zt=Yt;function es(t,a){return t===a&&(t!==0||1/t===1/a)||t!==t&&a!==a}var ts=typeof Object.is=="function"?Object.is:es,ss=Zt.useSyncExternalStore,as=Se.useRef,ns=Se.useEffect,rs=Se.useMemo,os=Se.useDebugValue;it.useSyncExternalStoreWithSelector=function(t,a,s,n,r){var o=as(null);if(o.current===null){var l={hasValue:!1,value:null};o.current=l}else l=o.current;o=rs(function(){function x(y){if(!f){if(f=!0,d=y,y=n(y),r!==void 0&&l.hasValue){var S=l.value;if(r(S,y))return b=S}return b=y}if(S=b,ts(d,y))return S;var m=n(y);return r!==void 0&&r(S,m)?(d=y,S):(d=y,b=m)}var f=!1,d,b,v=s===void 0?null:s;return[function(){return x(a())},v===null?void 0:function(){return x(v())}]},[a,s,n,r]);var c=ss(t,o[0],o[1]);return ns(function(){l.hasValue=!0,l.value=c},[c]),os(c),c};lt.exports=it;var ls=lt.exports;const is=St(ls),ut={},{useDebugValue:cs}=Ye,{useSyncExternalStoreWithSelector:ds}=is;let Qe=!1;const us=t=>t;function xs(t,a=us,s){(ut?"production":void 0)!=="production"&&s&&!Qe&&(console.warn("[DEPRECATED] Use `createWithEqualityFn` instead of `create` or use `useStoreWithEqualityFn` instead of `useStore`. They can be imported from 'zustand/traditional'. https://github.com/pmndrs/zustand/discussions/1937"),Qe=!0);const n=ds(t.subscribe,t.getState,t.getServerState||t.getInitialState,a,s);return cs(n),n}const We=t=>{(ut?"production":void 0)!=="production"&&typeof t!="function"&&console.warn("[DEPRECATED] Passing a vanilla store will be unsupported in a future version. Instead use `import { useStore } from 'zustand'`.");const a=typeof t=="function"?Bt(t):t,s=(n,r)=>xs(a,n,r);return Object.assign(s,a),s},Ne=t=>t?We(t):We,fs={};function ms(t,a){let s;try{s=t()}catch{return}return{getItem:r=>{var o;const l=x=>x===null?null:JSON.parse(x,void 0),c=(o=s.getItem(r))!=null?o:null;return c instanceof Promise?c.then(l):l(c)},setItem:(r,o)=>s.setItem(r,JSON.stringify(o,void 0)),removeItem:r=>s.removeItem(r)}}const fe=t=>a=>{try{const s=t(a);return s instanceof Promise?s:{then(n){return fe(n)(s)},catch(n){return this}}}catch(s){return{then(n){return this},catch(n){return fe(n)(s)}}}},hs=(t,a)=>(s,n,r)=>{let o={getStorage:()=>localStorage,serialize:JSON.stringify,deserialize:JSON.parse,partialize:p=>p,version:0,merge:(p,$)=>({...$,...p}),...a},l=!1;const c=new Set,x=new Set;let f;try{f=o.getStorage()}catch{}if(!f)return t((...p)=>{console.warn(`[zustand persist middleware] Unable to update item '${o.name}', the given storage is currently unavailable.`),s(...p)},n,r);const d=fe(o.serialize),b=()=>{const p=o.partialize({...n()});let $;const w=d({state:p,version:o.version}).then(I=>f.setItem(o.name,I)).catch(I=>{$=I});if($)throw $;return w},v=r.setState;r.setState=(p,$)=>{v(p,$),b()};const y=t((...p)=>{s(...p),b()},n,r);let S;const m=()=>{var p;if(!f)return;l=!1,c.forEach(w=>w(n()));const $=((p=o.onRehydrateStorage)==null?void 0:p.call(o,n()))||void 0;return fe(f.getItem.bind(f))(o.name).then(w=>{if(w)return o.deserialize(w)}).then(w=>{if(w)if(typeof w.version=="number"&&w.version!==o.version){if(o.migrate)return o.migrate(w.state,w.version);console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return w.state}).then(w=>{var I;return S=o.merge(w,(I=n())!=null?I:y),s(S,!0),b()}).then(()=>{$==null||$(S,void 0),l=!0,x.forEach(w=>w(S))}).catch(w=>{$==null||$(void 0,w)})};return r.persist={setOptions:p=>{o={...o,...p},p.getStorage&&(f=p.getStorage())},clearStorage:()=>{f==null||f.removeItem(o.name)},getOptions:()=>o,rehydrate:()=>m(),hasHydrated:()=>l,onHydrate:p=>(c.add(p),()=>{c.delete(p)}),onFinishHydration:p=>(x.add(p),()=>{x.delete(p)})},m(),S||y},ps=(t,a)=>(s,n,r)=>{let o={storage:ms(()=>localStorage),partialize:m=>m,version:0,merge:(m,p)=>({...p,...m}),...a},l=!1;const c=new Set,x=new Set;let f=o.storage;if(!f)return t((...m)=>{console.warn(`[zustand persist middleware] Unable to update item '${o.name}', the given storage is currently unavailable.`),s(...m)},n,r);const d=()=>{const m=o.partialize({...n()});return f.setItem(o.name,{state:m,version:o.version})},b=r.setState;r.setState=(m,p)=>{b(m,p),d()};const v=t((...m)=>{s(...m),d()},n,r);r.getInitialState=()=>v;let y;const S=()=>{var m,p;if(!f)return;l=!1,c.forEach(w=>{var I;return w((I=n())!=null?I:v)});const $=((p=o.onRehydrateStorage)==null?void 0:p.call(o,(m=n())!=null?m:v))||void 0;return fe(f.getItem.bind(f))(o.name).then(w=>{if(w)if(typeof w.version=="number"&&w.version!==o.version){if(o.migrate)return[!0,o.migrate(w.state,w.version)];console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return[!1,w.state];return[!1,void 0]}).then(w=>{var I;const[M,F]=w;if(y=o.merge(F,(I=n())!=null?I:v),s(y,!0),M)return d()}).then(()=>{$==null||$(y,void 0),y=n(),l=!0,x.forEach(w=>w(y))}).catch(w=>{$==null||$(void 0,w)})};return r.persist={setOptions:m=>{o={...o,...m},m.storage&&(f=m.storage)},clearStorage:()=>{f==null||f.removeItem(o.name)},getOptions:()=>o,rehydrate:()=>S(),hasHydrated:()=>l,onHydrate:m=>(c.add(m),()=>{c.delete(m)}),onFinishHydration:m=>(x.add(m),()=>{x.delete(m)})},o.skipHydration||S(),y||v},bs=(t,a)=>"getStorage"in a||"serialize"in a||"deserialize"in a?((fs?"production":void 0)!=="production"&&console.warn("[DEPRECATED] `getStorage`, `serialize` and `deserialize` options are deprecated. Use `storage` option instead."),hs(t,a)):ps(t,a),Oe=bs,Re="/api/v1";async function R(t,a){const s={...a==null?void 0:a.headers};a!=null&&a.body&&(s["Content-Type"]??(s["Content-Type"]="application/json"));const n=await fetch(`${Re}${t}`,{...a,headers:s});if(!n.ok){const r=await n.json().catch(()=>({detail:n.statusText}));throw new Error(r.detail||`HTTP ${n.status}`)}if(n.status!==204)return n.json()}const B={getSessions:()=>R("/sessions"),createSession:t=>R("/sessions",{method:"POST",body:JSON.stringify(t)}),getSession:t=>R(`/sessions/${t}`),updateSession:(t,a)=>R(`/sessions/${t}`,{method:"PUT",body:JSON.stringify(a)}),deleteSession:t=>R(`/sessions/${t}`,{method:"DELETE"}),testSession:t=>R(`/sessions/${t}/test`,{method:"POST"}),probeConnection:t=>R("/sessions/probe",{method:"POST",body:JSON.stringify(t)}),getDatabases:t=>R(`/sessions/${t}/databases`),getTables:(t,a)=>R(`/sessions/${t}/databases/${a}/tables`),getColumns:(t,a,s)=>R(`/sessions/${t}/databases/${a}/tables/${s}/columns`),getIndexes:(t,a,s)=>R(`/sessions/${t}/databases/${a}/tables/${s}/indexes`),getCreateSql:(t,a,s)=>R(`/sessions/${t}/databases/${a}/tables/${s}/create_sql`),executeQuery:(t,a,s,n)=>R(`/sessions/${t}/query`,{method:"POST",body:JSON.stringify({sql:a,database:s,limit:n})}),cellUpdate:(t,a)=>R(`/sessions/${t}/cell-update`,{method:"POST",body:JSON.stringify(a)}),rowInsert:(t,a)=>R(`/sessions/${t}/row-insert`,{method:"POST",body:JSON.stringify(a)}),rowDelete:(t,a)=>R(`/sessions/${t}/rows`,{method:"DELETE",body:JSON.stringify(a)}),createTable:(t,a,s)=>R(`/sessions/${t}/databases/${a}/tables`,{method:"POST",body:JSON.stringify(s)}),dropTable:(t,a,s)=>R(`/sessions/${t}/databases/${a}/tables/${s}`,{method:"DELETE"}),truncateTable:(t,a,s)=>R(`/sessions/${t}/databases/${a}/tables/${s}/truncate`,{method:"POST"}),createIndex:(t,a,s,n)=>R(`/sessions/${t}/databases/${a}/tables/${s}/indexes`,{method:"POST",body:JSON.stringify(n)}),dropIndex:(t,a,s,n)=>R(`/sessions/${t}/databases/${a}/tables/${s}/indexes/${n}`,{method:"DELETE"}),setPrimaryKey:(t,a,s,n)=>R(`/sessions/${t}/databases/${a}/tables/${s}/primary-key`,{method:"POST",body:JSON.stringify({columns:n})}),dropPrimaryKey:(t,a,s)=>R(`/sessions/${t}/databases/${a}/tables/${s}/primary-key`,{method:"DELETE"}),addColumn:(t,a,s,n)=>R(`/sessions/${t}/databases/${a}/tables/${s}/columns`,{method:"POST",body:JSON.stringify(n)}),modifyColumn:(t,a,s,n,r)=>R(`/sessions/${t}/databases/${a}/tables/${s}/columns/${n}`,{method:"PUT",body:JSON.stringify(r)}),dropColumn:(t,a,s,n)=>R(`/sessions/${t}/databases/${a}/tables/${s}/columns/${n}`,{method:"DELETE"}),exportConfig:async t=>{const a=await fetch(`${Re}/config/export`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({passphrase:t})});if(!a.ok){const x=await a.json().catch(()=>({detail:a.statusText}));throw new Error(x.detail||`HTTP ${a.status}`)}const s=await a.blob(),r=(a.headers.get("Content-Disposition")??"").match(/filename="([^"]+)"/),o=r?r[1]:"lagun_sessions.json",l=URL.createObjectURL(s),c=document.createElement("a");c.href=l,c.download=o,c.click(),URL.revokeObjectURL(l)},importConfig:async(t,a)=>{const s=new FormData;s.append("file",t),s.append("passphrase",a);const n=await fetch(`${Re}/config/import`,{method:"POST",body:s});if(!n.ok){const r=await n.json().catch(()=>({detail:n.statusText}));throw new Error(r.detail||`HTTP ${n.status}`)}return n.json()}},te=Ne()(Oe((t,a)=>({sessions:[],activeSessionId:null,loading:!1,error:null,loadSessions:async()=>{t({loading:!0,error:null});try{const s=await B.getSessions();t({sessions:s,loading:!1})}catch(s){t({error:String(s),loading:!1})}},setActiveSession:s=>t({activeSessionId:s}),createSession:async s=>{const n=await B.createSession(s);return t(r=>({sessions:[...r.sessions,n]})),n},updateSession:async(s,n)=>{const r=await B.updateSession(s,n);return t(o=>({sessions:o.sessions.map(l=>l.id===s?r:l)})),r},deleteSession:async s=>{await B.deleteSession(s),t(n=>({sessions:n.sessions.filter(r=>r.id!==s),activeSessionId:n.activeSessionId===s?null:n.activeSessionId}))},testSession:async s=>B.testSession(s)}),{name:"lagun-session-ui",version:1,partialize:t=>({activeSessionId:t.activeSessionId})}));function gs(){var t;return((t=crypto.randomUUID)==null?void 0:t.call(crypto))??"10000000-1000-4000-8000-100000000000".replace(/[018]/g,a=>(+a^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+a/4).toString(16))}function De(){return`tab-${gs()}`}const Z=Ne()(Oe((t,a)=>({tabs:[],activeTabId:null,pendingSqls:{},openQueryTab:(s,n)=>{const r=De(),o={id:r,label:n?`Query — ${n}`:"Query",type:"query",sessionId:s,database:n};t(l=>({tabs:[...l.tabs,o],activeTabId:r}))},openQueryTabWithSql:(s,n,r)=>{const o=De(),l={id:o,label:r?`Query — ${r}`:"Query",type:"query",sessionId:s,database:r,sql:n};t(c=>({tabs:[...c.tabs,l],activeTabId:o}))},openTableTab:(s,n,r)=>{const o=a().tabs.find(x=>x.type==="table"&&x.sessionId===s&&x.database===n&&x.table===r);if(o){t({activeTabId:o.id});return}const l=De(),c={id:l,label:r,type:"table",sessionId:s,database:n,table:r};t(x=>({tabs:[...x.tabs,c],activeTabId:l}))},closeTab:s=>{t(n=>{var l;const r=n.tabs.filter(c=>c.id!==s);let o=n.activeTabId;if(o===s){const c=n.tabs.findIndex(x=>x.id===s);o=((l=r[Math.max(0,c-1)])==null?void 0:l.id)??null}return{tabs:r,activeTabId:o}})},setActiveTab:s=>t({activeTabId:s}),closeAllTabs:()=>t({tabs:[],activeTabId:null}),setSql:(s,n)=>t(r=>({tabs:r.tabs.map(o=>o.id===s?{...o,sql:n}:o)})),setTabDatabase:(s,n)=>t(r=>({tabs:r.tabs.map(o=>o.id===s?{...o,database:n,label:`Query — ${n}`}:o)})),injectSqlToTab:(s,n,r)=>t(o=>({pendingSqls:{...o.pendingSqls,[s]:{sql:n,database:r}}})),consumePendingSql:s=>t(n=>{const r={...n.pendingSqls};return delete r[s],{pendingSqls:r}})}),{name:"lagun-tabs",version:2,partialize:t=>({tabs:t.tabs,activeTabId:t.activeTabId})})),W=i.forwardRef(({variant:t="secondary",size:a="md",className:s,children:n,...r},o)=>e.jsx("button",{ref:o,className:ue("inline-flex items-center justify-center gap-1.5 font-medium rounded-md transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500 disabled:opacity-50 disabled:cursor-not-allowed",{"bg-brand-600 hover:bg-brand-500 text-white":t==="primary","bg-surface-700 hover:bg-surface-600 text-slate-200 border border-surface-600":t==="secondary","hover:bg-surface-800 text-slate-400 hover:text-slate-200":t==="ghost","bg-red-700 hover:bg-red-600 text-white":t==="danger"},{"px-2 py-1 text-xs":a==="sm","px-3 py-1.5 text-sm":a==="md","px-4 py-2 text-base":a==="lg"},s),...r,children:n}));W.displayName="Button";function Ce({open:t,onClose:a,title:s,children:n,footer:r,width:o="max-w-lg"}){return i.useEffect(()=>{if(!t)return;const l=c=>{c.key==="Escape"&&a()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[t,a]),t?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:a}),e.jsxs("div",{className:`relative bg-surface-900 border border-surface-700 rounded-lg shadow-2xl w-full ${o} flex flex-col max-h-[90vh]`,children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-surface-700",children:[e.jsx("h2",{className:"text-sm font-semibold text-slate-100",children:s}),e.jsx(W,{variant:"ghost",size:"sm",onClick:a,className:"p-1",children:e.jsx(ye,{size:14})})]}),e.jsx("div",{className:"p-4 overflow-y-auto flex-1",children:n}),r&&e.jsx("div",{className:"px-4 py-3 border-t border-surface-700 flex justify-end gap-2",children:r})]})]}):null}const Y=i.forwardRef(({label:t,error:a,className:s,...n},r)=>{const o=n.id??(t?`input-${t.toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,"")}`:void 0);return e.jsxs("div",{className:"flex flex-col gap-1",children:[t&&e.jsx("label",{htmlFor:o,className:"text-xs font-medium text-slate-400 uppercase tracking-wide",children:t}),e.jsx("input",{ref:r,id:o,className:ue("bg-surface-800 border border-surface-700 rounded-md px-3 py-1.5 text-sm text-slate-100 placeholder-slate-500","focus:outline-none focus:ring-2 focus:ring-brand-500 focus:border-brand-500","disabled:opacity-50 disabled:cursor-not-allowed",a&&"border-red-500",s),...n}),a&&e.jsx("p",{className:"text-xs text-red-400",children:a})]})});Y.displayName="Input";const Ue={name:"",host:"localhost",port:"3306",username:"root",password:"",default_db:"",query_limit:"100",ssl_enabled:!1};function xt({open:t,onClose:a,session:s}){const{createSession:n,updateSession:r,testSession:o}=te(),[l,c]=i.useState(Ue),[x,f]=i.useState(!1),[d,b]=i.useState(!1),[v,y]=i.useState(null),[S,m]=i.useState([]),[p,$]=i.useState([]),[w,I]=i.useState(!1),[M,F]=i.useState(null),[U,V]=i.useState(null);i.useEffect(()=>{s?(c({name:s.name,host:s.host,port:String(s.port),username:s.username,password:"",default_db:s.default_db??"",query_limit:String(s.query_limit),ssl_enabled:s.ssl_enabled}),$(s.selected_databases??[])):(c(Ue),$([])),V(null),y(null),m([]),F(null)},[s,t]);const _=(u,C)=>c(T=>({...T,[u]:C})),G=async()=>{f(!0),V(null);try{const u={name:l.name,host:l.host,port:parseInt(l.port),username:l.username,...l.password?{password:l.password}:{},default_db:l.default_db||void 0,query_limit:parseInt(l.query_limit),ssl_enabled:l.ssl_enabled,selected_databases:p};s?await r(s.id,u):await n({...u,password:l.password}),a()}catch(u){V(String(u))}finally{f(!1)}},H=async()=>{b(!0),y(null);try{let u;s?u=await o(s.id):u=await B.probeConnection({host:l.host,port:parseInt(l.port),username:l.username,password:l.password,ssl_enabled:l.ssl_enabled}),u.ok?y({ok:!0,msg:`Connected! MySQL ${u.server_version} — ${u.latency_ms}ms`}):y({ok:!1,msg:u.error??"Connection failed"})}finally{b(!1)}},q=async()=>{I(!0),F(null);try{let u;if(s?u=await o(s.id):u=await B.probeConnection({host:l.host,port:parseInt(l.port),username:l.username,password:l.password,ssl_enabled:l.ssl_enabled}),u.ok){const C=u.databases??[];m(C),$(T=>T.filter(z=>C.includes(z)))}else F(u.error??"Connection failed")}catch(u){F(String(u))}finally{I(!1)}},D=u=>{$(C=>C.includes(u)?C.filter(T=>T!==u):[...C,u])},K=()=>{$(u=>u.length===S.length?[]:[...S])};return e.jsx(Ce,{open:t,onClose:a,title:s?"Edit Connection":"New Connection",footer:e.jsxs(e.Fragment,{children:[e.jsx(W,{variant:"ghost",onClick:a,children:"Cancel"}),e.jsxs(W,{variant:"secondary",onClick:H,disabled:d,children:[d?e.jsx(le,{size:12,className:"animate-spin"}):null,"Test"]}),e.jsxs(W,{variant:"primary",onClick:G,disabled:x,children:[x?e.jsx(le,{size:12,className:"animate-spin"}):null,s?"Save":"Create"]})]}),children:e.jsxs("div",{className:"flex flex-col gap-3",children:[v&&e.jsxs("div",{className:`flex items-center gap-2 text-xs px-3 py-2 rounded ${v.ok?"bg-green-900/40 text-green-300":"bg-red-900/40 text-red-300"}`,children:[v.ok?e.jsx(Ze,{size:12}):e.jsx(Nt,{size:12}),v.msg]}),U&&e.jsx("p",{className:"text-xs text-red-400",children:U}),e.jsx(Y,{label:"Connection Name",value:l.name,onChange:u=>_("name",u.target.value),placeholder:"My Database"}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx("div",{className:"col-span-2",children:e.jsx(Y,{label:"Host",value:l.host,onChange:u=>_("host",u.target.value),placeholder:"localhost"})}),e.jsx(Y,{label:"Port",type:"number",value:l.port,onChange:u=>_("port",u.target.value)})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(Y,{label:"Username",value:l.username,onChange:u=>_("username",u.target.value),placeholder:"root"}),e.jsx(Y,{label:"Password",type:"password",value:l.password,onChange:u=>_("password",u.target.value),placeholder:s?"(unchanged)":""})]}),e.jsx(Y,{label:"Default Database (optional)",value:l.default_db,onChange:u=>_("default_db",u.target.value),placeholder:"my_db"}),e.jsx(Y,{label:"Row Limit",type:"number",value:l.query_limit,onChange:u=>_("query_limit",u.target.value)}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-slate-300 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:l.ssl_enabled,onChange:u=>_("ssl_enabled",u.target.checked),className:"rounded"}),"Enable SSL"]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-medium text-slate-400 uppercase tracking-wide",children:"Databases"}),e.jsxs("div",{className:"flex items-center gap-2",children:[S.length>0&&e.jsx("button",{type:"button",onClick:K,className:"text-xs text-brand-400 hover:text-brand-300",children:p.length===S.length?"Deselect all":"Select all"}),e.jsxs("button",{type:"button",onClick:q,disabled:w,title:"Fetch databases from server",className:"flex items-center gap-1 px-2 py-0.5 rounded text-xs bg-surface-700 hover:bg-surface-600 text-slate-300 disabled:opacity-50",children:[w?e.jsx(le,{size:11,className:"animate-spin"}):e.jsx(je,{size:11}),"Fetch"]})]})]}),M&&e.jsx("p",{className:"text-xs text-red-400",children:M}),S.length===0&&!w&&!M&&e.jsx("p",{className:"text-xs text-slate-500 italic",children:"Click Fetch to load available databases from the server."}),S.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"max-h-40 overflow-y-auto rounded border border-surface-700 bg-surface-950 divide-y divide-surface-800",children:S.map(u=>e.jsxs("label",{className:"flex items-center gap-2 px-3 py-1.5 cursor-pointer hover:bg-surface-800",children:[e.jsx("input",{type:"checkbox",checked:p.includes(u),onChange:()=>D(u),className:"rounded"}),e.jsx(et,{size:11,className:"text-yellow-400 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-slate-300",children:u})]},u))}),e.jsx("p",{className:"text-xs text-slate-500",children:p.length===0?"No selection — all databases will be shown":`${p.length} of ${S.length} selected`})]})]})]})})}function vs({onNew:t}){const{sessions:a,activeSessionId:s,setActiveSession:n,deleteSession:r}=te(),{openQueryTab:o}=Z(),[l,c]=i.useState(null),[x,f]=i.useState(null);return a.length===0?e.jsx("div",{className:"px-3 py-4 text-center text-xs text-slate-500",children:"No connections yet."}):e.jsxs("div",{className:"py-1",children:[a.map(d=>e.jsxs("div",{className:ue("flex items-center px-3 py-1.5 cursor-pointer group transition-colors",s===d.id?"bg-brand-600/20 text-brand-300":"hover:bg-surface-800 text-slate-300"),onClick:()=>n(d.id),children:[e.jsx(Ct,{size:12,className:"flex-shrink-0 mr-2 text-green-400"}),e.jsx("span",{className:"flex-1 truncate text-xs",children:d.name}),e.jsx("span",{className:"text-slate-500 text-xs mr-1",children:d.host}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:b=>{b.stopPropagation(),f(x===d.id?null:d.id)},className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-surface-700 text-slate-400 hover:text-slate-200",children:e.jsx(kt,{size:12})}),x===d.id&&e.jsxs("div",{className:"absolute right-0 top-6 bg-surface-800 border border-surface-700 rounded shadow-lg z-50 py-1 w-40",onMouseLeave:()=>f(null),children:[e.jsxs("button",{className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-surface-700 text-slate-200",onClick:b=>{b.stopPropagation(),o(d.id),f(null)},children:[e.jsx(ie,{size:12})," New Query"]}),e.jsxs("button",{className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-surface-700 text-slate-200",onClick:b=>{b.stopPropagation(),c(d),f(null)},children:[e.jsx(Et,{size:12})," Edit"]}),e.jsxs("button",{className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-surface-700 text-red-400",onClick:b=>{b.stopPropagation(),r(d.id),f(null)},children:[e.jsx(Le,{size:12})," Delete"]})]})]})]},d.id)),l&&e.jsx(xt,{open:!!l,onClose:()=>c(null),session:l})]})}function js({open:t,onClose:a}){const[s,n]=i.useState(""),[r,o]=i.useState(""),[l,c]=i.useState(!1),[x,f]=i.useState(null),d=()=>{n(""),o(""),f(null),a()},b=async()=>{if(f(null),!s){f("Enter a passphrase to protect the exported passwords.");return}if(s!==r){f("Passphrases do not match.");return}c(!0);try{await B.exportConfig(s),d()}catch(v){f(String(v))}finally{c(!1)}};return e.jsx(Ce,{open:t,onClose:d,title:"Export Connections",width:"max-w-md",footer:e.jsxs(e.Fragment,{children:[e.jsx(W,{variant:"ghost",onClick:d,children:"Cancel"}),e.jsxs(W,{variant:"primary",onClick:b,disabled:l,children:[l?e.jsx(le,{size:12,className:"animate-spin mr-1"}):e.jsx(we,{size:12,className:"mr-1"}),"Download"]})]}),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("p",{className:"text-xs text-slate-400",children:"Export all saved connections to an encrypted JSON file. You will need this passphrase to import the file on any Lagun instance."}),e.jsx(Y,{label:"Passphrase",type:"password",value:s,onChange:v=>n(v.target.value),placeholder:"Strong passphrase",autoComplete:"new-password"}),e.jsx(Y,{label:"Confirm passphrase",type:"password",value:r,onChange:v=>o(v.target.value),placeholder:"Repeat passphrase",autoComplete:"new-password",onKeyDown:v=>v.key==="Enter"&&b()}),x&&e.jsx("p",{className:"text-xs text-red-400",children:x})]})})}function ys({open:t,onClose:a}){const{loadSessions:s}=te(),[n,r]=i.useState(null),[o,l]=i.useState(""),[c,x]=i.useState(!1),[f,d]=i.useState(null),[b,v]=i.useState(null),y=()=>{r(null),l(""),d(null),v(null),a()},S=async()=>{if(!n){v("Select a file first.");return}if(!o){v("Enter the passphrase used during export.");return}x(!0),v(null);try{const m=await B.importConfig(n,o);d(m),await s()}catch(m){v(String(m))}finally{x(!1)}};return e.jsx(Ce,{open:t,onClose:y,title:"Import Connections",width:"max-w-md",footer:f?e.jsx(W,{variant:"primary",onClick:y,children:"Done"}):e.jsxs(e.Fragment,{children:[e.jsx(W,{variant:"ghost",onClick:y,children:"Cancel"}),e.jsxs(W,{variant:"primary",onClick:S,disabled:c||!n,children:[c?e.jsx(le,{size:12,className:"animate-spin mr-1"}):e.jsx(ce,{size:12,className:"mr-1"}),"Import"]})]}),children:f?e.jsxs("div",{className:"flex flex-col items-center gap-3 py-4",children:[e.jsx(Ze,{size:32,className:"text-green-400"}),e.jsx("p",{className:"text-sm text-slate-200 font-medium",children:"Import complete"}),e.jsxs("p",{className:"text-xs text-slate-400",children:[f.imported," connection",f.imported!==1?"s":""," imported",f.skipped>0?`, ${f.skipped} skipped`:"","."]})]}):e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("p",{className:"text-xs text-slate-400",children:"Select a Lagun export file (.json) to restore saved connections."}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-slate-400 uppercase tracking-wide block mb-1",children:"Export file"}),e.jsx("input",{type:"file",accept:".json,application/json",onChange:m=>{var p;r(((p=m.target.files)==null?void 0:p[0])??null),v(null)},className:`text-sm text-slate-300 file:mr-3 file:py-1 file:px-3 file:rounded file:border-0
                         file:text-xs file:font-medium file:bg-surface-700 file:text-slate-200
                         hover:file:bg-surface-600 cursor-pointer`})]}),e.jsx(Y,{label:"Passphrase",type:"password",value:o,onChange:m=>l(m.target.value),placeholder:"Passphrase used during export",autoComplete:"current-password",onKeyDown:m=>m.key==="Enter"&&S()}),b&&e.jsx("p",{className:"text-xs text-red-400",children:b})]})})}const be={},ge={},ve={},me=Ne((t,a)=>({databases:{},tables:{},columns:{},loadingDbs:new Set,loadingTables:new Set,loadDatabases:async s=>{const{databases:n}=a();if(n[s])return n[s];if(be[s])return be[s];t(o=>({loadingDbs:new Set([...o.loadingDbs,s])}));const r=B.getDatabases(s).then(o=>(t(l=>({databases:{...l.databases,[s]:o},loadingDbs:new Set([...l.loadingDbs].filter(c=>c!==s))})),o)).catch(()=>(t(o=>({loadingDbs:new Set([...o.loadingDbs].filter(l=>l!==s))})),[])).finally(()=>{delete be[s]});return be[s]=r,r},loadTables:async(s,n)=>{const r=`${s}/${n}`,{tables:o}=a();if(o[r])return o[r];if(ge[r])return ge[r];t(c=>({loadingTables:new Set([...c.loadingTables,r])}));const l=B.getTables(s,n).then(c=>(t(x=>({tables:{...x.tables,[r]:c},loadingTables:new Set([...x.loadingTables].filter(f=>f!==r))})),c)).catch(()=>(t(c=>({loadingTables:new Set([...c.loadingTables].filter(x=>x!==r))})),[])).finally(()=>{delete ge[r]});return ge[r]=l,l},loadColumns:async(s,n,r)=>{const o=`${s}/${n}/${r}`,{columns:l}=a();if(l[o])return l[o];if(ve[o])return ve[o];const c=B.getColumns(s,n,r).then(x=>(t(f=>({columns:{...f.columns,[o]:x}})),x)).catch(()=>[]).finally(()=>{delete ve[o]});return ve[o]=c,c},invalidateSession:s=>{t(n=>{const r={...n.databases};delete r[s];const o=Object.fromEntries(Object.entries(n.tables).filter(([c])=>!c.startsWith(`${s}/`))),l=Object.fromEntries(Object.entries(n.columns).filter(([c])=>!c.startsWith(`${s}/`)));return{databases:r,tables:o,columns:l}})},invalidateTable:(s,n,r)=>{const o=`${s}/${n}/${r}`;t(l=>{const c={...l.columns};return delete c[o],{columns:c}})}})),ne=i.forwardRef(({label:t,error:a,className:s,children:n,...r},o)=>e.jsxs("div",{className:"flex flex-col gap-1",children:[t&&e.jsx("label",{className:"text-xs font-medium text-slate-400 uppercase tracking-wide",children:t}),e.jsx("select",{ref:o,className:ue("bg-surface-800 border border-surface-700 rounded-md px-3 py-1.5 text-sm text-slate-100","focus:outline-none focus:ring-2 focus:ring-brand-500 focus:border-brand-500","disabled:opacity-50 disabled:cursor-not-allowed",a&&"border-red-500",s),...r,children:n}),a&&e.jsx("p",{className:"text-xs text-red-400",children:a})]}));ne.displayName="Select";function ft({open:t,onClose:a,sessionId:s,database:n,table:r,onImportComplete:o}){const[l,c]=i.useState(null),[x,f]=i.useState(null),[d,b]=i.useState(null),[v,y]=i.useState(!1),[S,m]=i.useState(","),[p,$]=i.useState(""),[w,I]=i.useState('"'),[M,F]=i.useState('"'),[U,V]=i.useState("crlf"),[_,G]=i.useState("utf-8"),q={crlf:`\r
`,lf:`
`,cr:"\r"}[U]||`\r
`,[D,K]=i.useState(!0),[u,C]=i.useState(r??""),[T,z]=i.useState("insert"),[O,h]=i.useState(!1),[k,j]=i.useState(!1),[N,P]=i.useState(null),J=i.useRef(null),X=me(g=>g.tables[`${s}/${n}`]??[]),{loadTables:se}=me();i.useEffect(()=>{se(s,n)},[s,n,se]);const ae=S==="custom"?p:S,re=i.useCallback(()=>JSON.stringify({database:n,table:u,delimiter:ae,quotechar:w,escapechar:M,lineterminator:q,encoding:_,first_row_header:D,strategy:T}),[n,u,ae,w,M,q,_,D,T]),ee=i.useRef();i.useEffect(()=>{if(!l){f(null),b(null);return}return clearTimeout(ee.current),ee.current=setTimeout(async()=>{y(!0),b(null);try{const g=new FormData;g.append("file",l),g.append("config",re());const A=await fetch(`/api/v1/sessions/${s}/import/preview`,{method:"POST",body:g});A.ok?(f(await A.json()),b(null)):(b(await A.text()),f(null))}catch(g){b(String(g)),f(null)}finally{y(!1)}},300),()=>clearTimeout(ee.current)},[l,ae,w,M,U,_,D,s,re]);const E=g=>{g&&g.length>0&&(c(g[0]),P(null))},Q=g=>{g.preventDefault(),E(g.dataTransfer.files)},L=async()=>{if(!(!l||!u)){j(!0),P(null);try{const g=new FormData;g.append("file",l),g.append("config",re());const oe=await(await fetch(`/api/v1/sessions/${s}/import`,{method:"POST",body:g})).json();P(oe),oe.ok&&(o==null||o())}catch(g){P({ok:!1,rows_processed:0,rows_imported:0,method:"unknown",error:String(g)})}finally{j(!1)}}};return e.jsx(Ce,{open:t,onClose:a,title:`Import into ${n}${u?"."+u:""}`,width:"max-w-2xl",footer:e.jsxs(e.Fragment,{children:[e.jsx(W,{variant:"ghost",onClick:a,children:"Cancel"}),e.jsx(W,{variant:"primary",onClick:L,disabled:k||!l||!u,children:k?"Importing…":"Import"})]}),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"border-2 border-dashed border-surface-700 rounded-lg p-6 text-center cursor-pointer hover:border-surface-600 transition-colors",onClick:()=>{var g;return(g=J.current)==null?void 0:g.click()},onDragOver:g=>g.preventDefault(),onDrop:Q,children:[e.jsx("input",{ref:J,type:"file",accept:".csv,.tsv,.txt",className:"hidden",onChange:g=>E(g.target.files)}),l?e.jsxs("div",{className:"text-sm",children:[e.jsx(ce,{size:20,className:"mx-auto mb-2 text-brand-400"}),e.jsx("p",{className:"text-slate-200",children:l.name}),e.jsxs("p",{className:"text-xs text-slate-500 mt-1",children:[(l.size/1024).toFixed(1)," KB"]})]}):e.jsxs("div",{className:"text-sm text-slate-500",children:[e.jsx(ce,{size:20,className:"mx-auto mb-2"}),e.jsx("p",{children:"Drop a CSV file here or click to select"}),e.jsx("p",{className:"text-xs mt-1",children:".csv, .tsv, .txt"})]})]}),v&&e.jsx("p",{className:"text-xs text-slate-500",children:"Loading preview…"}),d&&e.jsx("p",{className:"text-xs text-red-400",children:d}),x&&e.jsxs("div",{className:"overflow-x-auto max-h-48 border border-surface-700 rounded",children:[e.jsxs("table",{className:"text-xs w-full",children:[e.jsx("thead",{children:e.jsx("tr",{className:"bg-surface-800",children:x.columns.map((g,A)=>e.jsx("th",{className:"px-2 py-1 text-left text-slate-300 font-medium whitespace-nowrap border-b border-surface-700",children:g},A))})}),e.jsx("tbody",{children:x.rows.map((g,A)=>e.jsx("tr",{className:"hover:bg-surface-800/50",children:g.map((oe,ke)=>e.jsx("td",{className:"px-2 py-1 text-slate-400 whitespace-nowrap border-b border-surface-800",children:oe},ke))},A))})]}),x.total_lines_sampled>x.rows.length&&e.jsxs("p",{className:"text-xs text-slate-500 px-2 py-1",children:["Showing ",x.rows.length," of ",x.total_lines_sampled,"+ rows"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs(ne,{label:"Target Table",value:u,onChange:g=>C(g.target.value),children:[e.jsx("option",{value:"",children:"Select table…"}),X.map(g=>e.jsx("option",{value:g.name,children:g.name},g.name))]}),e.jsxs(ne,{label:"Import Strategy",value:T,onChange:g=>z(g.target.value),children:[e.jsx("option",{value:"insert",children:"INSERT (fail on duplicate)"}),e.jsx("option",{value:"insert_ignore",children:"INSERT IGNORE (skip duplicates)"}),e.jsx("option",{value:"replace",children:"REPLACE INTO (overwrite)"})]})]}),e.jsxs("label",{className:"flex items-center gap-2 text-xs text-slate-300 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:g=>K(g.target.checked),className:"rounded border-surface-600 bg-surface-800 text-brand-500 focus:ring-brand-500"}),"First row contains column names"]}),e.jsxs("div",{children:[e.jsxs("button",{type:"button",className:"flex items-center gap-1 text-xs text-slate-400 hover:text-slate-200 transition-colors",onClick:()=>h(!O),children:[O?e.jsx(Pe,{size:12}):e.jsx(tt,{size:12}),"CSV Format Options"]}),O&&e.jsxs("div",{className:"mt-3 flex flex-col gap-3 pl-4 border-l border-surface-700",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsxs(ne,{label:"Delimiter",value:S,onChange:g=>m(g.target.value),children:[e.jsx("option",{value:",",children:"Comma (,)"}),e.jsx("option",{value:";",children:"Semicolon (;)"}),e.jsx("option",{value:"\\t",children:"Tab"}),e.jsx("option",{value:"|",children:"Pipe (|)"}),e.jsx("option",{value:"custom",children:"Custom"})]}),S==="custom"&&e.jsx(Y,{label:"Custom",value:p,onChange:g=>$(g.target.value.slice(0,1)),className:"w-16"})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs(ne,{label:"Quote Character",value:w,onChange:g=>I(g.target.value),children:[e.jsx("option",{value:'"',children:'Double Quote (")'}),e.jsx("option",{value:"'",children:"Single Quote (')"}),e.jsx("option",{value:"",children:"None"})]}),e.jsxs(ne,{label:"Escape Character",value:M,onChange:g=>F(g.target.value),children:[e.jsx("option",{value:'"',children:'Double Quote (")'}),e.jsx("option",{value:"\\\\",children:"Backslash (\\)"}),e.jsx("option",{value:"",children:"None"})]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs(ne,{label:"Line Ending",value:U,onChange:g=>V(g.target.value),children:[e.jsx("option",{value:"crlf",children:"CRLF (Windows)"}),e.jsx("option",{value:"lf",children:"LF (Unix/Mac)"}),e.jsx("option",{value:"cr",children:"CR (Legacy Mac)"})]}),e.jsxs(ne,{label:"Encoding",value:_,onChange:g=>G(g.target.value),children:[e.jsx("option",{value:"utf-8",children:"UTF-8"}),e.jsx("option",{value:"utf-8-sig",children:"UTF-8 with BOM"}),e.jsx("option",{value:"ascii",children:"ASCII"})]})]})]})]}),N&&e.jsx("div",{className:`p-3 rounded text-xs ${N.ok?"bg-green-900/30 border border-green-800 text-green-300":"bg-red-900/30 border border-red-800 text-red-300"}`,children:N.ok?e.jsxs(e.Fragment,{children:["Imported ",N.rows_imported," rows via ",N.method==="load_data"?"LOAD DATA":"batch insert",".",N.warnings&&N.warnings.length>0&&e.jsxs("ul",{className:"mt-1 list-disc list-inside text-yellow-400",children:[N.warnings.slice(0,5).map((g,A)=>e.jsx("li",{children:g},A)),N.warnings.length>5&&e.jsxs("li",{children:["…and ",N.warnings.length-5," more"]})]})]}):e.jsxs(e.Fragment,{children:["Import failed: ",N.error]})})]})})}const ws=Object.freeze(Object.defineProperty({__proto__:null,default:ft},Symbol.toStringTag,{value:"Module"}));function Ss(t){const a=`lagun-bookmarks-${t}`,[s,n]=i.useState(()=>{try{const l=localStorage.getItem(a);return new Set(l?JSON.parse(l):[])}catch{return new Set}});return{bookmarks:s,toggle:(l,c)=>{const x=`${l}/${c}`;n(f=>{const d=new Set(f);return d.has(x)?d.delete(x):d.add(x),localStorage.setItem(a,JSON.stringify([...d])),d})},isBookmarked:(l,c)=>s.has(`${l}/${c}`)}}function Ns({sessionId:t,selectedDatabases:a}){const{databases:s,loadDatabases:n,loadTables:r,tables:o,invalidateSession:l}=me(),{openTableTab:c,openQueryTab:x}=Z(),[f,d]=i.useState(new Set),[b,v]=i.useState(""),[y,S]=i.useState(!1),[m,p]=i.useState(null),[$,w]=i.useState(null),{bookmarks:I,toggle:M,isBookmarked:F}=Ss(t);i.useEffect(()=>{n(t)},[t,n]),i.useEffect(()=>{S(!1),v("")},[t]);const U=()=>{l(t),n(t),d(new Set),v("")},V=h=>{v(h),h&&q.forEach(k=>{d(j=>new Set([...j,k])),o[`${t}/${k}`]||r(t,k)})},_=async h=>{const k=new Set(f);k.has(h)?k.delete(h):(k.add(h),await r(t,h)),d(k)},G=()=>{const h=!y;S(h),h&&q.forEach(k=>{[...I].some(N=>N.startsWith(`${k}/`))&&(d(N=>new Set([...N,k])),o[`${t}/${k}`]||r(t,k))})},H=s[t]??[],q=a&&a.length>0?H.filter(h=>a.includes(h)):H,D=b.toLowerCase(),K=q.map(h=>{let j=o[`${t}/${h}`]??[];return y&&(j=j.filter(N=>F(h,N.name))),D&&(j=j.filter(N=>N.name.toLowerCase().includes(D))),{db:h,tbls:j}}).filter(({db:h,tbls:k})=>y?k.length>0:!D||k.length>0||h.toLowerCase().includes(D)),u=(h,k,j)=>{h.preventDefault(),h.stopPropagation(),p({x:h.clientX,y:h.clientY,db:k,table:j})},C=()=>p(null),T=async(h,k)=>{if(!confirm(`Drop table ${h}.${k}? This cannot be undone.`))return;await B.dropTable(t,h,k);const j=`${t}/${h}`;me.setState(N=>({tables:{...N.tables,[j]:(N.tables[j]??[]).filter(P=>P.name!==k)}})),C()},z=async(h,k)=>{confirm(`Truncate table ${h}.${k}? All rows will be deleted.`)&&(await B.truncateTable(t,h,k),C())},O=y&&I.size===0;return e.jsxs("div",{className:"py-1",onClick:C,children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-1",children:[e.jsx("span",{className:"text-xs font-medium text-slate-500 uppercase tracking-wide",children:"Databases"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:G,title:y?"Show all tables":"Show bookmarks only",className:`p-0.5 transition-colors ${y?"text-yellow-400":"text-slate-500 hover:text-slate-300"}`,children:e.jsx($e,{size:10,fill:y?"currentColor":"none"})}),e.jsx("button",{onClick:U,className:"p-0.5 text-slate-500 hover:text-slate-300 transition-colors",children:e.jsx(je,{size:10})})]})]}),e.jsx("div",{className:"px-2 pb-1",children:e.jsxs("div",{className:"flex items-center gap-1.5 bg-surface-800 rounded px-2 py-1",children:[e.jsx(st,{size:10,className:"text-slate-500 flex-shrink-0"}),e.jsx("input",{type:"text",value:b,onChange:h=>V(h.target.value),placeholder:y?"Filter bookmarks…":"Filter tables…",className:"bg-transparent text-xs text-slate-300 placeholder-slate-600 flex-1 outline-none min-w-0"}),b&&e.jsx("button",{onClick:()=>v(""),className:"text-slate-500 hover:text-slate-300",children:e.jsx(ye,{size:10})})]})}),O?e.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-center",children:[e.jsx($e,{size:18,className:"text-slate-700"}),e.jsxs("p",{className:"text-xs text-slate-600",children:["No bookmarks yet.",e.jsx("br",{}),"Hover a table and click ★ to add one."]})]}):K.map(({db:h,tbls:k})=>{const j=f.has(h);return e.jsxs("div",{children:[e.jsxs("button",{className:"flex items-center gap-1.5 w-full px-2 py-1 hover:bg-surface-800 text-slate-300 group",onClick:()=>_(h),onContextMenu:N=>u(N,h),title:h,children:[j?e.jsx(Pe,{size:12,className:"flex-shrink-0"}):e.jsx(tt,{size:12,className:"flex-shrink-0"}),e.jsx(et,{size:12,className:"flex-shrink-0 text-yellow-400"}),e.jsx("span",{className:"text-xs truncate flex-1 text-left",children:h}),e.jsx("span",{role:"button",title:"New query on this database",onClick:N=>{N.stopPropagation(),x(t,h)},className:"opacity-0 group-hover:opacity-100 p-0.5 hover:text-brand-400",children:e.jsx(ie,{size:10})})]}),j&&k.map(N=>{const P=F(h,N.name);return e.jsxs("button",{className:"flex items-center gap-1.5 w-full pl-7 pr-2 py-0.5 hover:bg-surface-800 text-slate-400 hover:text-slate-200 group",onClick:()=>c(t,h,N.name),onContextMenu:J=>u(J,h,N.name),title:N.name,children:[e.jsx(qe,{size:11,className:"flex-shrink-0 text-slate-500"}),e.jsx("span",{className:"text-xs truncate flex-1 text-left",children:N.name}),e.jsx("span",{role:"button",title:P?"Remove bookmark":"Bookmark table",onClick:J=>{J.stopPropagation(),M(h,N.name)},className:`p-0.5 transition-colors ${P?"text-yellow-400":"opacity-0 group-hover:opacity-100 text-slate-500 hover:text-yellow-400"}`,children:e.jsx($e,{size:10,fill:P?"currentColor":"none"})})]},N.name)})]},h)}),m&&e.jsx("div",{className:"fixed bg-surface-800 border border-surface-700 rounded shadow-lg z-50 py-1 w-44",style:{top:m.y,left:m.x},onClick:h=>h.stopPropagation(),children:m.table?e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-surface-700 text-slate-200",onClick:()=>{c(t,m.db,m.table),C()},children:[e.jsx(qe,{size:12})," Open Table"]}),e.jsxs("button",{className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-surface-700 text-slate-200",onClick:()=>{x(t,m.db),C()},children:[e.jsx(ie,{size:12})," New Query"]}),e.jsxs("button",{className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-surface-700 text-slate-200",onClick:()=>{w({db:m.db,table:m.table}),C()},children:[e.jsx(ce,{size:12})," Import CSV"]}),e.jsx("hr",{className:"border-surface-700 my-1"}),e.jsxs("button",{className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-surface-700 text-yellow-400",onClick:()=>z(m.db,m.table),children:[e.jsx(Tt,{size:12})," Truncate"]}),e.jsxs("button",{className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-surface-700 text-red-400",onClick:()=>T(m.db,m.table),children:[e.jsx(Le,{size:12})," Drop Table"]})]}):e.jsxs("button",{className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-surface-700 text-slate-200",onClick:()=>{x(t,m.db),C()},children:[e.jsx(ie,{size:12})," New Query"]})}),$&&e.jsx(ft,{open:!!$,onClose:()=>w(null),sessionId:t,database:$.db,table:$.table})]})}const Cs={sm:"w-7 h-7",md:"w-9 h-9",lg:"w-14 h-14"},ks={sm:"text-sm",md:"text-base",lg:"text-xl"};function mt({size:t="md",showText:a=!0,className:s=""}){return e.jsxs("div",{className:`flex items-center gap-2 ${s}`,children:[e.jsxs("svg",{viewBox:"0 0 128 128",xmlns:"http://www.w3.org/2000/svg",className:`${Cs[t]} flex-shrink-0`,children:[e.jsx("rect",{x:"4",y:"4",width:"120",height:"120",rx:"24",fill:"#f0f9ff"}),e.jsxs("g",{fill:"none",stroke:"#2563eb",strokeWidth:"3",strokeLinecap:"round",children:[e.jsx("path",{d:"M 28 34 Q 38 26 48 34 T 68 34 T 88 34 T 100 34"}),e.jsx("path",{d:"M 28 50 Q 38 42 48 50 T 68 50 T 88 50 T 100 50"}),e.jsx("path",{d:"M 28 66 Q 38 58 48 66 T 68 66 T 88 66 T 100 66"})]}),e.jsxs("g",{fill:"none",stroke:"#0891b2",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("line",{x1:"28",y1:"82",x2:"100",y2:"82"}),e.jsx("line",{x1:"28",y1:"94",x2:"100",y2:"94"}),e.jsx("line",{x1:"52",y1:"82",x2:"52",y2:"94"}),e.jsx("line",{x1:"76",y1:"82",x2:"76",y2:"94"})]}),e.jsx("circle",{cx:"64",cy:"74",r:"3",fill:"#0284c7"})]}),a&&e.jsx("span",{className:`font-semibold text-slate-100 ${ks[t]} tracking-tight`,children:"Lagun"})]})}function Es(){const{sessions:t,activeSessionId:a}=te(),[s,n]=i.useState(!1),[r,o]=i.useState(!1),[l,c]=i.useState(!1);return e.jsxs("aside",{className:"w-full bg-surface-900 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-3 border-b border-surface-800",children:[e.jsx(mt,{size:"sm",showText:!0}),e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>c(!0),title:"Import connections",className:"p-1",children:e.jsx(ce,{size:14})}),e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>o(!0),title:"Export connections",className:"p-1",children:e.jsx(we,{size:14})}),e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>n(!0),title:"New connection",className:"p-1",children:e.jsx(at,{size:14})})]})]}),e.jsx("div",{className:"flex-shrink-0 border-b border-surface-800",children:e.jsx(vs,{onNew:()=>n(!0)})}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:a&&(()=>{const x=t.find(f=>f.id===a);return e.jsx(Ns,{sessionId:a,selectedDatabases:x==null?void 0:x.selected_databases})})()}),e.jsx(xt,{open:s,onClose:()=>n(!1)}),e.jsx(js,{open:r,onClose:()=>o(!1)}),e.jsx(ys,{open:l,onClose:()=>c(!1)})]})}function Ts(){const{tabs:t,activeTabId:a,setActiveTab:s,closeTab:n,openQueryTab:r,closeAllTabs:o}=Z(),{activeSessionId:l}=te();return e.jsxs("div",{className:"flex items-center bg-surface-900 border-b border-surface-800 overflow-x-auto flex-shrink-0",children:[t.map(c=>e.jsxs("button",{onClick:()=>s(c.id),className:ue("flex items-center gap-1.5 px-3 py-2 text-xs border-r border-surface-800 whitespace-nowrap min-w-0 group transition-colors",a===c.id?"bg-surface-950 text-slate-100 border-t-2 border-t-brand-500":"text-slate-400 hover:text-slate-200 hover:bg-surface-800"),children:[c.type==="query"?e.jsx(ie,{size:12,className:"flex-shrink-0"}):e.jsx($t,{size:12,className:"flex-shrink-0"}),e.jsx("span",{className:"truncate max-w-[120px]",children:c.label}),e.jsx("span",{role:"button",onClick:x=>{x.stopPropagation(),n(c.id)},className:"ml-0.5 opacity-0 group-hover:opacity-100 hover:text-red-400 transition-opacity",children:e.jsx(ye,{size:10})})]},c.id)),l&&e.jsxs("button",{onClick:()=>r(l),title:"New query tab",className:"flex items-center gap-1 px-3 py-2 text-xs text-slate-500 hover:text-slate-200 hover:bg-surface-800 transition-colors whitespace-nowrap flex-shrink-0 border-r border-surface-800",children:[e.jsx(at,{size:12}),"New Query"]}),t.length>0&&e.jsxs("button",{onClick:o,title:"Close all tabs",className:"flex items-center gap-1 px-3 py-2 text-xs text-slate-500 hover:text-red-400 hover:bg-surface-800 transition-colors whitespace-nowrap flex-shrink-0 ml-auto",children:[e.jsx(_t,{size:12}),"Close All"]})]})}const $s="modulepreload",_s=function(t){return"/"+t},He={},Me=function(a,s,n){let r=Promise.resolve();if(s&&s.length>0){document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),c=(l==null?void 0:l.nonce)||(l==null?void 0:l.getAttribute("nonce"));r=Promise.allSettled(s.map(x=>{if(x=_s(x),x in He)return;He[x]=!0;const f=x.endsWith(".css"),d=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${x}"]${d}`))return;const b=document.createElement("link");if(b.rel=f?"stylesheet":$s,f||(b.as="script"),b.crossOrigin="",b.href=x,c&&b.setAttribute("nonce",c),document.head.appendChild(b),f)return new Promise((v,y)=>{b.addEventListener("load",v),b.addEventListener("error",()=>y(new Error(`Unable to preload CSS for ${x}`)))})}))}function o(l){const c=new Event("vite:preloadError",{cancelable:!0});if(c.payload=l,window.dispatchEvent(c),!c.defaultPrevented)throw l}return r.then(l=>{for(const c of l||[])c.status==="rejected"&&o(c.reason);return a().catch(o)})};function Ds(){var t;return((t=crypto.randomUUID)==null?void 0:t.call(crypto))??"10000000-1000-4000-8000-100000000000".replace(/[018]/g,a=>(+a^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+a/4).toString(16))}const Fe=Ne()(Oe(t=>({entries:[],addEntry:a=>t(s=>({entries:[{...a,id:Ds(),timestamp:new Date().toISOString()},...s.entries].slice(0,200)})),clearLog:()=>t({entries:[]})}),{name:"lagun-query-log",version:1,partialize:t=>({entries:t.entries})})),Is=[100,500,1e3,5e3,1e4];function Rs({value:t,onChange:a,onRun:s,running:n,database:r,databases:o,onDatabaseChange:l,schema:c,limit:x,onLimitChange:f,editorRef:d}){const b=i.useRef(c??{});b.current=c??{};const v=i.useRef(s);v.current=s;const y=i.useRef(n);y.current=n;const S=i.useMemo(()=>[Je({dialect:xe,defaultSchema:r}),xe.language.data.of({autocomplete:p=>yt({dialect:xe,schema:b.current,defaultSchema:r})(p)})],[r]),m=i.useMemo(()=>Ve.highest(Ke.of([{key:"Ctrl-Enter",mac:"Cmd-Enter",run:()=>(y.current||v.current(),!0)}])),[]);return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-surface-900 border-b border-surface-800",children:[e.jsx("div",{className:"flex items-center gap-2",children:o&&o.length>0?e.jsxs("select",{value:r??"",onChange:p=>l==null?void 0:l(p.target.value),className:ue("bg-surface-800 border rounded px-2 py-0.5 text-xs focus:outline-none focus:ring-1 focus:ring-brand-500",r?"border-surface-700 text-slate-300":"border-amber-600 text-amber-400"),children:[!r&&e.jsx("option",{value:"",disabled:!0,children:"Select database…"}),o.map(p=>e.jsx("option",{value:p,children:p},p))]}):r?e.jsx("span",{className:"text-xs text-slate-500 bg-surface-800 px-2 py-0.5 rounded",children:r}):null}),e.jsxs("div",{className:"flex items-center gap-2",children:[f&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-slate-500",children:[e.jsx("span",{children:"Limit"}),e.jsx("select",{value:x,onChange:p=>f(Number(p.target.value)),className:"bg-surface-800 border border-surface-700 rounded px-1.5 py-0.5 text-xs text-slate-300 focus:outline-none focus:ring-1 focus:ring-brand-500",children:Is.map(p=>e.jsx("option",{value:p,children:p.toLocaleString()},p))})]}),e.jsx("kbd",{className:"hidden sm:inline-flex items-center px-1.5 py-0.5 text-[10px] font-mono text-slate-500 bg-surface-800 border border-surface-700 rounded",children:"Ctrl+↵"}),e.jsxs(W,{variant:"primary",size:"sm",onClick:s,disabled:n||!t.trim(),title:"Run (Ctrl+Enter)",children:[n?e.jsx(le,{size:12,className:"animate-spin"}):e.jsx(Dt,{size:12}),"Run"]})]})]}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(Ge,{ref:d,value:t,onChange:a,extensions:[S,wt.lineWrapping,m],theme:Xe,className:"h-full text-sm",style:{height:"100%"},basicSetup:{lineNumbers:!0,highlightActiveLine:!0,autocompletion:!0,foldGutter:!0}})})]})}function zs({x:t,y:a,items:s,onClose:n}){const r=i.useRef(null),[o,l]=i.useState({left:t,top:a});return i.useLayoutEffect(()=>{if(!r.current)return;const{width:c,height:x}=r.current.getBoundingClientRect();l({left:Math.min(t,window.innerWidth-c-8),top:Math.min(a,window.innerHeight-x-8)})},[t,a]),i.useEffect(()=>{const c=f=>{f.key==="Escape"&&n()},x=f=>{r.current&&!r.current.contains(f.target)&&n()};return window.addEventListener("keydown",c),window.addEventListener("mousedown",x),()=>{window.removeEventListener("keydown",c),window.removeEventListener("mousedown",x)}},[n]),ot.createPortal(e.jsx("div",{ref:r,className:"fixed z-[9999] bg-surface-900 border border-surface-700 rounded-md shadow-2xl py-1 min-w-[180px]",style:{left:o.left,top:o.top},onContextMenu:c=>c.preventDefault(),children:s.map((c,x)=>c.type==="separator"?e.jsx("div",{className:"border-t border-surface-700 my-1"},x):e.jsxs("button",{className:`flex items-center gap-2 w-full px-3 py-1.5 text-xs text-left ${c.danger?"text-red-400 hover:bg-red-950/40":"text-slate-300 hover:bg-surface-800"}`,onClick:c.onClick,children:[c.icon,c.label]},x))}),document.body)}async function ze(t){if(navigator.clipboard){await navigator.clipboard.writeText(t);return}const a=document.createElement("textarea");a.value=t,a.style.position="fixed",a.style.opacity="0",document.body.appendChild(a),a.focus(),a.select();const s=document.execCommand("copy");if(document.body.removeChild(a),!s)throw new Error("Copy failed")}const Ls=Ft.withParams({backgroundColor:"#0f172a",foregroundColor:"#cbd5e1",headerBackgroundColor:"#1e293b",headerTextColor:"#94a3b8",borderColor:"#1e293b",rowHoverColor:"#1e293b",selectedRowBackgroundColor:"#1e3a5f",oddRowBackgroundColor:"#0f172a",fontFamily:"ui-monospace, monospace",fontSize:12,cellTextColor:"#cbd5e1",headerFontSize:12,headerFontWeight:600}),Ps=new Set(["datetime","timestamp","date","time"]);function Os(t){const a=o=>String(o).padStart(2,"0"),s=new Date,n=`${s.getFullYear()}-${a(s.getMonth()+1)}-${a(s.getDate())}`,r=`${a(s.getHours())}:${a(s.getMinutes())}:${a(s.getSeconds())}`;return t==="date"?n:t==="time"?r:`${n} ${r}`}const ht=i.forwardRef(function({result:a,onCellEdit:s,primaryKeyColumns:n=[],editable:r=!1,selectable:o,onSelectionChange:l,columns:c,onDeleteRows:x},f){const[d,b]=i.useState(null),v=i.useRef(null),y=i.useRef(null),S=i.useRef(new Set),m=i.useRef(null);i.useImperativeHandle(f,()=>({isAnyFilterPresent:()=>{var u;return((u=y.current)==null?void 0:u.isAnyFilterPresent())??!1},getFilteredData:()=>{var C;const u=[];return(C=y.current)==null||C.forEachNodeAfterFilterAndSort(T=>{T.data&&u.push(a.columns.map(z=>T.data[z]??null))}),{columns:a.columns,rows:u}}}));const p=i.useMemo(()=>a.columns.map(u=>({field:u,headerName:u,editable:r&&u!=="__rowIndex",resizable:!0,sortable:!0,filter:!0,cellStyle:{fontFamily:"ui-monospace, monospace",fontSize:"12px"},headerClass:"text-xs font-semibold"})),[a.columns,r]),$=i.useMemo(()=>a.rows.map((u,C)=>{const T={__ag_rowId:String(C)};return a.columns.forEach((z,O)=>{T[z]=u[O]}),T}),[a.rows,a.columns]),w=i.useCallback(u=>u.data.__ag_rowId,[]),I=i.useMemo(()=>o?{mode:"multiRow",checkboxes:!0,headerCheckbox:!0,enableClickSelection:!1}:void 0,[o]),M=i.useMemo(()=>({minWidth:80,flex:1}),[]),F=i.useCallback(u=>{!s||!u.colDef.field||s({column:u.colDef.field,newValue:u.newValue,data:u.data})},[s]),U=i.useCallback(u=>{l==null||l(u.api.getSelectedRows())},[l]),V=i.useCallback(u=>{const C=u.event;if(!(C!=null&&C.shiftKey)){v.current=u.rowIndex??null;return}const T=u.rowIndex??0,z=v.current??T,O=Math.min(z,T),h=Math.max(z,T);u.api.deselectAll(),u.api.forEachNode(k=>{k.rowIndex!==null&&k.rowIndex>=O&&k.rowIndex<=h&&k.setSelected(!0)})},[]),_=i.useCallback(u=>{const C=u.column.getColId();S.current.has(C)?(u.api.applyColumnState({state:[{colId:C,flex:1}]}),S.current.delete(C)):(u.api.autoSizeColumn(C),u.column.getActualWidth()>400&&u.api.setColumnWidth(C,400),S.current.add(C))},[]),G=i.useCallback(u=>{var O;if(!("getActualWidth"in u.column))return;const C=u.column,T=C.getColId(),z=Date.now();((O=m.current)==null?void 0:O.colId)===T&&z-m.current.time<300?(_({column:C,api:u.api}),m.current=null):m.current={colId:T,time:z}},[_]),H=i.useCallback(u=>{u.finished&&u.source==="uiColumnDragged"&&u.column&&S.current.delete(u.column.getColId())},[]),q=i.useCallback(u=>{const C=u.event;if(!C)return;C.preventDefault();const T=u.api.getSelectedRows();b({x:C.clientX,y:C.clientY,columnName:u.colDef.field??"",cellValue:u.value,rowData:u.data??{},selectedRows:T})},[]),D=i.useCallback(()=>b(null),[]),K=i.useMemo(()=>{if(!d)return[];const u=c==null?void 0:c.find(k=>k.name===d.columnName),C=u&&Ps.has(u.data_type.toLowerCase()),T=d.selectedRows.length>0?d.selectedRows:[d.rowData],{__ag_rowId:z,...O}=d.rowData,h=[{type:"item",label:"Copy cell",icon:e.jsx(rt,{size:12}),onClick:()=>{ze(String(d.cellValue??"")).catch(()=>{}),D()}},{type:"item",label:"Copy row as JSON",icon:e.jsx(Rt,{size:12}),onClick:()=>{ze(JSON.stringify(O,null,2)).catch(()=>{}),D()}}];if(r&&(u!=null&&u.is_nullable&&(h.push({type:"separator"}),h.push({type:"item",label:"Set to NULL",icon:e.jsx(It,{size:12}),onClick:()=>{s==null||s({column:d.columnName,newValue:null,data:d.rowData}),D()}})),C)){const k=Os(u.data_type.toLowerCase());h.push({type:"item",label:`Set to NOW()  ${k}`,icon:e.jsx(nt,{size:12}),onClick:()=>{s==null||s({column:d.columnName,newValue:k,data:d.rowData}),D()}})}if(x&&n.length>0){const k=T.length>1?`Delete ${T.length} rows`:"Delete row";h.push({type:"separator"}),h.push({type:"item",label:k,danger:!0,icon:e.jsx(Le,{size:12}),onClick:()=>{x(T),D()}})}return h},[d,c,r,s,x,n,D]);return a.error?e.jsx("div",{className:"p-4 bg-red-950/50 border border-red-800 rounded m-3",children:e.jsx("p",{className:"text-xs font-mono text-red-300",children:a.error})}):e.jsxs("div",{className:"h-full",children:[e.jsx(qt,{theme:Ls,columnDefs:p,rowData:$,getRowId:w,onGridReady:u=>{y.current=u.api},onCellValueChanged:F,onSelectionChanged:U,onRowClicked:o?V:void 0,onColumnHeaderClicked:G,onColumnResized:H,onCellContextMenu:q,onBodyScroll:D,defaultColDef:M,rowSelection:I,suppressContextMenu:!0,preventDefaultOnContextMenu:!0,stopEditingWhenCellsLoseFocus:!0}),d&&e.jsx(zs,{x:d.x,y:d.y,items:K,onClose:D})]})});function pt({result:t,running:a}){return a?e.jsx("div",{className:"flex items-center gap-3 px-3 py-1.5 bg-surface-900 border-t border-surface-800 text-xs text-slate-400",children:e.jsx("span",{className:"animate-pulse",children:"Executing..."})}):t?e.jsx("div",{className:"flex items-center gap-4 px-3 py-1.5 bg-surface-900 border-t border-surface-800 text-xs",children:t.error?e.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[e.jsx(zt,{size:11})," Error"]}):e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flex items-center gap-1 text-slate-400",children:[e.jsx(Lt,{size:11}),t.row_count.toLocaleString()," ",t.row_count===1?"row":"rows"]}),t.affected_rows!=null&&e.jsxs("span",{className:"text-slate-400",children:[t.affected_rows," affected"]}),e.jsxs("span",{className:"flex items-center gap-1 text-slate-500",children:[e.jsx(nt,{size:11}),t.exec_time_ms,"ms"]}),t.insert_id?e.jsxs("span",{className:"text-slate-500",children:["insert_id=",t.insert_id]}):null]})}):null}const Ms=i.lazy(()=>Me(()=>import("./TableSchemaView-pRJlVnGW.js"),__vite__mapDeps([0,1,2,3]))),bt=i.lazy(()=>Me(()=>import("./ExportDialog-bc6i1d15.js"),__vite__mapDeps([4,1,2,3]))),Fs=i.lazy(()=>Me(()=>Promise.resolve().then(()=>ws),void 0)),qs=[100,500,1e3,5e3,1e4];function As({tab:t}){return t.type==="query"?e.jsx(Qs,{tab:t}):e.jsx(Ws,{tab:t})}function Bs(t){const a=[];let s="",n=!1,r=!1,o=!1,l=!1,c=!1;for(let f=0;f<t.length;f++){const d=t[f],b=t[f+1];if(l){s+=d,d===`
`&&(l=!1);continue}if(c){d==="*"&&b==="/"?(s+="*/",f++,c=!1):s+=d;continue}if(n){s+=d,d==="'"&&b==="'"?(s+=b,f++):d==="'"&&(n=!1);continue}if(r){s+=d,d==='"'&&(r=!1);continue}if(o){s+=d,d==="`"&&(o=!1);continue}if(d==="-"&&b==="-"){l=!0,s+="--",f++;continue}if(d==="/"&&b==="*"){c=!0,s+="/*",f++;continue}if(d==="'"){n=!0,s+=d;continue}if(d==='"'){r=!0,s+=d;continue}if(d==="`"){o=!0,s+=d;continue}if(d===";"){const v=s.trim();v&&a.push(v),s="";continue}s+=d}const x=s.trim();return x&&a.push(x),a}function Qs({tab:t}){var k;const a=Z(j=>{var N;return((N=j.tabs.find(P=>P.id===t.id))==null?void 0:N.sql)??""}),s=Z(j=>j.setSql),[n,r]=i.useState(a),o=i.useRef(n);o.current=n,i.useEffect(()=>{const j=setTimeout(()=>s(t.id,n),500);return()=>clearTimeout(j)},[n,t.id,s]),i.useEffect(()=>()=>{s(t.id,o.current)},[t.id,s]),i.useEffect(()=>{r(a)},[t.id]);const[l,c]=i.useState([]),[x,f]=i.useState(0),[d,b]=i.useState(!1),[v,y]=i.useState(1e3),[S,m]=i.useState(!1),[p,$]=i.useState(),w=i.useRef(null),I=i.useRef(null),{tables:M,columns:F,databases:U,loadDatabases:V,loadTables:_,loadColumns:G}=me(),H=Z(j=>j.setTabDatabase),q=Z(j=>j.pendingSqls[t.id]),D=Z(j=>j.consumePendingSql),K=Fe(j=>j.addEntry);i.useEffect(()=>{q!==void 0&&(r(q.sql),q.database&&H(t.id,q.database),D(t.id))},[q]);const u=te(j=>j.sessions.find(N=>N.id===t.sessionId)),C=U[t.sessionId]??[],T=(k=u==null?void 0:u.selected_databases)!=null&&k.length?C.filter(j=>u.selected_databases.includes(j)):C,z=t.database&&!T.includes(t.database)?[...T,t.database]:T;i.useEffect(()=>{V(t.sessionId)},[t.sessionId]);const O=i.useMemo(()=>{if(!t.database)return{};const j=M[`${t.sessionId}/${t.database}`]??[],N={};for(const P of j){const J=`${t.sessionId}/${t.database}/${P.name}`;N[P.name]=(F[J]??[]).map(X=>X.name)}return N},[t.sessionId,t.database,M,F]);i.useEffect(()=>{t.database&&_(t.sessionId,t.database)},[t.sessionId,t.database]),i.useEffect(()=>{if(!t.database)return;const j=setTimeout(()=>{const N=[...n.matchAll(/(?:FROM|JOIN|INTO|UPDATE|TABLE)\s+`?(?:\w+`?\.`?)?(\w+)`?/gi)],P=[...n.matchAll(/,\s*`?(?:\w+`?\.`?)?(\w+)`?\s*(?:AS\s+\w+\s*)?(?:,|WHERE\b|SET\b|ON\b|$)/gi)],J=[...new Set([...N,...P].map(X=>X[1]))];for(const X of J)G(t.sessionId,t.database,X)},300);return()=>clearTimeout(j)},[n,t.sessionId,t.database]);const h=async()=>{var se;if(!n.trim())return;const j=(se=I.current)==null?void 0:se.view,P=(j?j.state.sliceDoc(j.state.selection.main.from,j.state.selection.main.to).trim():"")||n.trim(),J=Bs(P);if(J.length===0)return;b(!0);const X=[];try{for(const ae of J){const re=Date.now(),ee=await B.executeQuery(t.sessionId,ae,t.database,v);if(X.push(ee),K({sql:ae,sessionId:t.sessionId,database:t.database,rowCount:ee.row_count??void 0,execTimeMs:ee.exec_time_ms??Date.now()-re,error:ee.error??void 0}),ee.error)break}}finally{c(X),f(0),b(!1)}};return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"h-48 flex-shrink-0 border-b border-surface-800",children:e.jsx(Rs,{value:n,onChange:r,onRun:h,running:d,database:t.database,databases:z,onDatabaseChange:j=>H(t.id,j),schema:O,limit:v,onLimitChange:y,editorRef:I})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[l.length>1&&e.jsx("div",{className:"flex flex-shrink-0 bg-surface-900 border-b border-surface-800 overflow-x-auto",children:l.map((j,N)=>e.jsx("button",{onClick:()=>f(N),className:`px-3 py-1 text-xs whitespace-nowrap border-r border-surface-800 transition-colors ${x===N?"bg-surface-950 text-slate-200 border-t-2 border-t-brand-500":"text-slate-400 hover:text-slate-200 hover:bg-surface-800"}`,children:j.error?`✗ Result ${N+1}`:j.columns.length>0?`Result ${N+1} (${j.row_count} rows)`:`Result ${N+1} (${j.affected_rows??0} affected)`},N))}),e.jsx("div",{className:"flex-1 overflow-hidden",children:l.length>0?e.jsx(ht,{ref:w,result:l[x]},x):e.jsx("div",{className:"flex items-center justify-center h-full text-slate-600 text-sm",children:"Press Ctrl+Enter to run a query"})})]}),e.jsxs("div",{className:"flex items-center border-t border-surface-800",children:[e.jsx("div",{className:"flex-1",children:e.jsx(pt,{result:l[x]??null,running:d})}),l[x]&&!l[x].error&&l[x].columns.length>0&&e.jsxs("button",{onClick:()=>{var j;$((j=w.current)!=null&&j.isAnyFilterPresent()?w.current.getFilteredData():void 0),m(!0)},className:"flex items-center gap-1 px-3 py-1.5 text-xs text-slate-500 hover:text-slate-300 transition-colors",title:"Export result",children:[e.jsx(we,{size:11})," Export"]})]}),S&&t.database&&n.trim()&&e.jsx(i.Suspense,{fallback:null,children:e.jsx(bt,{open:S,onClose:()=>m(!1),sessionId:t.sessionId,database:t.database,table:"result",sql:n.trim(),rowsOverride:p})})]})}function Ws({tab:t}){const[a,s]=i.useState("schema"),[n,r]=i.useState(null),[o,l]=i.useState([]),[c,x]=i.useState(!1),[f,d]=i.useState(!1),[b,v]=i.useState(1e3),[y,S]=i.useState(null),[m,p]=i.useState([]),[$,w]=i.useState(!1),[I,M]=i.useState(),F=i.useRef(null),[U,V]=i.useState(!1),[_,G]=i.useState(""),[H,q]=i.useState(""),[D,K]=i.useState(""),[u,C]=i.useState(!1),T=Fe(E=>E.addEntry),z=o.filter(E=>E.is_primary_key).map(E=>E.name),O=z.length>0?z:o.map(E=>E.name),h=async(E,Q,L)=>{if(!t.database||!t.table)return;const g=E??b,A=Q!==void 0?Q:_,oe=L!==void 0?L:D;p([]),n===null?x(!0):d(!0);const ke=Date.now();try{const Ee=await B.getColumns(t.sessionId,t.database,t.table);l(Ee);let Te=`SELECT * FROM \`${t.database}\`.\`${t.table}\``;const he=[];if(A.trim()&&Ee.length>0){const gt=A.replace(/\\/g,"\\\\").replace(/'/g,"''").replace(/%/g,"\\%").replace(/_/g,"\\_"),vt=Ee.map(jt=>`\`${jt.name}\` LIKE '%${gt}%'`);he.push(`(${vt.join(" OR ")})`)}oe.trim()&&he.push(`(${oe.trim()})`),he.length>0&&(Te+=` WHERE ${he.join(" AND ")}`);const pe=await B.executeQuery(t.sessionId,Te,void 0,g);r(pe),T({sql:Te,sessionId:t.sessionId,database:t.database,rowCount:pe.row_count??void 0,execTimeMs:pe.exec_time_ms??Date.now()-ke,error:pe.error??void 0})}finally{x(!1),d(!1)}};i.useEffect(()=>{a==="data"&&!n&&h()},[a]),i.useEffect(()=>{s("schema"),r(null),l([]),G(""),q(""),K(""),C(!1)},[t.sessionId,t.database,t.table]),i.useEffect(()=>{if(a!=="data")return;const E=setTimeout(()=>{h(void 0,_,D)},400);return()=>clearTimeout(E)},[_]);const k=async E=>{if(!t.database||!t.table||O.length===0)return;const Q={};O.forEach(A=>{Q[A]=E.data[A]});const L=Date.now(),g=await B.cellUpdate(t.sessionId,{database:t.database,table:t.table,primary_key:Q,column:E.column,new_value:E.newValue});g.ok?(S(`✓ ${g.sql_executed}`),T({sql:g.sql_executed,sessionId:t.sessionId,database:t.database,affectedRows:g.affected_rows??void 0,execTimeMs:Date.now()-L}),h()):(S(`✗ ${g.error}`),T({sql:g.sql_executed||`UPDATE ${t.database}.${t.table}`,sessionId:t.sessionId,database:t.database,execTimeMs:Date.now()-L,error:g.error??void 0})),setTimeout(()=>S(null),4e3)},j=async E=>{if(!t.database||!t.table||O.length===0)return;const Q=E.map(g=>Object.fromEntries(O.map(A=>[A,g[A]]))),L=await B.rowDelete(t.sessionId,{database:t.database,table:t.table,primary_keys:Q});L.ok?(S(`✓ Deleted ${L.affected_rows} row${L.affected_rows!==1?"s":""}`),T({sql:`DELETE FROM \`${t.database}\`.\`${t.table}\` (${L.affected_rows} row${L.affected_rows!==1?"s":""})`,sessionId:t.sessionId,database:t.database,affectedRows:L.affected_rows,execTimeMs:0}),h()):S(`✗ ${L.error}`),setTimeout(()=>S(null),4e3)},N=E=>{v(E),n&&h(E)},P=i.useCallback(()=>{K(H),h(void 0,_,H)},[H,_]),J=()=>{q(""),K(""),h(void 0,_,"")},X=()=>{G("")},se=i.useRef(P);se.current=P;const ae=i.useMemo(()=>Je({dialect:xe}),[]),re=i.useMemo(()=>{const E=o.map(Q=>({label:Q.name,type:"property",boost:99}));return xe.language.data.of({autocomplete:Q=>{const L=Q.matchBefore(/\w+/);return!L&&!Q.explicit?null:{from:L?L.from:Q.pos,options:E,validFor:/^\w*$/}}})},[o]),ee=i.useMemo(()=>Ve.highest(Ke.of([{key:"Enter",run:()=>(se.current(),!0)},{key:"Mod-Enter",run:()=>(se.current(),!0)}])),[]);return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-surface-900 border-b border-surface-800",children:[e.jsxs("span",{className:"text-xs text-slate-400",children:[t.database,".",t.table]}),e.jsx("div",{className:"flex-1"}),a==="data"&&e.jsxs("div",{className:"relative flex items-center",children:[e.jsx(st,{size:11,className:"absolute left-2 text-slate-500 pointer-events-none"}),e.jsx("input",{type:"text",value:_,onChange:E=>G(E.target.value),placeholder:"Search all columns…",className:"bg-surface-800 border border-surface-700 rounded pl-6 pr-6 py-0.5 text-xs text-slate-300 placeholder-slate-600 focus:outline-none focus:ring-1 focus:ring-brand-500 w-44"}),_&&e.jsx("button",{onClick:X,className:"absolute right-1.5 text-slate-500 hover:text-slate-300",children:e.jsx(ye,{size:10})})]}),a==="data"&&e.jsxs("button",{onClick:()=>C(E=>!E),className:`flex items-center gap-1 px-2 py-0.5 text-xs rounded transition-colors ${u||D?"text-brand-400 bg-brand-950 border border-brand-800":"text-slate-500 hover:text-slate-300"}`,title:"Toggle WHERE filter",children:[e.jsx(Pt,{size:11}),D?"Filtered":"Filter"]}),a==="data"&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-slate-500",children:[e.jsx("span",{children:"Limit"}),e.jsx("select",{value:b,onChange:E=>N(Number(E.target.value)),className:"bg-surface-800 border border-surface-700 rounded px-1.5 py-0.5 text-xs text-slate-300 focus:outline-none focus:ring-1 focus:ring-brand-500",children:qs.map(E=>e.jsx("option",{value:E,children:E.toLocaleString()},E))})]}),a==="data"&&f&&e.jsx(je,{size:12,className:"animate-spin text-slate-400"}),e.jsxs("div",{className:"flex rounded overflow-hidden border border-surface-700",children:[e.jsx("button",{className:`px-2.5 py-0.5 text-xs transition-colors ${a==="schema"?"bg-brand-600 text-white":"bg-surface-800 text-slate-400 hover:text-slate-200"}`,onClick:()=>s("schema"),children:"Schema"}),e.jsx("button",{className:`px-2.5 py-0.5 text-xs transition-colors ${a==="data"?"bg-brand-600 text-white":"bg-surface-800 text-slate-400 hover:text-slate-200"}`,onClick:()=>s("data"),children:"Data"})]}),a==="data"&&e.jsxs("button",{onClick:()=>V(!0),className:"flex items-center gap-1 px-2 py-0.5 text-xs text-slate-500 hover:text-slate-300 transition-colors",title:"Import data",children:[e.jsx(ce,{size:11})," Import"]}),a==="data"&&n&&!n.error&&e.jsxs("button",{onClick:()=>{var E;m.length===0&&((E=F.current)!=null&&E.isAnyFilterPresent())?M(F.current.getFilteredData()):M(void 0),w(!0)},className:"flex items-center gap-1 px-2 py-0.5 text-xs text-slate-500 hover:text-slate-300 transition-colors",title:"Export data",children:[e.jsx(we,{size:11})," Export"]}),a==="data"&&e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>h(),title:"Refresh",disabled:c||f,children:e.jsx(je,{size:12,className:c||f?"animate-spin":""})})]}),a==="data"&&u&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-surface-900 border-b border-surface-700",children:[e.jsx("span",{className:"text-xs text-slate-500 font-mono shrink-0",children:"WHERE"}),e.jsx("div",{className:"flex-1 rounded overflow-hidden border border-surface-700 focus-within:ring-1 focus-within:ring-brand-500",children:e.jsx(Ge,{value:H,onChange:E=>{q(E),!E.trim()&&D&&(K(""),h(void 0,_,""))},extensions:[ae,re,ee],theme:Xe,height:"28px",placeholder:"e.g. id = 5 AND name LIKE 'John%'",basicSetup:{lineNumbers:!1,foldGutter:!1,highlightActiveLine:!1,autocompletion:!0}})}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx("kbd",{className:"hidden sm:inline-flex items-center px-1.5 py-0.5 text-[10px] font-mono text-slate-500 bg-surface-800 border border-surface-700 rounded",children:"Ctrl+↵"}),e.jsx("button",{onClick:P,className:"px-2.5 py-0.5 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded transition-colors",children:"Apply"})]}),D&&e.jsx("button",{onClick:J,className:"px-2 py-0.5 text-xs text-slate-500 hover:text-slate-300 transition-colors shrink-0",children:"Clear"})]}),e.jsx("div",{className:"flex-1 overflow-hidden",children:a==="schema"&&t.database&&t.table?e.jsx(i.Suspense,{fallback:e.jsx("div",{className:"flex items-center justify-center h-full text-slate-500 text-sm",children:"Loading schema…"}),children:e.jsx(Ms,{sessionId:t.sessionId,database:t.database,table:t.table})}):a==="data"?c?e.jsxs("div",{className:"flex items-center justify-center h-full text-slate-500 text-sm",children:["Loading ",t.table,"…"]}):n?e.jsx(ht,{ref:F,result:n,editable:o.length>0,primaryKeyColumns:O,onCellEdit:k,onDeleteRows:j,selectable:!0,onSelectionChange:p,columns:o}):e.jsx("div",{className:"flex items-center justify-center h-full text-slate-600 text-sm",children:"No data loaded"}):null}),y&&e.jsx("div",{className:"px-3 py-1.5 bg-surface-900 border-t border-surface-800",children:e.jsx("p",{className:"text-xs font-mono text-slate-400 truncate",children:y})}),a==="data"&&n&&e.jsx(pt,{result:n,running:!1}),$&&t.database&&t.table&&e.jsx(i.Suspense,{fallback:null,children:e.jsx(bt,{open:$,onClose:()=>w(!1),sessionId:t.sessionId,database:t.database,table:t.table,pkValues:m.length>0?m.map(E=>{const Q=z.length>0?z:o.map(L=>L.name);return Object.fromEntries(Q.map(L=>[L,E[L]]))}):void 0,rowsOverride:I,pkColumnsForSql:z})}),U&&t.database&&e.jsx(i.Suspense,{fallback:null,children:e.jsx(Fs,{open:U,onClose:()=>V(!1),sessionId:t.sessionId,database:t.database,table:t.table,onImportComplete:()=>h()})})]})}function Us(t){const a=new Date(t),s=String(a.getHours()).padStart(2,"0"),n=String(a.getMinutes()).padStart(2,"0"),r=String(a.getSeconds()).padStart(2,"0");return`${s}:${n}:${r}`}function Hs(t){return t.affectedRows!=null?`${t.affectedRows} affected`:t.rowCount!=null?`${t.rowCount} rows`:"—"}function Js(){const[t,a]=i.useState(!1),{entries:s,clearLog:n}=Fe(),{tabs:r,activeTabId:o,injectSqlToTab:l,openQueryTabWithSql:c}=Z(),x=r.find(d=>d.id===o),f=(x==null?void 0:x.type)==="query";return e.jsxs("div",{className:"flex-shrink-0 border-t border-surface-800 bg-surface-950",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 h-7 cursor-pointer select-none",onClick:()=>a(d=>!d),children:[e.jsx(ie,{size:12,className:"text-slate-500"}),e.jsx("span",{className:"text-xs text-slate-400 font-medium",children:"Query Log"}),s.length>0&&e.jsx("span",{className:"text-xs bg-surface-800 text-slate-400 rounded px-1 py-0.5 leading-none",children:s.length}),e.jsx("div",{className:"flex-1"}),t&&s.length>0&&e.jsx("button",{onClick:d=>{d.stopPropagation(),n()},className:"text-xs text-slate-500 hover:text-slate-300 transition-colors px-1",children:"Clear"}),t?e.jsx(Pe,{size:12,className:"text-slate-500"}):e.jsx(Ot,{size:12,className:"text-slate-500"})]}),t&&e.jsx("div",{className:"h-[180px] overflow-y-auto",children:s.length===0?e.jsx("div",{className:"flex items-center justify-center h-full text-slate-600 text-xs",children:"No queries logged yet"}):e.jsxs("table",{className:"w-full text-xs border-collapse",children:[e.jsx("thead",{className:"sticky top-0 bg-surface-900",children:e.jsxs("tr",{className:"text-slate-500",children:[e.jsx("th",{className:"text-left px-2 py-1 font-medium w-16",children:"Time"}),e.jsx("th",{className:"text-left px-2 py-1 font-medium",children:"SQL"}),e.jsx("th",{className:"text-left px-2 py-1 font-medium w-24",children:"Rows"}),e.jsx("th",{className:"text-left px-2 py-1 font-medium w-16",children:"ms"}),e.jsx("th",{className:"text-left px-2 py-1 font-medium w-12",children:"Status"}),e.jsx("th",{className:"w-14"})]})}),e.jsx("tbody",{children:s.map(d=>e.jsxs("tr",{className:`border-t border-surface-800 ${d.error?"bg-red-950/30":""}`,children:[e.jsx("td",{className:"px-2 py-0.5 text-slate-500 tabular-nums whitespace-nowrap",children:Us(d.timestamp)}),e.jsx("td",{className:"px-2 py-0.5 font-mono text-slate-300 w-full break-all",children:d.sql}),e.jsx("td",{className:"px-2 py-0.5 text-slate-400 tabular-nums whitespace-nowrap",children:Hs(d)}),e.jsx("td",{className:"px-2 py-0.5 text-slate-400 tabular-nums whitespace-nowrap",children:d.execTimeMs}),e.jsx("td",{className:"px-2 py-0.5 whitespace-nowrap",children:d.error?e.jsx("span",{className:"text-red-400",title:d.error,children:"✗"}):e.jsx("span",{className:"text-green-400",children:"✓"})}),e.jsx("td",{className:"px-2 py-0.5 whitespace-nowrap",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>ze(d.sql).catch(()=>{}),title:"Copy SQL",className:"p-0.5 text-slate-600 hover:text-slate-300 transition-colors",children:e.jsx(rt,{size:10})}),e.jsx("button",{onClick:()=>{f?l(o,d.sql,d.database):c(d.sessionId,d.sql,d.database)},title:f?"Load into editor":"Open in new query tab",className:"p-0.5 text-slate-600 hover:text-brand-400 transition-colors",children:e.jsx(Mt,{size:10})})]})})]},d.id))})]})})]})}const Vs=160,Ks=520;function Gs(){const{tabs:t,activeTabId:a}=Z(),[s,n]=i.useState(()=>{const l=localStorage.getItem("lagun-sidebar-width");return l?Number(l):256}),r=i.useRef(null),o=l=>{l.preventDefault(),r.current={x:l.clientX,width:s};const c=f=>{if(!r.current)return;const d=Math.max(Vs,Math.min(Ks,r.current.width+f.clientX-r.current.x));n(d),localStorage.setItem("lagun-sidebar-width",String(d))},x=()=>{r.current=null,document.removeEventListener("mousemove",c),document.removeEventListener("mouseup",x)};document.addEventListener("mousemove",c),document.addEventListener("mouseup",x)};return e.jsxs("div",{className:"flex h-screen overflow-hidden bg-surface-950 text-slate-100",children:[e.jsxs("div",{style:{width:s},className:"flex-shrink-0 flex",children:[e.jsx(Es,{}),e.jsx("div",{onMouseDown:o,className:"w-1 flex-shrink-0 bg-surface-800 hover:bg-brand-500 cursor-col-resize transition-colors"})]}),e.jsxs("div",{className:"flex flex-col flex-1 min-w-0 overflow-hidden",children:[e.jsx(Ts,{}),e.jsx("div",{className:"flex-1 overflow-hidden",children:t.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-slate-500 gap-4",children:[e.jsx(mt,{size:"lg",showText:!1,className:"opacity-40"}),e.jsx("p",{className:"text-sm",children:"Select a table from the sidebar or open a query tab"})]}):t.map(l=>e.jsx("div",{className:`h-full ${a===l.id?"":"hidden"}`,children:e.jsx(As,{tab:l})},l.id))}),e.jsx(Js,{})]})]})}function Xs(){const t=te(a=>a.loadSessions);return i.useEffect(()=>{t().then(()=>{const a=new Set(te.getState().sessions.map(r=>r.id)),{activeSessionId:s}=te.getState();s&&!a.has(s)&&te.getState().setActiveSession(null);const{tabs:n}=Z.getState();for(const r of n)a.has(r.sessionId)||Z.getState().closeTab(r.id)})},[t]),e.jsx(Gs,{})}Ie.createRoot(document.getElementById("root")).render(e.jsx(Ye.StrictMode,{children:e.jsx(Xs,{})}));export{W as B,Y as I,Ce as M,ne as S,B as a,ze as c,me as u};
