@dataramen/cli 0.0.61-beta.1 → 0.0.61

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/bin/app.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ var ee=Object.create;var P=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var ne=Object.getPrototypeOf,oe=Object.prototype.hasOwnProperty;var se=(e,t,o,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of re(t))!oe.call(e,r)&&r!==o&&P(e,r,{get:()=>t[r],enumerable:!(a=te(t,r))||a.enumerable});return e};var c=(e,t,o)=>(o=e!=null?ee(ne(e)):{},se(t||!e||!e.__esModule?P(o,"default",{value:e,enumerable:!0}):o,e));var Z=require("commander");var b=c(require("fs-extra")),R=require("node:path");var _=require("node:os"),C=require("node:path"),ie=(0,_.homedir)(),m="@dataramen/server",i=(0,C.join)(ie,".dataramen",".runtime","server");function V(e){let t;function o(){try{return t||(t=b.readJsonSync(e)),t}catch{return}}return o}var N=V((0,R.join)(__dirname,"..","package.json")),A=V((0,R.join)(i,"package.json"));var p=c(require("fs-extra")),f=require("node:path"),k=require("node:child_process"),M=require("node:util"),g=c(require("yocto-spinner")),d=(0,M.promisify)(k.exec);function O(){try{let e=A();if(!e)return!0;let t=p.readJsonSync((0,f.join)(__dirname,"..","dist","package.json"));return e.version!==t.version}catch{return!0}}async function W(){let e=(0,g.default)({text:"Checking if PM2 is installed"}).start();try{return await d("pm2 -v"),e.success("PM2 already installed"),!0}catch{return e.warning("PM2 not installed"),!1}}async function j(){let e=(0,g.default)({text:"Installing PM2"}).start();try{await d("npm i -g pm2"),e.success("Installed PM2")}catch{e.error("Failed to install PM2"),process.exit(1)}}async function E(){let e=(0,g.default)({text:"Stop running instances of "+m}).start();try{await d(`pm2 stop "${m}"`),e.warning("Stopped "+m)}catch{e.success("No running instances of "+m+" found")}}async function I(){let e=(0,g.default)({text:"Create local server"}).start();p.removeSync((0,f.join)(i,"code")),p.copySync((0,f.join)(__dirname,"..","dist","code"),(0,f.join)(i,"code")),p.copySync((0,f.join)(__dirname,"..","dist","package.json"),(0,f.join)(i,"package.json")),e.text="Install local server dependencies",await d("npm i",{cwd:i}),e.success("Local server installed")}var v=c(require("node:crypto"));var S=require("fs-extra"),T=require("node:path");function ae(e){try{return(0,S.readFileSync)((0,T.join)(i,e),"utf-8")}catch{return}}function me(e){let t={},o=ae(e);if(o){let a=o.split(`
3
+ `);for(let r of a){let s=r.trim();if(!s||s.startsWith("#"))continue;let u=s.indexOf("=");if(u===-1)continue;let w=s.slice(0,u).trim(),l=s.slice(u+1).trim();(l.startsWith('"')&&l.endsWith('"')||l.startsWith("'")&&l.endsWith("'"))&&(l=l.slice(1,-1)),t[w]=l}}return t}function ce(){let e={customValues:{},fileName:".env"};function t(){e.customValues=me(e.fileName)}function o(){let s=Object.entries(e.customValues).map(([u,w])=>`${u}=${w}`).join(`
4
+ `)+`
5
+ `;(0,S.writeFileSync)((0,T.join)(i,e.fileName),s,{encoding:"utf8"})}function a(r){if(e.customValues[r])return e.customValues[r]}return t(),{getNumber:r=>le(a(r)),getString:r=>fe(a(r)),getBoolean:r=>pe(a(r)),flush:o,set:(r,s)=>{e.customValues[r]=s},unset:r=>{delete e.customValues[r]}}}function le(e){if(!e)return;let t=Number(e);if(!isNaN(t)&&e.trim()!=="")return t;throw new Error("Wrong env value type")}function fe(e){if(e){if(typeof e=="string")return e;throw new Error("Wrong env value type")}}function pe(e){if(!e)return;let t=e.toLowerCase();if(t==="true"||t==="1")return!0;if(t==="false"||t==="0")return!1;throw new Error("Wrong env value type")}var n=ce();function J(){let e=!1;if(!n.getString("SYMM_ENCRYPTION_KEY")){let t=v.randomBytes(32).toString("hex");n.set("SYMM_ENCRYPTION_KEY",t),console.log("Generated random SYMM_ENCRYPTION_KEY"),e=!0}if(!n.getString("JWT_SECRET")){let t=v.randomBytes(32).toString("hex");n.set("JWT_SECRET",t),console.log("Generated random JWT_SECRET"),e=!0}if(!n.getString("JWT_REFRESH_SECRET")){let t=v.randomBytes(32).toString("hex");n.set("JWT_REFRESH_SECRET",t),console.log("Generated random JWT_REFRESH_SECRET"),e=!0}e&&n.flush()}var $=require("node:net");async function H(e){return new Promise(t=>{let o=(0,$.createServer)().once("error",()=>{t(!1)}).once("listening",()=>{o.close()}).once("close",()=>t(!0)).listen(e,"127.0.0.1")})}var x=c(require("yocto-spinner"));var L=c(require("fs-extra")),Y=require("node:path");var ue=async e=>{try{return(await fetch(e,{method:"GET",signal:AbortSignal.timeout(5e3)})).status===200}catch{return!1}},F=async(e,t,o)=>{let a=Date.now();for(;Date.now()-a<t;){if(await ue(e))return!0;await new Promise(s=>setTimeout(s,o))}return!1};var K=c(require("open")),Ee={command:"start",description:"Start local server, restarts if already running",handler:async()=>{await W()||await j(),await E();try{O()&&await I(),J();let t=n.getNumber("PORT")||4466;if(!t)throw new Error("PORT env variable not found");if(!await H(t))throw new Error(`Port ${t} is occupied by another process`);let a=(0,x.default)({text:"Starting new instance of "+m}).start(),r=L.readJsonSync((0,Y.join)(i,"package.json"));await d(`pm2 start "${r.main}" --name "${m}" --no-autorestart -- "${i}/.env"`,{cwd:i}),a.success("Local server will be available in a couple of seconds");let s=(0,x.default)({text:"Waiting for the server to become available"}).start();await F(`http://localhost:${t}/api/status`,3e4,1e3)?(await(0,K.default)(`http://localhost:${t}`),s.success(`App is running at http://localhost:${t}`)):s.error("Server failed to become available in time")}catch(t){console.error("Failed to start local server",t)}}},h=Ee;var D=require("node:child_process");var Se={command:"logs",description:"Listen for logs",handler:async()=>{(0,D.execSync)(`pm2 logs ${m}`,{stdio:"inherit"})}},B=Se;var ve={command:"stop",description:"Stop the server",handler:E},G=ve;var U=c(require("open")),he={command:"open",description:"Open webapp",handler:async()=>{let e=n.getNumber("PORT");await(0,U.default)(`http://localhost:${e}`)}},Q=he;var ye={command:"set <prop> <value>",description:"Set env value",handler:async(e,t)=>{n.set(e,t),n.flush(),console.log(`Environment property set: ${e}`)}},q=ye;var we={command:"unset <prop>",description:"Remove env value",handler:async e=>{n.unset(e),n.flush(),console.log(`Environment property unset: ${e}`)}},z=we;var X=[h,B,G,Q,q,z];var y=new Z.Command;y.name("dataramen").description("A cozy web GUI for MySQL and PostgreSQL - built for developers who like to move fast and stay focused.").version(N().version,"-v, --version","Show version");y.command("default",{hidden:!0,isDefault:!0}).action(h.handler);X.forEach(e=>{y.command(e.command).description(e.description).action(e.handler)});y.parse();
@@ -190,4 +190,4 @@ to {
190
190
  pointer-events: auto;
191
191
  }
192
192
  `,Fo=16,I3=({reverseOrder:n,position:l="top-center",toastOptions:i,gutter:r,children:u,containerStyle:c,containerClassName:d})=>{let{toasts:m,handlers:p}=N3(i);return b.createElement("div",{id:"_rht_toaster",style:{position:"fixed",zIndex:9999,top:Fo,left:Fo,right:Fo,bottom:Fo,pointerEvents:"none",...c},className:d,onMouseEnter:p.startPause,onMouseLeave:p.endPause},m.map(y=>{let v=y.position||l,x=p.calculateOffset(y,{reverseOrder:n,gutter:r,defaultPosition:l}),E=P3(v,x);return b.createElement(Z3,{id:y.id,key:y.id,onHeightUpdate:p.updateHeight,className:y.visible?J3:"",style:E},y.type==="custom"?du(y.message,y):u?u(y):b.createElement(F3,{toast:y,position:v}))}))},Zt=kt;const rt=new bS({defaultOptions:{queries:{staleTime:1e3*60*5,retry:(n,l)=>fu(l)&&l.response?.status===404?!1:n<3}},mutationCache:new O1({onError:n=>{fu(n)&&n.status&&n.status>=400&&n.status<500&&n.response?.data.error&&Zt.error(n.response.data.error)}})}),W3=async()=>{const{data:n}=await Kd.post("/auth/refresh");return n.data.accessToken},e4=async n=>{const{data:l}=await Kd.post("/auth/login",n);return l.data.accessToken},Oy=()=>{rt.invalidateQueries({queryKey:["accessToken"]})},jr=(()=>{let n=Promise.resolve(o3()),l=!1;const i=async()=>{await Kd.post("/auth/logout"),Xo(void 0),window.location.reload()};return{get:async()=>n,refresh:()=>(l||(l=!0,n=W3().then(d=>(Xo(d),d)).catch(()=>{Xo(void 0),i()}).finally(()=>{l=!1,Oy()})),n),login:d=>(l||(l=!0,n=e4(d).then(m=>(Xo(m),m)).finally(()=>{l=!1,Oy()})),n),logout:i}})(),cg=location.hostname.includes("app.dataramen.xyz")?"http://localhost:4466/api":"/api",je=et.create({baseURL:cg,withCredentials:!0});je.interceptors.request.use(async n=>{const l=await jr.get();return l&&(n.headers.Authorization=`Bearer ${l}`),n});je.interceptors.response.use(n=>n,n=>(fu(n)&&n.status===401&&n?.response?.data.error!=="Missing auth token"&&jr.refresh(),Promise.reject(n)));const Kd=et.create({baseURL:cg,withCredentials:!0}),yl="data-sources",fg="auth-user",t4=n=>Pt({queryKey:["project","datasources",n],queryFn:async()=>{const{data:l}=await je.get(`/project/team/${n}/datasources`);return l.data},enabled:!!n}),n4=n=>Pt({queryKey:["project","saved-queries",n],queryFn:async()=>{const{data:l}=await je.get(`/project/team/${n}/queries`);return l.data},enabled:!!n}),ni=n=>{const l=["project","datasources"],i=["project","saved-queries"];return Promise.all([rt.invalidateQueries({queryKey:l}),rt.invalidateQueries({queryKey:i})])},a4=n=>{const l=["trash","team"];return rt.invalidateQueries({queryKey:l})},l4=(n,l)=>Pt({queryKey:["project",l.teamId,"tables",n,l.selectedDataSources],queryFn:async()=>{const{data:i}=await je.get(`/project/team/${l.teamId}/query`,{params:{size:30,search:n,selectedDataSources:l.selectedDataSources}});return i.data},enabled:!!l.teamId,staleTime:0}),s4=(n,l=30)=>OS({queryKey:["project","tabs-history",n,l],queryFn:async({pageParam:i})=>{const{data:r}=await je.get(`/project/team/${n}/tabs-history?page=${i}&size=${l}`);return r},select:({pages:i})=>i.flatMap(r=>r.data),enabled:!!n,initialPageParam:0,getNextPageParam:(i,r)=>{if(i.hasMore)return r.length},staleTime:0}),i4=()=>rt.invalidateQueries({queryKey:["project","tabs-history"]}),r4=(n,l)=>{},o4=()=>{},u4={event:r4,pageView:o4},Nu=n=>Pt({queryKey:[yl,n],queryFn:async()=>{const{data:l}=await je.get("/data-sources/"+n);return l.data},enabled:!!n}),$d=n=>Pt({queryKey:[yl,n.teamId],queryFn:async()=>{const{data:l}=await je.get("/data-sources",{params:n});return l.data},enabled:n.teamId!==void 0}),ai=n=>Pt({queryKey:[yl,n,"inspections"],queryFn:async()=>{const{data:l}=await je.get(`/data-sources/${n}/inspections`);return l.data},enabled:!!n}),c4=()=>gt({mutationFn:async n=>{const{data:l}=await je.post("/data-sources",n);return l.data},onSuccess:()=>{rt.invalidateQueries({queryKey:[yl]}),ni()},onError:()=>{}}),f4=()=>gt({mutationFn:async({dataSource:n,id:l})=>{const{data:i}=await je.put(`/data-sources/${l}`,n);return i.data},onSuccess:()=>{rt.invalidateQueries({queryKey:[yl]}),ni()}}),dg=()=>gt({mutationFn:async n=>{await je.post(`/data-sources/${n}/inspect`)},onSuccess:()=>{rt.invalidateQueries({queryKey:[yl]})}}),d4=()=>gt({mutationFn:async n=>{await je.delete(`/data-sources/${n}`)},onSuccess:()=>{rt.invalidateQueries({queryKey:[yl]}),ni()}}),hg=()=>Pt({queryKey:["accessToken"],queryFn:jr.get}),Bn=()=>{const{data:n}=hg();return Pt({queryKey:[fg],queryFn:async()=>{const{data:l}=await je.get("/users");return l.data},enabled:!!n,retry:(l,i)=>fu(i)&&i.code==="ERR_NETWORK"?!1:l<3})},h4=()=>gt({mutationFn:async n=>{const{data:l}=await je.patch("/users",n);return l.data},onSuccess:async n=>{rt.setQueryData([fg],n)}}),m4=()=>gt({mutationFn:async n=>(await je.post("/users",n),!0),onSuccess:()=>{rt.invalidateQueries({queryKey:["team-users"]})}}),p4="_alert_24f5s_2",y4="_info_24f5s_2",g4="_danger_24f5s_2",v4="_success_24f5s_2",b4="_warning_24f5s_2",x4="_dark_24f5s_2",ks={alert:p4,info:y4,danger:g4,success:v4,warning:b4,dark:x4};function mg(n){var l,i,r="";if(typeof n=="string"||typeof n=="number")r+=n;else if(typeof n=="object")if(Array.isArray(n)){var u=n.length;for(l=0;l<u;l++)n[l]&&(i=mg(n[l]))&&(r&&(r+=" "),r+=i)}else for(i in n)n[i]&&(r&&(r+=" "),r+=i);return r}function re(){for(var n,l,i=0,r="",u=arguments.length;i<u;i++)(n=arguments[i])&&(l=mg(n))&&(r&&(r+=" "),r+=l);return r}const wt=({variant:n,noRounded:l,className:i,children:r,...u})=>h.jsx("div",{className:re(ks.alert,!l&&"rounded-lg",(n==="info"||!n)&&ks.info,n==="danger"&&ks.danger,n==="dark"&&ks.dark,n==="warning"&&ks.warning,n==="success"&&ks.success,i),role:"alert",...u,children:r}),cn=n=>{const l=new Set;let i=n;const r=m=>(l.add(m),()=>l.delete(m)),u=m=>(l.forEach(p=>p(m)),!0),c=m=>{i=typeof m=="function"?m(i):m,u(i)},d=m=>()=>m?m(i):i;return[m=>b.useSyncExternalStore(r,d(m),d(m)),c,{get:()=>i,subscribe:m=>(m(i),r(m))}]};function S4(n){const l=[];for(const i of n)for(const r of i.columns)r.ref&&(l.push({id:`${i.tableName}->${r.ref.table}.${r.ref.field}`,name:`${i.tableName} in ${r.ref.table}`,where:`${i.tableName}.${r.name} = ${r.ref.table}.${r.ref.field}`,on:{fromTable:r.ref.table,toTable:i.tableName,fromColumn:r.ref.field,toColumn:r.name}}),l.push({id:`${r.ref.table}->${i.tableName}.${r.name}`,name:`${r.ref.table} in ${i.tableName}`,where:`${r.ref.table}.${r.ref.field} = ${i.tableName}.${r.name}`,on:{fromTable:i.tableName,toTable:r.ref.table,fromColumn:r.name,toColumn:r.ref.field}}));return l}const w4=n=>Pt({queryKey:["hooks",n],queryFn:async()=>{const l=await rt.fetchQuery({queryKey:[yl,n,"inspections"],queryFn:async()=>{const{data:i}=await je.get(`/data-sources/${n}/inspections`);return i.data}});return S4(l)},enabled:!!n}),Gd=[{value:"=",label:"equals"},{value:"<>",label:"not equal"},{value:">",label:"greater than"},{value:">=",label:"greater than or equal"},{value:"<",label:"less than"},{value:"<=",label:"less than or equal"},{value:"LIKE",label:"contains"},{value:"NOT LIKE",label:"not contains"},{value:"IN",label:"in list"},{value:"NOT IN",label:"not in list"},{value:"IS NULL",label:"is null"},{value:"IS NOT NULL",label:"is not null"}],pg=Gd.reduce((n,l)=>(n[l.value]=l.label,n),{}),Xd=Gd.reduce((n,l)=>(n[l.label]=l.value,n),{}),li=n=>n.map(l=>({label:pg[l],value:l})),E4=li(["=","<>",">",">=","<","<=","IN","NOT IN","IS NULL","IS NOT NULL"]),C4=li(["=","<>","LIKE","NOT LIKE","IN","NOT IN","IS NULL","IS NOT NULL"]);li(["=","<>","IS NULL","IS NOT NULL"]);const _4=li(["=","<>",">",">=","<","<=","IS NULL","IS NOT NULL"]);li(["IS NULL","IS NOT NULL"]);li(["IN","NOT IN"]);const yg=n=>n!=="IS NULL"&&n!=="IS NOT NULL",N4=(n,l)=>yg(n)?n==="IN"||n==="NOT IN"?l.split(",").map(i=>({value:i.trim(),isColumn:!1})):[{value:l,isColumn:!1}]:[],j4=["char","varchar","binary","varbinary","blob","text","enum","set","character","character varying","text","citext","uuid","xml","json","jsonb"],T4=["integer","smallint","decimal","numeric","float","real","double precision","int","smallint","integer","bigint","decimal","numeric","real","double precision","serial","bigserial","money"],A4=["date","time","datetime","timestamp","year","date","time","time without time zone","time with time zone","timestamp","timestamp without time zone","timestamp with time zone","interval"],R4=["date","datetime","timestamp","timestamptz"].reduce((n,l)=>(n[l]=!0,n),{}),gg=n=>n.fn?n.distinct===!0?`${n.fn} distinct ${n.value}`:`${n.fn} ${n.value}`:n.value;var Gt=(n=>(n.OWNER="owner",n.ADMIN="admin",n.EDITOR="editor",n.READ_ONLY="read_only",n))(Gt||{});const Dy={[Gt.READ_ONLY]:10,[Gt.EDITOR]:20,[Gt.ADMIN]:30,[Gt.OWNER]:40};function O4(n,l){if(!n||!l)return{};const i=new Set;for(const u of l)u.table&&i.add(u.table);const r={};for(const u of i){const c=n.find(d=>d.tableName===u);if(c){r[u]=[];const d=c.columns.filter(m=>m.isPrimary);for(const m of d)if(l.find(y=>y.table===u&&y.column===m.name))r[u].push(m.name);else{delete r[u];break}}}return r}function D4(n,l,i,r){const{data:u}=w4(l),{data:c}=ai(l);return b.useMemo(()=>{const d=O4(c,n?.result.columns);return{name:i,tabId:r,hooks:(()=>{const m=[];if(!u||!n||!n.result.columns)return m;for(const p of u)(n.result.tables.includes(p.on.toTable)||n.result.tables.includes(p.on.fromTable))&&m.push(p);return m})(),availableJoins:(()=>{const m=[];if(!u||!n||!n.result.columns)return m;for(const p of u)!n.result.tables.includes(p.on.toTable)&&n.result.tables.includes(p.on.fromTable)&&m.push(p);return m})(),allColumns:n?.result.allColumns||[],dataSourceId:l,entities:Object.keys(d),getValue:(m,p)=>{const y=gg(p),v=n?.result.columns?.findIndex(x=>x.full===y);if(v!=null&&v>-1)return m[v]},getEntityKey:(m,p)=>d[m].reduce((y,v)=>{const x=n?.result.columns?.findIndex(E=>E.column===v&&E.table===m);return x!=null&&x>-1&&y.push([v,p[x]]),y},[]),getColumnType:m=>{const p=n?.result.allColumns.find(y=>y.full===m);if(p)return p.type}}},[n,l,u,c,i])}function M4(n,l){return b.useMemo(()=>({state:n,setState:l}),[n,l])}function $s(n){return{dataSourceId:n.dataSourceId||"",page:n?.page||0,size:n?.size||50,table:n.table||"",filters:n?.filters||[],joins:n?.joins??[],orderBy:n?.orderBy??[],columns:n?.columns??[],groupBy:n?.groupBy??[],aggregations:n?.aggregations??[]}}const Ye={home:{path:"/"},workbench:{path:"/workbench"},share:{path:"/share"},login:{path:"/login"}},Fd=n=>{rt.setQueryData(["workbench-tabs"],l=>n(l||[]))},L4=(n,l)=>{rt.setQueryData(["workbench-tabs",n],i=>i&&l(i))},Zd=()=>Pt({queryKey:["workbench-tabs"],queryFn:async()=>{const{data:n}=await je.get("/workbench-tabs");return n.data}}),U4=n=>Pt({queryKey:["workbench-tabs",n],queryFn:async()=>{const{data:l}=await je.get(`/workbench-tabs/${n}`);return l.data}}),si=()=>gt({mutationFn:async n=>{const{data:l}=await je.post("/workbench-tabs",n);return l.data},onSuccess:async n=>{Fd(l=>[...l,n])}}),z4=()=>gt({mutationFn:async n=>(await je.patch(`/workbench-tabs/${n}`,{archived:!0}),n),onMutate:n=>{Fd(l=>l.filter(i=>i.id!==n))}}),vg=()=>gt({mutationFn:async n=>(await je.patch(`/workbench-tabs/${n}`,{archived:!1}),n),onSuccess:()=>xg()}),k4=()=>gt({mutationFn:async({id:n,payload:l})=>(await je.patch(`/workbench-tabs/${n}`,l),!0),onMutate:({id:n,payload:l})=>{L4(n,i=>({...i,...l})),Fd(i=>i.map(r=>r.id!==n?r:{...r,name:l.name||r.name}))}}),q4=(n,l)=>{const{dataSourceId:i,searchAll:r,table:u,filters:c,joins:d,orderBy:m,groupBy:p,columns:y,aggregations:v,page:x=0,size:E=20}=l;return Pt({queryKey:["workbench-tab-runner",n,i,u,x,E,c,v,d,m,p,y,r],queryFn:async()=>{const{data:C}=await je.post(`/workbench-tabs/${n}/run`,l);return C.data},retry:1,enabled:!!u&&!!i})},B4=()=>gt({mutationFn:async n=>{await je.delete(`/workbench-tabs/${n}`)},onSuccess:()=>{xg(),i4()}}),bg=n=>rt.invalidateQueries({queryKey:["workbench-tab-runner",n]}),xg=()=>rt.invalidateQueries({queryKey:["workbench-tabs"]}),[H4,Pf,Q4]=cn(void 0),Y4=async()=>new Promise(n=>{Pf({onCancel:()=>{Pf(void 0),n(void 0)},onConfirm:(l,i,r)=>{Pf(void 0),n({dsId:r,id:i,type:l})}})}),Tr=n=>{const l=Et(),i=si(),r=vg();return b.useEffect(()=>{i?.data?.id&&l(`${Ye.workbench.path}/tab/${i.data.id}`),r?.data&&l(`${Ye.workbench.path}/tab/${r?.data}`)},[i.data,r.data]),b.useCallback(()=>{Q4.get()||Y4().then(c=>{c?.type==="table"?i.mutate({name:c.id,opts:$s({table:c.id,dataSourceId:c.dsId})}):c?.type==="query"?i.mutate({queryId:c.id}):c?.type==="tab"&&r.mutate(c.id)})},[l,n])},Ar=n=>{const{data:l}=Bn();return b.useMemo(()=>l?Dy[l.teamRole]>=Dy[n]:!1,[l,n])},V4="_input_18t53_2",K4="_small_18t53_2",$4="_content_18t53_2",G4="_form_18t53_2",X4="_mode-select_18t53_2",ze={input:V4,small:K4,content:$4,form:G4,switch:"_switch_18t53_2",modeSelect:X4},F4="_modal_1g5ny_2",Z4="_modal-visible_1g5ny_2",P4="_modal-invisible_1g5ny_2",J4="_backdrop_1g5ny_2",I4="_modal-container_1g5ny_2",W4="_close-button_1g5ny_2",Ys={modal:F4,modalVisible:Z4,modalInvisible:P4,backdrop:J4,modalContainer:I4,closeButton:W4},Pl=n=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},b.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32,d:"M368 368L144 144M368 144L144 368"})),fn=({children:n,backdropClose:l,isVisible:i,onClose:r,onClosed:u,noPadding:c=!1,portal:d=!1})=>{const[m,p]=b.useState(!1),y=()=>{l&&r()},v=E=>{i||getComputedStyle(E.currentTarget).opacity==="0"&&(p(!1),u&&u())};b.useEffect(()=>{i&&p(!0)},[i]);const x=h.jsxs("div",{onTransitionEnd:v,className:re(Ys.modal,i?Ys.modalVisible:Ys.modalInvisible),children:[h.jsx("div",{onClick:y,className:Ys.backdrop}),h.jsx("div",{className:re(Ys.modalContainer,c!==!0&&"p-4"),children:m&&n})]});return d?Px.createPortal(x,document.body):x},aa=({onClick:n})=>{const l=b.useRef(n);return l.current=n,b.useEffect(()=>{const i=r=>{r.key==="Escape"&&l.current?.()};return window.addEventListener("keyup",i),()=>{window.removeEventListener("keyup",i)}},[]),h.jsx("button",{className:Ys.closeButton,onClick:n,children:h.jsx(Pl,{width:20,height:20})})},Sg=({children:n})=>h.jsx("h2",{className:"text-xl font-semibold",children:n}),Rr=n=>{const[l,i]=b.useState(n),[r,u]=b.useState([]),c=b.useRef(n),d=b.useCallback((y,v)=>{i(x=>({...x,[y]:v}))},[]),m=b.useCallback(y=>v=>{v.target.type==="checkbox"?d(y,v.target.checked):d(y,v.target.value),u(x=>x.includes(y)?x:[...x,y])},[d]),p=b.useCallback(()=>{i(c.current),u([])},[]);return[l,{set:d,change:m,reset:p,touched:r}]},eE=({form:n,change:l})=>h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:re(ze.input,ze.small),children:[h.jsx("label",{children:"Database URL"}),h.jsx("input",{value:n.dbUrl,onChange:l("dbUrl"),className:"input"})]}),h.jsxs("div",{className:re(ze.input,ze.small),children:[h.jsx("label",{children:"Database port"}),h.jsx("input",{value:n.dbPort,onChange:l("dbPort"),type:"number",className:"input"})]}),h.jsxs("div",{className:re(ze.input,ze.small),children:[h.jsx("label",{children:"User"}),h.jsx("input",{value:n.dbUser,onChange:l("dbUser"),className:"input"})]}),h.jsxs("div",{className:re(ze.input,ze.small),children:[h.jsx("label",{children:"Password"}),h.jsx("input",{type:"password",value:n.dbPassword,onChange:l("dbPassword"),className:"input"})]}),h.jsxs("div",{className:re(ze.input,ze.small),children:[h.jsx("label",{children:"Database"}),h.jsx("input",{value:n.dbDatabase,onChange:l("dbDatabase"),className:"input"})]})]}),tE=({form:n,change:l})=>h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:re(ze.input,ze.small),children:[h.jsx("label",{children:"Database URL"}),h.jsx("input",{value:n.dbUrl,onChange:l("dbUrl"),className:"input"})]}),h.jsxs("div",{className:re(ze.input,ze.small),children:[h.jsx("label",{children:"Database port"}),h.jsx("input",{value:n.dbPort,onChange:l("dbPort"),type:"number",className:"input"})]}),h.jsxs("div",{className:re(ze.input,ze.small),children:[h.jsx("label",{children:"User"}),h.jsx("input",{value:n.dbUser,onChange:l("dbUser"),className:"input"})]}),h.jsxs("div",{className:re(ze.input,ze.small),children:[h.jsx("label",{children:"Password"}),h.jsx("input",{type:"password",value:n.dbPassword,onChange:l("dbPassword"),className:"input"})]}),h.jsxs("div",{className:re(ze.input,ze.small),children:[h.jsx("label",{children:"Database"}),h.jsx("input",{value:n.dbDatabase,onChange:l("dbDatabase"),className:"input"})]}),h.jsxs("div",{className:re(ze.input,ze.small),children:[h.jsx("label",{children:"Schema"}),h.jsx("input",{value:n.dbSchema,onChange:l("dbSchema"),className:"input"})]})]}),qs=[{label:"PostgreSQL",tag:"postgres"},{label:"MySQL",tag:"mysql"}],nE=({show:n,onClose:l,dbType:i="postgres"})=>{const r=c4(),u=dg(),{data:c}=Bn(),[d,{change:m,set:p}]=Rr({name:"",dbType:i,dbUrl:"",dbUser:"",dbPassword:"",dbDatabase:"",dbSchema:"",dbPort:5432,teamId:"",ownerId:"",description:"",allowInsert:!1,allowUpdate:!1}),y=async()=>{const w=await r.mutateAsync({...d,dbPort:Number(d.dbPort),teamId:c.teamId,ownerId:c.id});await u.mutateAsync(w.id),l(),u4.event("Create Datasource",{dbType:d.dbType})},v=w=>{p("allowInsert",!w),p("allowUpdate",!w)},x=()=>{l()},E=r.isPending||u.isPending,C=!d.allowInsert&&!d.allowUpdate;return h.jsxs(fn,{isVisible:n,onClose:x,children:[h.jsx(aa,{onClick:x}),h.jsxs(wt,{variant:"warning",className:"text-sm mb-2 max-w-xl",children:["DataRamen is currently under active development. In production-like environments, ",h.jsx("span",{className:"font-semibold underline",children:"it’s recommended to use read-only database credentials"}),"."]}),r.isError&&h.jsx(wt,{variant:"danger",className:"mb-2",children:h.jsx("span",{children:"Failed to connect to the database. Please check if the data are correct and retry."})}),r.isPending&&h.jsx(wt,{className:"mb-2",variant:"info",children:"Creating connection"}),u.isPending&&h.jsx(wt,{className:"mb-2",variant:"info",children:"Inspecting connection"}),h.jsxs("div",{className:ze.switch,children:[h.jsxs("label",{className:"button tertiary",children:[h.jsx("input",{type:"radio",name:"bdType",className:"mr-2",checked:d.dbType===qs[0].tag,onChange:()=>p("dbType",qs[0].tag)}),h.jsx("span",{children:qs[0].label})]}),h.jsxs("label",{className:"button tertiary",children:[h.jsx("input",{type:"radio",name:"bdType",className:"mr-2",checked:d.dbType===qs[1].tag,onChange:()=>p("dbType",qs[1].tag)}),h.jsx("span",{children:qs[1].label})]})]}),h.jsxs("div",{className:"overflow-y-auto mt-2",children:[h.jsx("div",{className:ze.content,children:h.jsxs("div",{className:ze.form,children:[h.jsxs("div",{className:re(ze.input,"col-span-2"),children:[h.jsx("label",{children:"Name"}),h.jsx("input",{value:d.name,onChange:m("name"),className:"input"})]}),h.jsxs("div",{className:re(ze.input,"col-span-2"),children:[h.jsx("label",{children:"Description"}),h.jsx("textarea",{value:d.description,onChange:m("description"),className:"input"})]}),d.dbType==="mysql"&&h.jsx(eE,{form:d,change:m}),d.dbType==="postgres"&&h.jsx(tE,{form:d,change:m})]})}),h.jsxs("div",{className:"mt-4",children:[h.jsxs("label",{className:ze.modeSelect,children:[h.jsxs("div",{children:[h.jsx("input",{type:"radio",name:"production-mode",className:"mr-2",checked:C,onChange:()=>v(!0)}),h.jsx("span",{className:"text-sm font-semibold",children:"Production mode"})]}),h.jsxs("p",{className:"text-xs mt-1 text-gray-600",children:["Mutation operations (such as INSERT or UPDATE) are ",h.jsx("strong",{children:"forbidden"}),". You won't be able to insert new rows or edit existing data. Tables in this data source are read-only."]})]}),h.jsxs("label",{className:ze.modeSelect,children:[h.jsxs("div",{children:[h.jsx("input",{type:"radio",name:"production-mode",className:"mr-2",checked:!C,onChange:()=>v(!1)}),h.jsx("span",{className:"text-sm font-semibold",children:"Dev mode"})]}),h.jsxs("p",{className:"text-xs mt-1 text-gray-600",children:["Mutation operations (such as INSERT or UPDATE) are ",h.jsx("strong",{children:"allowed"}),". You will be able to insert new rows and edit existing data."]})]})]})]}),h.jsxs("div",{className:"flex justify-end gap-1 mt-2",children:[h.jsx("button",{onClick:x,className:"button tertiary",disabled:E,children:"Cancel"}),h.jsx("button",{onClick:y,className:"button primary",disabled:E,children:"Create"})]})]})},aE="_data-source-entry_1i5tp_2",lE="_action-title_1i5tp_2",sE="_action-subtext_1i5tp_2",iE="_dev-tag_1i5tp_2",rE="_prod-tag_1i5tp_2",$t={dataSourceEntry:aE,actionTitle:lE,actionSubtext:sE,devTag:iE,prodTag:rE},oE=n=>b.createElement("svg",{fill:"#000000",width:"800px",height:"800px",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",...n},b.createElement("path",{d:"m24.129 23.412-.508-.484c-.251-.331-.518-.624-.809-.891l-.005-.004q-.448-.407-.931-.774-.387-.266-1.064-.641c-.371-.167-.661-.46-.818-.824l-.004-.01-.048-.024c.212-.021.406-.06.592-.115l-.023.006.57-.157c.236-.074.509-.122.792-.133h.006c.298-.012.579-.06.847-.139l-.025.006q.194-.048.399-.109t.351-.109v-.169q-.145-.217-.351-.496c-.131-.178-.278-.333-.443-.468l-.005-.004q-.629-.556-1.303-1.076c-.396-.309-.845-.624-1.311-.916l-.068-.04c-.246-.162-.528-.312-.825-.435l-.034-.012q-.448-.182-.883-.399c-.097-.048-.21-.09-.327-.119l-.011-.002c-.117-.024-.217-.084-.29-.169l-.001-.001c-.138-.182-.259-.389-.355-.609l-.008-.02q-.145-.339-.314-.651-.363-.702-.702-1.427t-.651-1.452q-.217-.484-.399-.967c-.134-.354-.285-.657-.461-.942l.013.023c-.432-.736-.863-1.364-1.331-1.961l.028.038c-.463-.584-.943-1.106-1.459-1.59l-.008-.007c-.509-.478-1.057-.934-1.632-1.356l-.049-.035q-.896-.651-1.96-1.282c-.285-.168-.616-.305-.965-.393l-.026-.006-1.113-.278-.629-.048q-.314-.024-.629-.024c-.148-.078-.275-.171-.387-.279-.11-.105-.229-.204-.353-.295l-.01-.007c-.605-.353-1.308-.676-2.043-.93l-.085-.026c-.193-.113-.425-.179-.672-.179-.176 0-.345.034-.499.095l.009-.003c-.38.151-.67.458-.795.84l-.003.01c-.073.172-.115.371-.115.581 0 .368.13.705.347.968l-.002-.003q.544.725.834 1.14.217.291.448.605c.141.188.266.403.367.63l.008.021c.056.119.105.261.141.407l.003.016q.048.206.121.448.217.556.411 1.14c.141.425.297.785.478 1.128l-.019-.04q.145.266.291.52t.314.496c.065.098.147.179.241.242l.003.002c.099.072.164.185.169.313v.001c-.114.168-.191.369-.217.586l-.001.006c-.035.253-.085.478-.153.695l.008-.03c-.223.666-.351 1.434-.351 2.231 0 .258.013.512.04.763l-.003-.031c.06.958.349 1.838.812 2.6l-.014-.025c.197.295.408.552.641.787.168.188.412.306.684.306.152 0 .296-.037.422-.103l-.005.002c.35-.126.599-.446.617-.827v-.002c.048-.474.12-.898.219-1.312l-.013.067c.024-.063.038-.135.038-.211 0-.015-.001-.03-.002-.045v.002q-.012-.109.133-.206v.048q.145.339.302.677t.326.677c.295.449.608.841.952 1.202l-.003-.003c.345.372.721.706 1.127 1.001l.022.015c.212.162.398.337.566.528l.004.004c.158.186.347.339.56.454l.01.005v-.024h.048c-.039-.087-.102-.157-.18-.205l-.002-.001c-.079-.044-.147-.088-.211-.136l.005.003q-.217-.217-.448-.484t-.423-.508q-.508-.702-.969-1.467t-.871-1.555q-.194-.387-.375-.798t-.351-.798c-.049-.099-.083-.213-.096-.334v-.005c-.006-.115-.072-.214-.168-.265l-.002-.001c-.121.206-.255.384-.408.545l.001-.001c-.159.167-.289.364-.382.58l-.005.013c-.141.342-.244.739-.289 1.154l-.002.019q-.072.641-.145 1.318l-.048.024-.024.024c-.26-.053-.474-.219-.59-.443l-.002-.005q-.182-.351-.326-.69c-.248-.637-.402-1.374-.423-2.144v-.009c-.009-.122-.013-.265-.013-.408 0-.666.105-1.308.299-1.91l-.012.044q.072-.266.314-.896t.097-.871c-.05-.165-.143-.304-.265-.41l-.001-.001c-.122-.106-.233-.217-.335-.335l-.003-.004q-.169-.244-.326-.52t-.278-.544c-.165-.382-.334-.861-.474-1.353l-.022-.089c-.159-.565-.336-1.043-.546-1.503l.026.064c-.111-.252-.24-.47-.39-.669l.006.008q-.244-.326-.436-.617-.244-.314-.484-.605c-.163-.197-.308-.419-.426-.657l-.009-.02c-.048-.097-.09-.21-.119-.327l-.002-.011c-.011-.035-.017-.076-.017-.117 0-.082.024-.159.066-.223l-.001.002c.011-.056.037-.105.073-.145.039-.035.089-.061.143-.072h.002c.085-.055.188-.088.3-.088.084 0 .165.019.236.053l-.003-.001c.219.062.396.124.569.195l-.036-.013q.459.194.847.375c.298.142.552.292.792.459l-.018-.012q.194.121.387.266t.411.291h.339q.387 0 .822.037c.293.023.564.078.822.164l-.024-.007c.481.143.894.312 1.286.515l-.041-.019q.593.302 1.125.641c.589.367 1.098.743 1.577 1.154l-.017-.014c.5.428.954.867 1.38 1.331l.01.012c.416.454.813.947 1.176 1.464l.031.047c.334.472.671 1.018.974 1.584l.042.085c.081.154.163.343.234.536l.011.033q.097.278.217.57.266.605.57 1.221t.57 1.198l.532 1.161c.187.406.396.756.639 1.079l-.011-.015c.203.217.474.369.778.422l.008.001c.368.092.678.196.978.319l-.047-.017c.143.065.327.134.516.195l.04.011c.212.065.396.151.565.259l-.009-.005c.327.183.604.363.868.559l-.021-.015q.411.302.822.57.194.145.651.423t.484.52c-.114-.004-.249-.007-.384-.007-.492 0-.976.032-1.45.094l.056-.006c-.536.072-1.022.203-1.479.39l.04-.014c-.113.049-.248.094-.388.129l-.019.004c-.142.021-.252.135-.266.277v.001c.061.076.11.164.143.26l.002.006c.034.102.075.19.125.272l-.003-.006c.119.211.247.393.391.561l-.004-.005c.141.174.3.325.476.454l.007.005q.244.194.508.399c.161.126.343.25.532.362l.024.013c.284.174.614.34.958.479l.046.016c.374.15.695.324.993.531l-.016-.011q.291.169.58.375t.556.399c.073.072.137.152.191.239l.003.005c.091.104.217.175.36.193h.003v-.048c-.088-.067-.153-.16-.184-.267l-.001-.004c-.025-.102-.062-.191-.112-.273l.002.004zm-18.576-19.205q-.194 0-.363.012c-.115.008-.222.029-.323.063l.009-.003v.024h.048q.097.145.244.326t.266.351l.387.798.048-.024c.113-.082.2-.192.252-.321l.002-.005c.052-.139.082-.301.082-.469 0-.018 0-.036-.001-.054v.003c-.045-.044-.082-.096-.108-.154l-.001-.003-.081-.182c-.053-.084-.127-.15-.214-.192l-.003-.001c-.094-.045-.174-.102-.244-.169z"})),uE=n=>b.createElement("svg",{width:"800px",height:"800px",viewBox:"0 0 32 32",xmlns:"http://www.w3.org/2000/svg",...n},b.createElement("title",null,"file_type_pgsql"),b.createElement("path",{d:"M29.507,18.773a1.378,1.378,0,0,0-1.144-.921,2.619,2.619,0,0,0-.913.051,8.2,8.2,0,0,1-1.406.185,27.125,27.125,0,0,0,2.872-6.83c.953-3.689.444-5.369-.151-6.13A8.239,8.239,0,0,0,22.121,2a11.773,11.773,0,0,0-3.453.484A12.858,12.858,0,0,0,16.648,2.3a6.565,6.565,0,0,0-3.518.867,16.039,16.039,0,0,0-2.484-.624,7.694,7.694,0,0,0-5.819.924C3.093,4.691,2.289,6.819,2.438,9.792A36.351,36.351,0,0,0,3.844,16.33a22.579,22.579,0,0,0,1.514,3.863A4.786,4.786,0,0,0,7.8,22.742a2.4,2.4,0,0,0,2.379-.516,2.08,2.08,0,0,0,.5.43,3.328,3.328,0,0,0,.944.4,5.069,5.069,0,0,0,3.3-.2c.006.171.011.335.014.477.006.229.013.454.021.665a11.641,11.641,0,0,0,.441,3.3c.016.043.037.107.059.176a3.975,3.975,0,0,0,.991,1.745,2.955,2.955,0,0,0,2.09.777,4.7,4.7,0,0,0,.977-.109A4.592,4.592,0,0,0,22.607,28.1c.811-1.155,1.206-2.894,1.277-5.635.009-.078.018-.152.026-.222l.017-.145.191.017.049,0a7.562,7.562,0,0,0,3.163-.548c.631-.293,2.654-1.361,2.177-2.8"}),b.createElement("path",{d:"M27.689,19.053c-3.163.652-3.38-.418-3.38-.418C27.648,13.68,29.044,7.39,27.839,5.851c-3.286-4.2-8.975-2.213-9.07-2.162l-.031.006a11.28,11.28,0,0,0-2.11-.22,5.212,5.212,0,0,0-3.34,1S3.14.294,3.612,9.733c.1,2.008,2.878,15.194,6.191,11.211,1.211-1.456,2.381-2.688,2.381-2.688a3.071,3.071,0,0,0,2.006.512l.057-.048a2.21,2.21,0,0,0,.023.567c-.854.954-.6,1.121-2.309,1.472-1.726.356-.712.989-.05,1.155a3.508,3.508,0,0,0,3.915-1.272l-.05.2c.334.268.569,1.742.53,3.079a8.481,8.481,0,0,0,.2,2.971c.264.717.526,2.329,2.769,1.849a3.307,3.307,0,0,0,2.98-3.179c.1-1.234.313-1.052.326-2.155l.174-.522c.2-1.673.032-2.213,1.186-1.962l.281.025a6.4,6.4,0,0,0,2.615-.44c1.406-.652,2.239-1.742.853-1.455h0",style:{fill:"#336791"}}),b.createElement("path",{d:"M13.882,10.631a.981.981,0,0,0-.674.1.247.247,0,0,0-.1.164.48.48,0,0,0,.117.314.881.881,0,0,0,.559.349.637.637,0,0,0,.09.006.725.725,0,0,0,.687-.467c.035-.248-.326-.414-.676-.463m9.442.008c-.027-.195-.374-.25-.7-.2s-.647.194-.62.389a.667.667,0,0,0,.62.411.592.592,0,0,0,.083-.006.8.8,0,0,0,.451-.247.5.5,0,0,0,.169-.343",style:{fill:"#fff"}}),b.createElement("path",{d:"M28.741,18.979c-.121-.365-.509-.482-1.154-.349-1.915.4-2.6.121-2.826-.044a26.327,26.327,0,0,0,3.373-7.565,14.374,14.374,0,0,0,.5-3.253,3.513,3.513,0,0,0-.509-2.2,7.482,7.482,0,0,0-6.049-2.825,10.363,10.363,0,0,0-3.5.551,8.717,8.717,0,0,0-1.968-.253,5.684,5.684,0,0,0-3.372.929,15.051,15.051,0,0,0-2.74-.718,6.978,6.978,0,0,0-5.242.805c-1.5,1.064-2.2,2.966-2.061,5.653a35.489,35.489,0,0,0,1.373,6.348c1.07,3.505,2.233,5.49,3.457,5.9a1.548,1.548,0,0,0,.491.081,2.049,2.049,0,0,0,1.563-.886q1.042-1.25,2.155-2.438a3.472,3.472,0,0,0,1.55.417l0,.042q-.14.166-.273.338c-.375.475-.452.574-1.658.823-.343.071-1.254.259-1.267.9-.014.7,1.077.991,1.2,1.022a5.144,5.144,0,0,0,1.249.162,3.634,3.634,0,0,0,2.5-.934,23.674,23.674,0,0,0,.381,5.684,2.854,2.854,0,0,0,2.729,2.1,4.378,4.378,0,0,0,.917-.1,3.462,3.462,0,0,0,3.156-3.212c.177-1.026.481-3.475.624-4.789a3.859,3.859,0,0,0,1.11.137,6.6,6.6,0,0,0,2.519-.48c.712-.331,2-1.141,1.763-1.846ZM24.051,10.1a7.968,7.968,0,0,1-.116,1.107,10.229,10.229,0,0,0-.14,1.3,9.859,9.859,0,0,0,.1,1.47,5.236,5.236,0,0,1-.229,2.986,3.882,3.882,0,0,1-.207-.426c-.058-.141-.185-.368-.359-.681-.68-1.22-2.274-4.078-1.458-5.244.243-.347.86-.7,2.408-.512ZM22.174,3.531a6.617,6.617,0,0,1,5.334,2.522c.975,1.245-.1,6.912-3.205,11.8l-.094-.119-.039-.049a5.524,5.524,0,0,0,.506-3.8,9.114,9.114,0,0,1-.1-1.352,9.572,9.572,0,0,1,.131-1.206,7.614,7.614,0,0,0,.123-1.493.619.619,0,0,0,.013-.21,8.381,8.381,0,0,0-1.912-3.6,8.61,8.61,0,0,0-3.039-2.284,10.246,10.246,0,0,1,2.28-.214ZM9.479,20.654c-.627.754-1.061.61-1.2.562-.928-.31-2.006-2.272-2.955-5.384a35.167,35.167,0,0,1-1.34-6.159c-.12-2.4.462-4.074,1.73-4.974,2.063-1.463,5.456-.587,6.819-.143-.02.019-.04.037-.059.057-2.237,2.259-2.184,6.119-2.178,6.355,0,.091.007.22.018.4a15.969,15.969,0,0,1-.081,3.226A4.08,4.08,0,0,0,11.3,18.007q.133.138.278.262c-.383.41-1.216,1.318-2.1,2.385Zm2.39-3.19a3.3,3.3,0,0,1-.865-2.764,16.7,16.7,0,0,0,.087-3.381c-.006-.095-.011-.178-.014-.243A4.3,4.3,0,0,1,14,10.223a1.188,1.188,0,0,1,.918,1.026c.646,2.989.085,4.234-.365,5.235-.093.206-.181.4-.255.6l-.058.156a10.218,10.218,0,0,0-.368,1.109,2.788,2.788,0,0,1-2-.887Zm.113,4.03a1.733,1.733,0,0,1-.523-.225,2.553,2.553,0,0,1,.557-.166c1.418-.292,1.637-.5,2.116-1.105.11-.139.234-.3.406-.489h0c.256-.287.374-.238.586-.15a.829.829,0,0,1,.408.525.585.585,0,0,1-.05.491A3.1,3.1,0,0,1,11.983,21.495ZM19.406,28.4a2.113,2.113,0,0,1-2.754-1.526,31.129,31.129,0,0,1-.3-6.853.392.392,0,0,0-.017-.124,1.643,1.643,0,0,0-.048-.23,1.589,1.589,0,0,0-.862-1.034,1.216,1.216,0,0,0-.793-.1,9.586,9.586,0,0,1,.342-1.022l.058-.157c.066-.177.148-.36.235-.554.471-1.047,1.117-2.482.416-5.722a2.044,2.044,0,0,0-2.468-1.669A5.694,5.694,0,0,0,11.328,10c-.078.04-.15.078-.216.115A8.244,8.244,0,0,1,13.03,5.163,4.711,4.711,0,0,1,16.6,3.827,7.567,7.567,0,0,1,22.381,6.59,8.774,8.774,0,0,1,23.963,9.3c-1.463-.149-2.458.14-2.962.861-1.1,1.568.6,4.612,1.416,6.075.15.268.279.5.319.6a5.432,5.432,0,0,0,.861,1.387c.077.1.152.189.208.271-.443.128-1.239.423-1.166,1.9-.058.74-.474,4.205-.686,5.43-.279,1.617-.874,2.22-2.548,2.579Zm7.242-8.288a5.714,5.714,0,0,1-1.931.4,2.422,2.422,0,0,1-1.3-.167c-.045-.919.3-1.015.66-1.117.057-.016.112-.032.166-.05a1.353,1.353,0,0,0,.11.08c.639.422,1.78.467,3.39.135l.018,0a4.334,4.334,0,0,1-1.116.72Z",style:{fill:"#fff"}})),ii=({size:n,type:l})=>l==="mysql"?h.jsx(oE,{width:n,height:n}):h.jsx(uE,{width:n,height:n}),[cE,Gs]=cn(void 0),[fE,Xs]=cn({show:!1}),dE=()=>{const n=Tr("Home");return h.jsxs("div",{className:"card-white lg:col-span-2",onClick:n,children:[h.jsxs("h2",{className:$t.actionTitle,children:[h.jsx("span",{children:"🔎 Start new query"}),h.jsx("span",{className:"hotkey",children:"N"})]}),h.jsx("input",{className:"input mt-3 w-full",placeholder:"Search table or query to start"})]})},hE=()=>{const[n,l]=b.useState(void 0),i=Ar(Gt.EDITOR),r=u=>{i?l(u):Zt.error("You don't have permission to connect new data sources in this team")};return h.jsxs("div",{children:[n&&h.jsx(nE,{show:!0,dbType:n,onClose:()=>l(void 0)}),h.jsxs("div",{className:"card-white hover:bg-gray-50! cursor-pointer",onClick:()=>r("postgres"),children:[h.jsx("p",{className:$t.actionTitle,children:"🧙‍♂️ Connection wizard"}),h.jsx("p",{className:$t.actionSubtext,children:"Configure new database connection."})]})]})},mE=()=>{const n=Et(),{data:l}=Zd(),i=Tr("Home"),r=()=>{l&&l.length>0?n(`${Ye.workbench.path}/tab/${l[0].id}`):i()};return h.jsxs("div",{className:"card-white hover:bg-gray-50! cursor-pointer",onClick:r,children:[h.jsxs("h2",{className:$t.actionTitle,children:[h.jsx("span",{children:"🛠️ Workbench"}),h.jsx("span",{className:"hotkey",children:"W"})]}),h.jsx("p",{className:$t.actionSubtext,children:"Continue your work from where you left."})]})},pE=()=>{const{data:n}=Bn(),{data:l}=$d({teamId:n?.teamId}),i=r=>{Gs(r)};return!l||l.length===0?null:h.jsxs("div",{className:"mt-8",children:[h.jsx("h2",{className:"font-semibold text-gray-700",children:"Data sources"}),h.jsx("div",{className:"grid lg:grid-cols-3 gap-2 mt-4",children:l?.map(r=>h.jsxs("div",{className:$t.dataSourceEntry,onClick:()=>i(r.id),tabIndex:0,children:[h.jsx(ii,{size:32,type:r.dbType}),h.jsxs("div",{className:"overflow-hidden",children:[h.jsx("p",{className:"font-semibold truncate text-gray-800 flex-1",children:r.name}),r.allowInsert?h.jsx("span",{className:$t.devTag,children:"dev"}):h.jsx("span",{className:$t.prodTag,children:"prod"})]})]},r.id))})]})},yE=()=>h.jsxs("div",{className:"mt-8",children:[h.jsx("h2",{className:"font-semibold text-gray-700",children:"Useful links"}),h.jsxs("div",{className:"grid lg:grid-cols-3 gap-2 mt-4",children:[h.jsxs("a",{className:"card-white hover:bg-gray-50!",href:"https://dataramen.xyz/",children:[h.jsx("h2",{className:$t.actionTitle,children:"↗️ Documentation"}),h.jsx("p",{className:$t.actionSubtext,children:"Learn how to use DataRamen"})]}),h.jsxs("a",{className:"card-white hover:bg-gray-50!",href:"https://github.com/OleksandrDemian/dataramen",children:[h.jsx("h2",{className:$t.actionTitle,children:"↗️ Github"}),h.jsx("p",{className:$t.actionSubtext,children:"Codebase is open source"})]}),h.jsxs("a",{className:"card-white hover:bg-gray-50!",href:"#",onClick:()=>Xs({show:!0}),children:[h.jsxs("h2",{className:$t.actionTitle,children:[h.jsx("span",{children:"⌛ Recent tabs"}),h.jsx("span",{className:"hotkey",children:"H"})]}),h.jsx("p",{className:$t.actionSubtext,children:"Manage recent tabs"})]})]})]}),gE=()=>{const{data:n}=Bn(),{data:l}=$d({teamId:n?.teamId}),i=!!l&&l.length>0,r=!!n;return h.jsx("div",{className:"page-container h-screen max-h-screen bg-(--bg)",children:h.jsxs("div",{className:"page-content h-full pb-12 overflow-y-auto",children:[h.jsx("h2",{className:"font-semibold text-gray-700 mt-4 hidden lg:block",children:"Quick actions"}),r&&!i&&h.jsx(wt,{variant:"warning",className:"font-semibold mt-4",children:"Connect at least one datasource to start using DataRamen"}),h.jsxs("div",{className:"grid lg:grid-cols-2 gap-2 mt-4",children:[h.jsx(dE,{}),h.jsx(hE,{}),r&&h.jsx(mE,{})]}),r&&h.jsx(pE,{}),h.jsx(yE,{})]})})},[vE,Pd]=cn(void 0),bE=()=>Pd(void 0);function $l(n,l){if(n==null)return"";switch(l){case"json":case"jsonb":return JSON.stringify(n,null,2)}if(n===0||n===!1)return n.toString();switch(typeof n){case"string":return n;case"number":case"boolean":return n.toString();default:return JSON.stringify(n)}}const xE=n=>{const l=n.value?.map(i=>i.value).join(", ")||"";return`${n.column} ${n.operator} ${l}`},SE=n=>n.value?.map(l=>l.value).join(", ")||"",lu=n=>n.distinct?[n.fn,"DISTINCT",n.value].join(" "):[n.fn,n.value].join(" "),ol=n=>{let l=n.replace(/[_-]+/g," ");return l=l.replace(/([a-z0-9])([A-Z])/g,"$1 $2"),l=l.toLowerCase().replace(/\b\w/g,i=>i.toUpperCase()),l},wE="_container_17h05_2",EE="_header_17h05_2",CE="_fields-container_17h05_2",_E="_field-label_17h05_2",NE="_actions_17h05_2",ur={container:wE,header:EE,fieldsContainer:CE,fieldLabel:_E,actions:NE},dl=()=>Date.now().toString(36)+Math.random().toString(36).substring(2),jE=(n,l,i)=>Pt({queryKey:["entity",n,l,i],queryFn:async()=>{const r=i?i.map(([c,d])=>({id:dl(),column:c,operator:"=",value:[{value:d}],connector:"AND"})):[],{data:u}=await je.post("/runner/select",{datasourceId:n,opts:{table:l,filters:r,joins:[],columns:[],orderBy:[],groupBy:[],aggregations:[]},size:1,page:0,name:`Select ${l}: [${i?.join()}]`});return u.data},retry:1,enabled:!!l&&!!n&&!!i,staleTime:0}),TE=()=>gt({mutationFn:async n=>{const{data:l}=await je.post("/runner/update",n);return l.data}}),AE=()=>gt({mutationFn:async n=>{const{data:l}=await je.post("/runner/insert",n);return l.data}}),Jd=n=>b.useMemo(()=>{if(n)return n instanceof r3?n.response?.data.error?n.response.data.error:n.response?.data?.message?n.response.data.message:n.message:n instanceof Error?n.message:"Undefined error"},[n]),Id=()=>{const{pathname:n}=qt();return b.useMemo(()=>pr({path:`${Ye.workbench.path}/tab/:id`,end:!1},n)?.params.id,[n])},RE=({data:n})=>{const[l,{change:i,touched:r}]=Rr({}),u=Id(),{mutateAsync:c,error:d}=AE(),m=Jd(d),{data:p}=ai(n.dataSourceId),[y,v]=b.useState(""),x=b.useMemo(()=>p?.find(w=>w.tableName===n.table),[p,n.table]),E=b.useMemo(()=>{if(!x)return[];if(!y)return x.columns.map(j=>({...j,label:ol(j.name)}));const w=y.toLowerCase();return x.columns.filter(j=>j.name.toLowerCase().includes(w)).map(j=>({...j,label:ol(j.name)}))},[y,x]),C=()=>{const w=[];for(const j of r)w.push({value:l[j],column:j});c({datasourceId:n.dataSourceId,table:n.table,values:w}).then(()=>{bE(),u&&bg(u)})};return h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:ur.header,children:[h.jsxs("p",{className:"text-lg font-semibold",children:["Insert new row in ",h.jsx("span",{className:"underline",children:n.table})]}),m&&h.jsx(wt,{variant:"danger",children:h.jsx("p",{children:m})})]}),h.jsx("div",{className:"bg-gray-50 py-1 px-4 border-y border-gray-200",children:h.jsx("p",{className:"text-xs text-gray-800",children:"Tip: use = to write raw SQL. Ex: =NULL or =NOW()"})}),h.jsx("div",{className:ur.container,children:h.jsx("div",{className:ur.fieldsContainer,children:E.map(w=>h.jsxs("label",{className:ur.fieldLabel,children:[h.jsxs("div",{className:"flex justify-between",children:[h.jsxs("p",{children:[w.isPrimary?"🔐":"🏷️"," ",w.label]}),h.jsxs("p",{className:"text-blue-800 text-sm",children:["[",w.name,": ",w.type,"]"]})]}),h.jsx("input",{className:"input w-full",value:$l(l[w.name]),onChange:i(w.name),placeholder:w.name})]},w.name))})}),h.jsxs("div",{className:ur.actions,children:[h.jsxs("label",{children:[h.jsx("span",{className:"mr-2",children:"🔎"}),h.jsx("input",{className:"input bg-white!",value:y,onChange:w=>v(w.target.value),placeholder:"Filter columns"})]}),h.jsx("span",{className:"flex-1"}),h.jsx("button",{disabled:!r.length,className:"button primary",onClick:C,children:"Run insert"})]})]})},OE=()=>{const n=vE(),[l,i]=b.useState(void 0);b.useEffect(()=>{n&&i(n)},[n]);const r=()=>Pd(void 0);return h.jsxs(fn,{isVisible:n!=null,onClose:r,onClosed:()=>i(void 0),noPadding:!0,children:[h.jsx(aa,{onClick:r}),l&&h.jsx(RE,{data:l})]})},[DE,Wd]=cn(void 0),ME=()=>Wd(void 0),LE="_container_erj1q_2",UE="_header_erj1q_2",zE="_key_erj1q_2",kE="_fields-container_erj1q_2",qE="_field-label_erj1q_2",BE="_actions_erj1q_2",Bs={container:LE,header:UE,key:zE,fieldsContainer:kE,fieldLabel:qE,actions:BE},HE=({data:n})=>{const[l,{change:i,set:r,reset:u,touched:c}]=Rr({}),d=Id(),[m,p]=b.useState(""),{data:y,isLoading:v}=jE(n.dataSourceId,n.tableName,n.entityId),{mutateAsync:x,error:E}=TE(),C=Jd(E),w=Ar(Gt.EDITOR),{data:j}=ai(n.dataSourceId),{data:N}=Nu(n.dataSourceId),T=b.useMemo(()=>j?.find(Y=>Y.tableName===n.tableName),[n.tableName,j]),_=b.useMemo(()=>{if(!T)return[];if(!m)return T.columns.map(K=>({...K,label:ol(K.name)}));const Y=m.toLowerCase();return T.columns.filter(K=>K.name.toLowerCase().includes(Y)).map(K=>({...K,label:ol(K.name)}))},[m,T]);b.useEffect(()=>{const Y=y?.rows[0];if(u(),Y&&y?.columns)for(let K=0;K<y.columns.length;K++){const Z=y.columns[K];r(Z.column,$l(Y[K]))}},[y,r,u]);const O=()=>{const Y=[];for(const K of c)Y.push({value:l[K],column:K});x({datasourceId:n.dataSourceId,table:n.tableName,filters:n.entityId.map(K=>({id:dl(),value:[{value:K[1]}],column:K[0],connector:"AND",operator:"="})),values:Y}).then(()=>{ME(),d&&bg(d)})},H=n.entityId.map(([Y,K])=>`${Y} = ${K}`).join(", ")||"",G=!N?.allowUpdate||!w;return h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:Bs.header,children:[h.jsxs("p",{className:"text-lg font-semibold",children:[G?"View":"Edit"," row in ",h.jsx("span",{className:"underline",children:n?.tableName})]}),h.jsx("span",{className:Bs.key,children:H}),C&&h.jsx(wt,{variant:"danger",children:h.jsx("p",{children:C})})]}),!G&&h.jsx("div",{className:"bg-gray-50 py-1 px-4 border-y border-gray-200",children:h.jsx("p",{className:"text-xs text-gray-800",children:"Tip: use = to write raw SQL. Ex: =NULL or =NOW()"})}),h.jsx("div",{className:Bs.container,children:h.jsx("div",{className:Bs.fieldsContainer,children:_.map(Y=>h.jsxs("label",{className:Bs.fieldLabel,children:[h.jsxs("div",{className:"flex justify-between",children:[h.jsxs("p",{children:[Y.isPrimary?"🔐":"🏷️"," ",Y.label]}),h.jsxs("p",{className:"text-blue-800 text-sm",children:["[",Y.name,": ",Y.type,"]"]})]}),h.jsx("input",{disabled:Y.isPrimary||v||G,className:"input w-full",value:$l(l[Y.name]),onChange:i(Y.name),placeholder:Y.name})]},Y.name))})}),h.jsxs("div",{className:Bs.actions,children:[h.jsxs("label",{children:[h.jsx("span",{className:"mr-2",children:"🔎"}),h.jsx("input",{className:"input bg-white!",value:m,onChange:Y=>p(Y.target.value),placeholder:"Filter columns"})]}),h.jsx("span",{className:"flex-1"}),!G&&h.jsx("button",{disabled:!c.length,className:"button primary",onClick:O,children:"Run update"})]})]})},QE=()=>{const n=DE(),[l,i]=b.useState(void 0);b.useEffect(()=>{n&&i(n)},[n]);const r=()=>Wd(void 0);return h.jsxs(fn,{isVisible:n!=null,onClose:r,onClosed:()=>i(void 0),noPadding:!0,children:[h.jsx(aa,{onClick:r}),l&&h.jsx(HE,{data:l})]})},[YE,Jf]=cn(void 0),wg=async n=>new Promise(l=>{Jf({message:n,onCancel:()=>{l(!1),Jf(void 0)},onConfirm:()=>{l(!0),Jf(void 0)}})}),VE=({confirm:n})=>h.jsxs("div",{children:[h.jsx("p",{children:n.message}),h.jsxs("div",{className:"flex gap-2 justify-end mt-4",children:[h.jsx("button",{className:"button tertiary",onClick:n.onCancel,children:"Cancel"}),h.jsx("button",{className:"button primary",onClick:n.onConfirm,children:"Confirm"})]})]}),KE=()=>{const n=YE(),[l,i]=b.useState(void 0);return b.useEffect(()=>{n&&i(n)},[n]),h.jsx(fn,{isVisible:!!n,onClose:()=>n?.onCancel(),onClosed:()=>i(void 0),children:l&&h.jsx(VE,{confirm:l})})},[$E,su]=cn(void 0),Or=async(n,l,i)=>new Promise(r=>{su({message:n,defaultValue:l,alert:i,onCancel:()=>{su(void 0),r(void 0)},onConfirm:u=>{su(void 0),r(u)}})}),GE="_root_12mtw_1",XE={root:GE},FE=({data:n})=>{const[l,i]=b.useState("");b.useEffect(()=>{n.defaultValue&&i(n.defaultValue)},[n]);const r=c=>{i(c.target.value)},u=c=>{c.key==="Enter"&&(c.preventDefault(),n.onConfirm(l)),c.key==="Escape"&&(c.preventDefault(),n.onCancel())};return h.jsxs("div",{className:XE.root,children:[h.jsx("h2",{className:"text-xl font-semibold",children:n.message}),n.alert&&h.jsx(wt,{variant:n.alert.type,className:"mt-2",children:n.alert.message}),h.jsx("input",{autoFocus:!0,className:"w-full input my-2",value:l,onChange:r,onKeyDown:u}),h.jsxs("div",{className:"flex justify-end gap-2",children:[h.jsx("button",{className:"button tertiary",onClick:n.onCancel,children:"Cancel"}),h.jsx("button",{className:"button primary",onClick:()=>n.onConfirm(l),children:"Confirm"})]})]})},ZE=()=>{const n=$E(),[l,i]=b.useState(void 0);return b.useEffect(()=>{n&&i(n)},[n]),h.jsx(fn,{isVisible:!!n,onClose:()=>su(void 0),onClosed:()=>i(void 0),children:l&&h.jsx(FE,{data:l})})},[PE,JE]=cn(void 0),Eg=n=>{JE(n)},IE="_textarea_ay8hc_2",WE={textarea:IE},e6=()=>{const n=PE(),l=()=>{n&&(navigator.clipboard.writeText(n.toString()),Zt.success("Copied!"))},i=()=>Eg(void 0);return h.jsxs(fn,{isVisible:!!n,onClose:i,backdropClose:!0,children:[h.jsx("textarea",{className:WE.textarea,readOnly:!0,defaultValue:n?.toString()}),h.jsxs("div",{className:"mt-2 flex gap-1 justify-end",children:[h.jsx("button",{className:"button primary",onClick:l,children:"Copy"}),h.jsx("button",{className:"button tertiary",onClick:i,children:"Close"})]})]})},t6="_tabs_5g9zx_2",n6="_mobile_5g9zx_2",a6="_tab_5g9zx_2",l6="_active_5g9zx_2",s6="_close-button_5g9zx_2",cr={tabs:t6,mobile:n6,tab:a6,active:l6,closeButton:s6},My=n=>window.matchMedia(n).matches;function Cg(n,{defaultValue:l=!1,initializeWithValue:i=!0}={}){const[r,u]=b.useState(()=>i?My(n):l);return b.useLayoutEffect(()=>{const c=window.matchMedia(n);function d(){u(()=>My(n))}return d(),c.addListener?c.addListener(d):c.addEventListener("change",d),()=>{c.removeListener?c.removeListener(d):c.removeEventListener("change",d)}},[n]),r}const eh={laptop:"(min-width: 1024px)"},i6=()=>window.matchMedia(eh.laptop).matches,r6="_table_1rsid_2",o6="_semi-transparent_1rsid_2",u6="_table-loading_1rsid_2",c6="_table-empty_1rsid_2",f6="_table-row-cells_1rsid_2",d6="_header-cell_1rsid_2",h6="_header-actions_1rsid_2",m6="_cell_1rsid_2",p6="_cell-actions_1rsid_2",y6="_value_1rsid_2",g6="_table-config_1rsid_2",v6="_tab-name_1rsid_2",b6="_table-action_1rsid_2",x6="_blue_1rsid_2",S6="_modal_1rsid_2",w6="_selected-size_1rsid_2",E6="_options-container_1rsid_2",C6="_row-options-entries-list_1rsid_2",_6="_underlying-rows-btn_1rsid_2",N6="_option-item_1rsid_2",j6="_pagination-indicator_1rsid_2",se={table:r6,semiTransparent:o6,tableLoading:u6,tableEmpty:c6,tableRowCells:f6,headerCell:d6,headerActions:h6,cell:m6,cellActions:p6,value:y6,tableConfig:g6,tabName:v6,tableAction:b6,blue:x6,modal:S6,selectedSize:w6,optionsContainer:E6,rowOptionsEntriesList:C6,underlyingRowsBtn:_6,optionItem:N6,paginationIndicator:j6},gl=b.createContext({name:"No name",hooks:[],availableJoins:[],allColumns:[],dataSourceId:"",entities:[],getValue:()=>{},getColumnType:()=>{},getEntityKey:()=>[]}),Jt=b.createContext({state:$s({}),setState:()=>{}}),Ra=b.createContext({}),_g={ON_ANIMATION_END:Symbol("ON_TRANSITION_END")},Ng=()=>{const[n,l]=b.useState(),[i,r]=b.useState("hidden");return b.useMemo(()=>{const u=m=>{m.preventDefault(),r("in"),l({x:m.clientX-1,y:m.clientY-1})},c=()=>{r("out")},d=m=>{console.log("onAnimationEnd",m),i==="in"?r("visible"):i==="out"&&(l(void 0),r("hidden"))};return{show:!!n,position:n,state:i,open:u,close:c,[_g.ON_ANIMATION_END]:d}},[n,i])},T6=n=>{if(n==="ASC")return"DESC";if(n!=="DESC")return"ASC"},A6=()=>{const{state:n,setState:l}=b.useContext(Jt),i=b.useCallback(r=>{l(u=>{const c=u.orderBy[0];if(c&&c.column===r){const d=T6(c.direction);return d?{...u,orderBy:[{column:r,direction:d}]}:{...u,orderBy:[]}}return{...u,orderBy:[{column:r,direction:"ASC"}]}})},[l]);return{orderBy:n.orderBy,updateOrderBy:i}};function R6(n){const l=n.target?.dataset;if(l){if(l.copyCol&&l.copyRow)return{col:parseInt(l.copyCol),row:parseInt(l.copyRow),action:"copy"};if(l.showCol&&l.showRow)return{col:parseInt(l.showCol),row:parseInt(l.showRow),action:"show"};if(l.filterCol&&l.filterRow)return{col:parseInt(l.filterCol),row:parseInt(l.filterRow),action:"filter"}}}function If(n,l,i){const r=n?.rows?.[l]?.[i],u=n?.columns?.[i];return{value:r,column:u}}const O6=()=>{const{data:n}=b.useContext(Ra),{getColumnType:l}=b.useContext(gl),{setState:i}=b.useContext(Jt),r=m=>{const{value:p,column:y}=If(n?.result,m.row,m.col);if(y){const v=$l(p,l(y.full));navigator.clipboard.writeText(v),Zt.success("Copied!")}},u=m=>{const{value:p,column:y}=If(n?.result,m.row,m.col);if(y){const v=$l(p,l(y.full));Eg(v)}},c=m=>{const{value:p,column:y}=If(n?.result,m.row,m.col);let v=y?.full||"",x;if(y?.table===""){Zt.error("Filtering on aggregated column is not supported yet");return}if(v){let E;if(p==null)E={id:dl(),isEnabled:!0,column:v,connector:"AND",operator:"IS NULL"};else{const C=$l(p,l(v));E={id:dl(),isEnabled:!0,column:v,connector:"AND",operator:"=",fn:x,value:[{value:C}]}}i(C=>({...C,filters:[...C.filters,E]})),Zt.success(`Added new filter on column ${y?.alias}`)}};return m=>{const p=R6(m);p&&(p.action==="copy"?r(p):p.action==="show"?u(p):p.action==="filter"&&c(p))}},D6="_container_1h5uv_2",M6="_animate-show_1h5uv_2",L6="_animate-hide_1h5uv_2",U6="_content_1h5uv_2",z6="_backdrop_1h5uv_2",Hl={container:D6,animateShow:M6,animateHide:L6,content:U6,backdrop:z6},jg=({children:n,handler:l})=>{const i=b.useRef(l.close);i.current=l.close;const r=b.useMemo(()=>{if(!l.position)return;const u={};if(typeof window<"u"){const c=l.position.y>window.innerHeight/2,d=l.position.x>window.innerWidth/2;c?u.bottom=window.innerHeight-l.position.y:u.top=l.position.y,i6()?d?u.right=window.innerWidth-l.position.x:u.left=l.position.x:(u.right=36,u.left=36)}return u},[l.position]);return b.useEffect(()=>{const u=c=>{c.code==="Escape"&&i.current()};return window.addEventListener("keyup",u),()=>{window.removeEventListener("keyup",u)}},[]),r?h.jsxs("div",{className:re(Hl.container,l.state==="out"&&Hl.animateHide,l.state==="in"&&Hl.animateShow),onAnimationEnd:l[_g.ON_ANIMATION_END],children:[h.jsx("div",{className:Hl.backdrop,onClick:u=>{u.stopPropagation(),u.preventDefault(),l.close()}}),h.jsx("div",{className:re(Hl.content,l.state==="out"&&Hl.animateHide,l.state==="in"&&Hl.animateShow),style:r,children:n})]}):null},k6="_table_1orj8_2",q6="_root_1orj8_2",B6="_content_1orj8_2",H6="_sub_1orj8_2",Zo={table:k6,root:q6,content:B6,sub:H6},Tg=({hook:n,onClick:l})=>h.jsxs("button",{className:Zo.root,onClick:l,children:[h.jsx("span",{children:"📄"}),h.jsxs("div",{className:Zo.content,children:[h.jsxs("p",{className:Zo.table,children:[" ",n.on.toTable]}),h.jsxs("span",{className:Zo.sub,children:[n.on.toColumn," = ",n.on.fromTable,".",n.on.fromColumn]})]})]},n.where),hl=(n,l)=>n!=null&&n>l,Q6=({handler:n,rowIndex:l})=>{const{hooks:i,entities:r,dataSourceId:u,getEntityKey:c,getValue:d}=b.useContext(gl),{state:m}=b.useContext(Jt),{data:p}=b.useContext(Ra),[y,v]=b.useState(""),x=b.useMemo(()=>p?.result.rows[l],[p,l]),E=si(),C=Et(),[w,j]=b.useState("hooks"),N=()=>{x&&E.mutateAsync({name:`${m.table} > [${m.joins.map(Y=>Y.table).join()}]`,opts:$s({joins:m.joins,table:m.table,dataSourceId:m.dataSourceId,filters:[...m.filters,...m.groupBy.map(Y=>({id:dl(),connector:"AND",column:Y.value,operator:"=",value:[{value:d(x,Y)}]}))]})}).then(Y=>{C(`${Ye.workbench.path}/tab/${Y.id}`),n.close()})},T=Y=>{if(!x)return;const K=d(x,{value:`${Y.on.fromTable}.${Y.on.fromColumn}`});E.mutateAsync({name:`${Y.on.toTable} ${Y.on.toColumn} equals ${K}`,opts:$s({table:Y.on.toTable,dataSourceId:u,filters:[{id:dl(),column:`${Y.on.toTable}.${Y.on.toColumn}`,operator:K==null?"IS NULL":"=",connector:"AND",value:K!=null?[{value:K,isColumn:!1}]:void 0}]})}).then(Z=>{C(`${Ye.workbench.path}/tab/${Z.id}`),n.close()})},_=Y=>{if(!x)return;const K=c(Y,x);n.close(),Wd({tableName:Y,dataSourceId:u,entityId:K}),n.close()},O=b.useMemo(()=>y?r.filter(Y=>Y.includes(y)):r,[r,y]),H=b.useMemo(()=>{if(!p)return[];const Y=y.toLowerCase();return i.filter(K=>p.result.columns.some(te=>te.column===K.on.fromColumn&&te.table===K.on.fromTable)?K.on.toTable.toLowerCase().includes(Y):!1)},[y,i,p]),G=m.groupBy.length>0;return h.jsx(jg,{handler:n,children:h.jsxs("div",{className:se.optionsContainer,children:[h.jsxs("div",{className:"grid grid-cols-2 mb-2",children:[h.jsx("button",{className:re("p-2 cursor-pointer border-b",w==="hooks"?"border-white":"border-r rounded-br-lg border-gray-200 bg-gray-50 text-gray-400"),onClick:()=>j("hooks"),children:"Drill down"}),h.jsx("button",{className:re("p-2 cursor-pointer border-b",w==="entities"?"border-white":"border-l rounded-bl-lg border-gray-200 bg-gray-50 text-gray-400"),onClick:()=>j("entities"),children:"Entities"})]}),h.jsx("input",{className:"input mx-2",placeholder:"Filter",value:y,onChange:Y=>v(Y.target.value)}),w==="entities"&&r.length>0&&h.jsx("div",{className:se.rowOptionsEntriesList,children:hl(O.length,0)?O.map(Y=>h.jsx("button",{className:re(se.optionItem,"font-semibold"),onClick:()=>_(Y),children:h.jsxs("span",{children:["📄 ",Y]})},Y)):h.jsx("p",{className:"text-center p-2 text-gray-800",children:"Empty"})}),w==="hooks"&&i.length>0&&h.jsx("div",{className:se.rowOptionsEntriesList,children:H.length>0?H.map(Y=>h.jsx(Tg,{hook:Y,onClick:()=>T(Y)},Y.where)):h.jsx("p",{className:"text-center p-2 text-gray-800",children:"Empty"})}),G&&h.jsx("button",{onClick:N,className:se.underlyingRowsBtn,children:"🎯 Underlying rows"})]})})},Y6={ASC:"⬆️",DESC:"⬇️"},V6=()=>{const{data:n}=b.useContext(Ra),{orderBy:l,updateOrderBy:i}=A6(),r=n?.result.columns||[],u=l[0],c=hl(n?.result.tables.length,1);return h.jsx("thead",{children:h.jsxs("tr",{children:[h.jsx("td",{className:"py-1 px-4 text-center text-sm text-gray-600 border-r",children:"#"}),r.map(d=>h.jsxs("td",{className:se.headerCell,children:[h.jsxs("div",{className:"overflow-hidden",children:[c&&h.jsx("p",{className:"text-xs truncate italic",children:d.table||"-"}),h.jsx("p",{className:"text-sm font-semibold truncate",children:d.column})]}),h.jsx("div",{className:se.headerActions,children:h.jsx("button",{onClick:()=>i(d.full),children:u?.column===d.full?Y6[u.direction]:"↕️"})})]},d.full))]})})};function K6({value:n,row:l,col:i}){if(n==="")return h.jsx("span",{className:"pointer-events-none text-black/30 truncate",children:"<EMPTY STRING>"});if(n==null)return h.jsx("span",{className:"pointer-events-none text-black/30",children:"<NULL>"});const r=$l(n);return h.jsxs(h.Fragment,{children:[h.jsx("span",{"data-row":l,className:se.value,children:r}),h.jsxs("div",{className:se.cellActions,children:[h.jsx("button",{"data-copy-col":i,"data-copy-row":l,children:"📋"}),h.jsx("button",{"data-show-col":i,"data-show-row":l,children:"👀"}),h.jsx("button",{"data-filter-col":i,"data-filter-row":l,children:"🔎"})]})]})}const $6=b.memo(({row:n,isLastRow:l,index:i,offset:r})=>h.jsxs("tr",{className:re(se.tableRowCells,l&&"rounded-b-lg"),children:[h.jsx("td",{className:"py-1 px-4 text-center align-middle text-xs w-8 text-blue-500 border-r",children:i+1+r}),n.map((u,c)=>h.jsx("td",{className:se.cell,"data-row":i,children:h.jsx(K6,{value:u,col:c,row:i})},c))]})),G6=()=>{const{data:n,error:l,isLoading:i,isFetching:r}=b.useContext(Ra),{state:{page:u,size:c}}=b.useContext(Jt),d=Jd(l),m=O6(),p=Ng(),[y,v]=b.useState(void 0),x=C=>{const j=C.target?.dataset?.row;j!=null&&(v(parseInt(j)),p.open(C))},E=u*c;return h.jsxs(h.Fragment,{children:[y!=null&&p.show&&h.jsx(Q6,{handler:p,rowIndex:y}),d&&h.jsx(wt,{className:"my-4",variant:"danger",children:d}),i&&h.jsx("div",{className:se.tableLoading,children:"Loading data"}),n&&h.jsxs("table",{className:re(se.table,r&&se.semiTransparent),onContextMenu:x,onClick:m,children:[h.jsx(V6,{}),h.jsxs("tbody",{children:[n.result.rows?.length<1&&h.jsx("tr",{className:se.tableEmpty,children:h.jsx("td",{colSpan:n.result.columns.length+1,children:"No data"})}),n.result.rows?.map((C,w)=>h.jsx($6,{index:w,offset:E,row:C,isLastRow:w===n.result.rows.length-1},w))]})]})]})},X6=()=>{const{state:n,setState:l}=b.useContext(Jt),i=b.useCallback(u=>{l(c=>({...c,page:u}))},[l]),r=b.useCallback((u,c=!1)=>{l(d=>({...d,size:u,page:c?0:d.page}))},[l]);return{page:n.page,size:n.size,setSize:r,setPage:i}},F6=()=>gt({mutationFn:async n=>{const{data:l}=await je.post("/saved-queries",n);return l.data},onSuccess:()=>{rt.invalidateQueries({queryKey:["queries"]}),ni()}}),Z6=()=>gt({mutationFn:async n=>je.delete("/saved-queries/"+n),onSuccess:()=>{ni()}}),P6=()=>gt({mutationFn:async({id:n,payload:l})=>{const{data:i}=await je.patch("/saved-queries/"+n,l);return i.data},onSuccess:()=>{ni(),a4()}}),[ju,th]=cn({filters:!1,joins:!1,columns:!1,groupBy:!1,aggregate:!1}),Ln=n=>th(l=>({...l,[n]:!0})),Tu=n=>th(l=>({...l,[n]:!1})),hu=n=>th(l=>({...l,[n]:!l[n]})),Fs=Math.min,Gl=Math.max,mu=Math.round,Po=Math.floor,Wn=n=>({x:n,y:n}),J6={left:"right",right:"left",bottom:"top",top:"bottom"},I6={start:"end",end:"start"};function Ed(n,l,i){return Gl(n,Fs(l,i))}function Dr(n,l){return typeof n=="function"?n(l):n}function Jl(n){return n.split("-")[0]}function Mr(n){return n.split("-")[1]}function Ag(n){return n==="x"?"y":"x"}function nh(n){return n==="y"?"height":"width"}function ul(n){return["top","bottom"].includes(Jl(n))?"y":"x"}function ah(n){return Ag(ul(n))}function W6(n,l,i){i===void 0&&(i=!1);const r=Mr(n),u=ah(n),c=nh(u);let d=u==="x"?r===(i?"end":"start")?"right":"left":r==="start"?"bottom":"top";return l.reference[c]>l.floating[c]&&(d=pu(d)),[d,pu(d)]}function eC(n){const l=pu(n);return[Cd(n),l,Cd(l)]}function Cd(n){return n.replace(/start|end/g,l=>I6[l])}function tC(n,l,i){const r=["left","right"],u=["right","left"],c=["top","bottom"],d=["bottom","top"];switch(n){case"top":case"bottom":return i?l?u:r:l?r:u;case"left":case"right":return l?c:d;default:return[]}}function nC(n,l,i,r){const u=Mr(n);let c=tC(Jl(n),i==="start",r);return u&&(c=c.map(d=>d+"-"+u),l&&(c=c.concat(c.map(Cd)))),c}function pu(n){return n.replace(/left|right|bottom|top/g,l=>J6[l])}function aC(n){return{top:0,right:0,bottom:0,left:0,...n}}function Rg(n){return typeof n!="number"?aC(n):{top:n,right:n,bottom:n,left:n}}function yu(n){const{x:l,y:i,width:r,height:u}=n;return{width:r,height:u,top:i,left:l,right:l+r,bottom:i+u,x:l,y:i}}function Ly(n,l,i){let{reference:r,floating:u}=n;const c=ul(l),d=ah(l),m=nh(d),p=Jl(l),y=c==="y",v=r.x+r.width/2-u.width/2,x=r.y+r.height/2-u.height/2,E=r[m]/2-u[m]/2;let C;switch(p){case"top":C={x:v,y:r.y-u.height};break;case"bottom":C={x:v,y:r.y+r.height};break;case"right":C={x:r.x+r.width,y:x};break;case"left":C={x:r.x-u.width,y:x};break;default:C={x:r.x,y:r.y}}switch(Mr(l)){case"start":C[d]-=E*(i&&y?-1:1);break;case"end":C[d]+=E*(i&&y?-1:1);break}return C}const lC=async(n,l,i)=>{const{placement:r="bottom",strategy:u="absolute",middleware:c=[],platform:d}=i,m=c.filter(Boolean),p=await(d.isRTL==null?void 0:d.isRTL(l));let y=await d.getElementRects({reference:n,floating:l,strategy:u}),{x:v,y:x}=Ly(y,r,p),E=r,C={},w=0;for(let j=0;j<m.length;j++){const{name:N,fn:T}=m[j],{x:_,y:O,data:H,reset:G}=await T({x:v,y:x,initialPlacement:r,placement:E,strategy:u,middlewareData:C,rects:y,platform:d,elements:{reference:n,floating:l}});v=_??v,x=O??x,C={...C,[N]:{...C[N],...H}},G&&w<=50&&(w++,typeof G=="object"&&(G.placement&&(E=G.placement),G.rects&&(y=G.rects===!0?await d.getElementRects({reference:n,floating:l,strategy:u}):G.rects),{x:v,y:x}=Ly(y,E,p)),j=-1)}return{x:v,y:x,placement:E,strategy:u,middlewareData:C}};async function Og(n,l){var i;l===void 0&&(l={});const{x:r,y:u,platform:c,rects:d,elements:m,strategy:p}=n,{boundary:y="clippingAncestors",rootBoundary:v="viewport",elementContext:x="floating",altBoundary:E=!1,padding:C=0}=Dr(l,n),w=Rg(C),N=m[E?x==="floating"?"reference":"floating":x],T=yu(await c.getClippingRect({element:(i=await(c.isElement==null?void 0:c.isElement(N)))==null||i?N:N.contextElement||await(c.getDocumentElement==null?void 0:c.getDocumentElement(m.floating)),boundary:y,rootBoundary:v,strategy:p})),_=x==="floating"?{x:r,y:u,width:d.floating.width,height:d.floating.height}:d.reference,O=await(c.getOffsetParent==null?void 0:c.getOffsetParent(m.floating)),H=await(c.isElement==null?void 0:c.isElement(O))?await(c.getScale==null?void 0:c.getScale(O))||{x:1,y:1}:{x:1,y:1},G=yu(c.convertOffsetParentRelativeRectToViewportRelativeRect?await c.convertOffsetParentRelativeRectToViewportRelativeRect({elements:m,rect:_,offsetParent:O,strategy:p}):_);return{top:(T.top-G.top+w.top)/H.y,bottom:(G.bottom-T.bottom+w.bottom)/H.y,left:(T.left-G.left+w.left)/H.x,right:(G.right-T.right+w.right)/H.x}}const sC=n=>({name:"arrow",options:n,async fn(l){const{x:i,y:r,placement:u,rects:c,platform:d,elements:m,middlewareData:p}=l,{element:y,padding:v=0}=Dr(n,l)||{};if(y==null)return{};const x=Rg(v),E={x:i,y:r},C=ah(u),w=nh(C),j=await d.getDimensions(y),N=C==="y",T=N?"top":"left",_=N?"bottom":"right",O=N?"clientHeight":"clientWidth",H=c.reference[w]+c.reference[C]-E[C]-c.floating[w],G=E[C]-c.reference[C],Y=await(d.getOffsetParent==null?void 0:d.getOffsetParent(y));let K=Y?Y[O]:0;(!K||!await(d.isElement==null?void 0:d.isElement(Y)))&&(K=m.floating[O]||c.floating[w]);const Z=H/2-G/2,te=K/2-j[w]/2-1,ye=Fs(x[T],te),Ae=Fs(x[_],te),Ce=ye,$e=K-j[w]-Ae,me=K/2-j[w]/2+Z,_e=Ed(Ce,me,$e),q=!p.arrow&&Mr(u)!=null&&me!==_e&&c.reference[w]/2-(me<Ce?ye:Ae)-j[w]/2<0,F=q?me<Ce?me-Ce:me-$e:0;return{[C]:E[C]+F,data:{[C]:_e,centerOffset:me-_e-F,...q&&{alignmentOffset:F}},reset:q}}}),iC=function(n){return n===void 0&&(n={}),{name:"flip",options:n,async fn(l){var i,r;const{placement:u,middlewareData:c,rects:d,initialPlacement:m,platform:p,elements:y}=l,{mainAxis:v=!0,crossAxis:x=!0,fallbackPlacements:E,fallbackStrategy:C="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:j=!0,...N}=Dr(n,l);if((i=c.arrow)!=null&&i.alignmentOffset)return{};const T=Jl(u),_=ul(m),O=Jl(m)===m,H=await(p.isRTL==null?void 0:p.isRTL(y.floating)),G=E||(O||!j?[pu(m)]:eC(m)),Y=w!=="none";!E&&Y&&G.push(...nC(m,j,w,H));const K=[m,...G],Z=await Og(l,N),te=[];let ye=((r=c.flip)==null?void 0:r.overflows)||[];if(v&&te.push(Z[T]),x){const me=W6(u,d,H);te.push(Z[me[0]],Z[me[1]])}if(ye=[...ye,{placement:u,overflows:te}],!te.every(me=>me<=0)){var Ae,Ce;const me=(((Ae=c.flip)==null?void 0:Ae.index)||0)+1,_e=K[me];if(_e&&(!(x==="alignment"?_!==ul(_e):!1)||ye.every(J=>J.overflows[0]>0&&ul(J.placement)===_)))return{data:{index:me,overflows:ye},reset:{placement:_e}};let q=(Ce=ye.filter(F=>F.overflows[0]<=0).sort((F,J)=>F.overflows[1]-J.overflows[1])[0])==null?void 0:Ce.placement;if(!q)switch(C){case"bestFit":{var $e;const F=($e=ye.filter(J=>{if(Y){const he=ul(J.placement);return he===_||he==="y"}return!0}).map(J=>[J.placement,J.overflows.filter(he=>he>0).reduce((he,R)=>he+R,0)]).sort((J,he)=>J[1]-he[1])[0])==null?void 0:$e[0];F&&(q=F);break}case"initialPlacement":q=m;break}if(u!==q)return{reset:{placement:q}}}return{}}}};async function rC(n,l){const{placement:i,platform:r,elements:u}=n,c=await(r.isRTL==null?void 0:r.isRTL(u.floating)),d=Jl(i),m=Mr(i),p=ul(i)==="y",y=["left","top"].includes(d)?-1:1,v=c&&p?-1:1,x=Dr(l,n);let{mainAxis:E,crossAxis:C,alignmentAxis:w}=typeof x=="number"?{mainAxis:x,crossAxis:0,alignmentAxis:null}:{mainAxis:x.mainAxis||0,crossAxis:x.crossAxis||0,alignmentAxis:x.alignmentAxis};return m&&typeof w=="number"&&(C=m==="end"?w*-1:w),p?{x:C*v,y:E*y}:{x:E*y,y:C*v}}const oC=function(n){return n===void 0&&(n=0),{name:"offset",options:n,async fn(l){var i,r;const{x:u,y:c,placement:d,middlewareData:m}=l,p=await rC(l,n);return d===((i=m.offset)==null?void 0:i.placement)&&(r=m.arrow)!=null&&r.alignmentOffset?{}:{x:u+p.x,y:c+p.y,data:{...p,placement:d}}}}},uC=function(n){return n===void 0&&(n={}),{name:"shift",options:n,async fn(l){const{x:i,y:r,placement:u}=l,{mainAxis:c=!0,crossAxis:d=!1,limiter:m={fn:N=>{let{x:T,y:_}=N;return{x:T,y:_}}},...p}=Dr(n,l),y={x:i,y:r},v=await Og(l,p),x=ul(Jl(u)),E=Ag(x);let C=y[E],w=y[x];if(c){const N=E==="y"?"top":"left",T=E==="y"?"bottom":"right",_=C+v[N],O=C-v[T];C=Ed(_,C,O)}if(d){const N=x==="y"?"top":"left",T=x==="y"?"bottom":"right",_=w+v[N],O=w-v[T];w=Ed(_,w,O)}const j=m.fn({...l,[E]:C,[x]:w});return{...j,data:{x:j.x-i,y:j.y-r,enabled:{[E]:c,[x]:d}}}}}};function Au(){return typeof window<"u"}function ri(n){return Dg(n)?(n.nodeName||"").toLowerCase():"#document"}function on(n){var l;return(n==null||(l=n.ownerDocument)==null?void 0:l.defaultView)||window}function la(n){var l;return(l=(Dg(n)?n.ownerDocument:n.document)||window.document)==null?void 0:l.documentElement}function Dg(n){return Au()?n instanceof Node||n instanceof on(n).Node:!1}function zn(n){return Au()?n instanceof Element||n instanceof on(n).Element:!1}function ea(n){return Au()?n instanceof HTMLElement||n instanceof on(n).HTMLElement:!1}function Uy(n){return!Au()||typeof ShadowRoot>"u"?!1:n instanceof ShadowRoot||n instanceof on(n).ShadowRoot}function Lr(n){const{overflow:l,overflowX:i,overflowY:r,display:u}=kn(n);return/auto|scroll|overlay|hidden|clip/.test(l+r+i)&&!["inline","contents"].includes(u)}function cC(n){return["table","td","th"].includes(ri(n))}function Ru(n){return[":popover-open",":modal"].some(l=>{try{return n.matches(l)}catch{return!1}})}function lh(n){const l=sh(),i=zn(n)?kn(n):n;return["transform","translate","scale","rotate","perspective"].some(r=>i[r]?i[r]!=="none":!1)||(i.containerType?i.containerType!=="normal":!1)||!l&&(i.backdropFilter?i.backdropFilter!=="none":!1)||!l&&(i.filter?i.filter!=="none":!1)||["transform","translate","scale","rotate","perspective","filter"].some(r=>(i.willChange||"").includes(r))||["paint","layout","strict","content"].some(r=>(i.contain||"").includes(r))}function fC(n){let l=ml(n);for(;ea(l)&&!Zs(l);){if(lh(l))return l;if(Ru(l))return null;l=ml(l)}return null}function sh(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function Zs(n){return["html","body","#document"].includes(ri(n))}function kn(n){return on(n).getComputedStyle(n)}function Ou(n){return zn(n)?{scrollLeft:n.scrollLeft,scrollTop:n.scrollTop}:{scrollLeft:n.scrollX,scrollTop:n.scrollY}}function ml(n){if(ri(n)==="html")return n;const l=n.assignedSlot||n.parentNode||Uy(n)&&n.host||la(n);return Uy(l)?l.host:l}function Mg(n){const l=ml(n);return Zs(l)?n.ownerDocument?n.ownerDocument.body:n.body:ea(l)&&Lr(l)?l:Mg(l)}function gr(n,l,i){var r;l===void 0&&(l=[]),i===void 0&&(i=!0);const u=Mg(n),c=u===((r=n.ownerDocument)==null?void 0:r.body),d=on(u);if(c){const m=_d(d);return l.concat(d,d.visualViewport||[],Lr(u)?u:[],m&&i?gr(m):[])}return l.concat(u,gr(u,[],i))}function _d(n){return n.parent&&Object.getPrototypeOf(n.parent)?n.frameElement:null}function Lg(n){const l=kn(n);let i=parseFloat(l.width)||0,r=parseFloat(l.height)||0;const u=ea(n),c=u?n.offsetWidth:i,d=u?n.offsetHeight:r,m=mu(i)!==c||mu(r)!==d;return m&&(i=c,r=d),{width:i,height:r,$:m}}function ih(n){return zn(n)?n:n.contextElement}function Vs(n){const l=ih(n);if(!ea(l))return Wn(1);const i=l.getBoundingClientRect(),{width:r,height:u,$:c}=Lg(l);let d=(c?mu(i.width):i.width)/r,m=(c?mu(i.height):i.height)/u;return(!d||!Number.isFinite(d))&&(d=1),(!m||!Number.isFinite(m))&&(m=1),{x:d,y:m}}const dC=Wn(0);function Ug(n){const l=on(n);return!sh()||!l.visualViewport?dC:{x:l.visualViewport.offsetLeft,y:l.visualViewport.offsetTop}}function hC(n,l,i){return l===void 0&&(l=!1),!i||l&&i!==on(n)?!1:l}function Il(n,l,i,r){l===void 0&&(l=!1),i===void 0&&(i=!1);const u=n.getBoundingClientRect(),c=ih(n);let d=Wn(1);l&&(r?zn(r)&&(d=Vs(r)):d=Vs(n));const m=hC(c,i,r)?Ug(c):Wn(0);let p=(u.left+m.x)/d.x,y=(u.top+m.y)/d.y,v=u.width/d.x,x=u.height/d.y;if(c){const E=on(c),C=r&&zn(r)?on(r):r;let w=E,j=_d(w);for(;j&&r&&C!==w;){const N=Vs(j),T=j.getBoundingClientRect(),_=kn(j),O=T.left+(j.clientLeft+parseFloat(_.paddingLeft))*N.x,H=T.top+(j.clientTop+parseFloat(_.paddingTop))*N.y;p*=N.x,y*=N.y,v*=N.x,x*=N.y,p+=O,y+=H,w=on(j),j=_d(w)}}return yu({width:v,height:x,x:p,y})}function rh(n,l){const i=Ou(n).scrollLeft;return l?l.left+i:Il(la(n)).left+i}function zg(n,l,i){i===void 0&&(i=!1);const r=n.getBoundingClientRect(),u=r.left+l.scrollLeft-(i?0:rh(n,r)),c=r.top+l.scrollTop;return{x:u,y:c}}function mC(n){let{elements:l,rect:i,offsetParent:r,strategy:u}=n;const c=u==="fixed",d=la(r),m=l?Ru(l.floating):!1;if(r===d||m&&c)return i;let p={scrollLeft:0,scrollTop:0},y=Wn(1);const v=Wn(0),x=ea(r);if((x||!x&&!c)&&((ri(r)!=="body"||Lr(d))&&(p=Ou(r)),ea(r))){const C=Il(r);y=Vs(r),v.x=C.x+r.clientLeft,v.y=C.y+r.clientTop}const E=d&&!x&&!c?zg(d,p,!0):Wn(0);return{width:i.width*y.x,height:i.height*y.y,x:i.x*y.x-p.scrollLeft*y.x+v.x+E.x,y:i.y*y.y-p.scrollTop*y.y+v.y+E.y}}function pC(n){return Array.from(n.getClientRects())}function yC(n){const l=la(n),i=Ou(n),r=n.ownerDocument.body,u=Gl(l.scrollWidth,l.clientWidth,r.scrollWidth,r.clientWidth),c=Gl(l.scrollHeight,l.clientHeight,r.scrollHeight,r.clientHeight);let d=-i.scrollLeft+rh(n);const m=-i.scrollTop;return kn(r).direction==="rtl"&&(d+=Gl(l.clientWidth,r.clientWidth)-u),{width:u,height:c,x:d,y:m}}function gC(n,l){const i=on(n),r=la(n),u=i.visualViewport;let c=r.clientWidth,d=r.clientHeight,m=0,p=0;if(u){c=u.width,d=u.height;const y=sh();(!y||y&&l==="fixed")&&(m=u.offsetLeft,p=u.offsetTop)}return{width:c,height:d,x:m,y:p}}function vC(n,l){const i=Il(n,!0,l==="fixed"),r=i.top+n.clientTop,u=i.left+n.clientLeft,c=ea(n)?Vs(n):Wn(1),d=n.clientWidth*c.x,m=n.clientHeight*c.y,p=u*c.x,y=r*c.y;return{width:d,height:m,x:p,y}}function zy(n,l,i){let r;if(l==="viewport")r=gC(n,i);else if(l==="document")r=yC(la(n));else if(zn(l))r=vC(l,i);else{const u=Ug(n);r={x:l.x-u.x,y:l.y-u.y,width:l.width,height:l.height}}return yu(r)}function kg(n,l){const i=ml(n);return i===l||!zn(i)||Zs(i)?!1:kn(i).position==="fixed"||kg(i,l)}function bC(n,l){const i=l.get(n);if(i)return i;let r=gr(n,[],!1).filter(m=>zn(m)&&ri(m)!=="body"),u=null;const c=kn(n).position==="fixed";let d=c?ml(n):n;for(;zn(d)&&!Zs(d);){const m=kn(d),p=lh(d);!p&&m.position==="fixed"&&(u=null),(c?!p&&!u:!p&&m.position==="static"&&!!u&&["absolute","fixed"].includes(u.position)||Lr(d)&&!p&&kg(n,d))?r=r.filter(v=>v!==d):u=m,d=ml(d)}return l.set(n,r),r}function xC(n){let{element:l,boundary:i,rootBoundary:r,strategy:u}=n;const d=[...i==="clippingAncestors"?Ru(l)?[]:bC(l,this._c):[].concat(i),r],m=d[0],p=d.reduce((y,v)=>{const x=zy(l,v,u);return y.top=Gl(x.top,y.top),y.right=Fs(x.right,y.right),y.bottom=Fs(x.bottom,y.bottom),y.left=Gl(x.left,y.left),y},zy(l,m,u));return{width:p.right-p.left,height:p.bottom-p.top,x:p.left,y:p.top}}function SC(n){const{width:l,height:i}=Lg(n);return{width:l,height:i}}function wC(n,l,i){const r=ea(l),u=la(l),c=i==="fixed",d=Il(n,!0,c,l);let m={scrollLeft:0,scrollTop:0};const p=Wn(0);function y(){p.x=rh(u)}if(r||!r&&!c)if((ri(l)!=="body"||Lr(u))&&(m=Ou(l)),r){const C=Il(l,!0,c,l);p.x=C.x+l.clientLeft,p.y=C.y+l.clientTop}else u&&y();c&&!r&&u&&y();const v=u&&!r&&!c?zg(u,m):Wn(0),x=d.left+m.scrollLeft-p.x-v.x,E=d.top+m.scrollTop-p.y-v.y;return{x,y:E,width:d.width,height:d.height}}function Wf(n){return kn(n).position==="static"}function ky(n,l){if(!ea(n)||kn(n).position==="fixed")return null;if(l)return l(n);let i=n.offsetParent;return la(n)===i&&(i=i.ownerDocument.body),i}function qg(n,l){const i=on(n);if(Ru(n))return i;if(!ea(n)){let u=ml(n);for(;u&&!Zs(u);){if(zn(u)&&!Wf(u))return u;u=ml(u)}return i}let r=ky(n,l);for(;r&&cC(r)&&Wf(r);)r=ky(r,l);return r&&Zs(r)&&Wf(r)&&!lh(r)?i:r||fC(n)||i}const EC=async function(n){const l=this.getOffsetParent||qg,i=this.getDimensions,r=await i(n.floating);return{reference:wC(n.reference,await l(n.floating),n.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function CC(n){return kn(n).direction==="rtl"}const _C={convertOffsetParentRelativeRectToViewportRelativeRect:mC,getDocumentElement:la,getClippingRect:xC,getOffsetParent:qg,getElementRects:EC,getClientRects:pC,getDimensions:SC,getScale:Vs,isElement:zn,isRTL:CC};function Bg(n,l){return n.x===l.x&&n.y===l.y&&n.width===l.width&&n.height===l.height}function NC(n,l){let i=null,r;const u=la(n);function c(){var m;clearTimeout(r),(m=i)==null||m.disconnect(),i=null}function d(m,p){m===void 0&&(m=!1),p===void 0&&(p=1),c();const y=n.getBoundingClientRect(),{left:v,top:x,width:E,height:C}=y;if(m||l(),!E||!C)return;const w=Po(x),j=Po(u.clientWidth-(v+E)),N=Po(u.clientHeight-(x+C)),T=Po(v),O={rootMargin:-w+"px "+-j+"px "+-N+"px "+-T+"px",threshold:Gl(0,Fs(1,p))||1};let H=!0;function G(Y){const K=Y[0].intersectionRatio;if(K!==p){if(!H)return d();K?d(!1,K):r=setTimeout(()=>{d(!1,1e-7)},1e3)}K===1&&!Bg(y,n.getBoundingClientRect())&&d(),H=!1}try{i=new IntersectionObserver(G,{...O,root:u.ownerDocument})}catch{i=new IntersectionObserver(G,O)}i.observe(n)}return d(!0),c}function jC(n,l,i,r){r===void 0&&(r={});const{ancestorScroll:u=!0,ancestorResize:c=!0,elementResize:d=typeof ResizeObserver=="function",layoutShift:m=typeof IntersectionObserver=="function",animationFrame:p=!1}=r,y=ih(n),v=u||c?[...y?gr(y):[],...gr(l)]:[];v.forEach(T=>{u&&T.addEventListener("scroll",i,{passive:!0}),c&&T.addEventListener("resize",i)});const x=y&&m?NC(y,i):null;let E=-1,C=null;d&&(C=new ResizeObserver(T=>{let[_]=T;_&&_.target===y&&C&&(C.unobserve(l),cancelAnimationFrame(E),E=requestAnimationFrame(()=>{var O;(O=C)==null||O.observe(l)})),i()}),y&&!p&&C.observe(y),C.observe(l));let w,j=p?Il(n):null;p&&N();function N(){const T=Il(n);j&&!Bg(j,T)&&i(),j=T,w=requestAnimationFrame(N)}return i(),()=>{var T;v.forEach(_=>{u&&_.removeEventListener("scroll",i),c&&_.removeEventListener("resize",i)}),x?.(),(T=C)==null||T.disconnect(),C=null,p&&cancelAnimationFrame(w)}}const TC=oC,AC=uC,RC=iC,OC=sC,qy=(n,l,i)=>{const r=new Map,u={platform:_C,...i},c={...u.platform,_c:r};return lC(n,l,{...u,platform:c})};var ed={exports:{}};var By;function DC(){return By||(By=1,function(n){(function(){var l={}.hasOwnProperty;function i(){for(var c="",d=0;d<arguments.length;d++){var m=arguments[d];m&&(c=u(c,r(m)))}return c}function r(c){if(typeof c=="string"||typeof c=="number")return c;if(typeof c!="object")return"";if(Array.isArray(c))return i.apply(null,c);if(c.toString!==Object.prototype.toString&&!c.toString.toString().includes("[native code]"))return c.toString();var d="";for(var m in c)l.call(c,m)&&c[m]&&(d=u(d,m));return d}function u(c,d){return d?c?c+" "+d:c+d:c}n.exports?(i.default=i,n.exports=i):window.classNames=i})()}(ed)),ed.exports}var MC=DC();const Nd=Ad(MC);var Hy={};const LC="react-tooltip-core-styles",UC="react-tooltip-base-styles",Qy={core:!1,base:!1};function Yy({css:n,id:l=UC,type:i="base",ref:r}){var u,c;if(!n||typeof document>"u"||Qy[i]||i==="core"&&typeof process<"u"&&(!((u=process==null?void 0:Hy)===null||u===void 0)&&u.REACT_TOOLTIP_DISABLE_CORE_STYLES)||i!=="base"&&typeof process<"u"&&(!((c=process==null?void 0:Hy)===null||c===void 0)&&c.REACT_TOOLTIP_DISABLE_BASE_STYLES))return;i==="core"&&(l=LC),r||(r={});const{insertAt:d}=r;if(document.getElementById(l))return;const m=document.head||document.getElementsByTagName("head")[0],p=document.createElement("style");p.id=l,p.type="text/css",d==="top"&&m.firstChild?m.insertBefore(p,m.firstChild):m.appendChild(p),p.styleSheet?p.styleSheet.cssText=n:p.appendChild(document.createTextNode(n)),Qy[i]=!0}const Vy=async({elementReference:n=null,tooltipReference:l=null,tooltipArrowReference:i=null,place:r="top",offset:u=10,strategy:c="absolute",middlewares:d=[TC(Number(u)),RC({fallbackAxisSideDirection:"start"}),AC({padding:5})],border:m,arrowSize:p=8})=>{if(!n)return{tooltipStyles:{},tooltipArrowStyles:{},place:r};if(l===null)return{tooltipStyles:{},tooltipArrowStyles:{},place:r};const y=d;return i?(y.push(OC({element:i,padding:5})),qy(n,l,{placement:r,strategy:c,middleware:y}).then(({x:v,y:x,placement:E,middlewareData:C})=>{var w,j;const N={left:`${v}px`,top:`${x}px`,border:m},{x:T,y:_}=(w=C.arrow)!==null&&w!==void 0?w:{x:0,y:0},O=(j={top:"bottom",right:"left",bottom:"top",left:"right"}[E.split("-")[0]])!==null&&j!==void 0?j:"bottom",H=m&&{borderBottom:m,borderRight:m};let G=0;if(m){const Y=`${m}`.match(/(\d+)px/);G=Y?.[1]?Number(Y[1]):1}return{tooltipStyles:N,tooltipArrowStyles:{left:T!=null?`${T}px`:"",top:_!=null?`${_}px`:"",right:"",bottom:"",...H,[O]:`-${p/2+G}px`},place:E}})):qy(n,l,{placement:"bottom",strategy:c,middleware:y}).then(({x:v,y:x,placement:E})=>({tooltipStyles:{left:`${v}px`,top:`${x}px`},tooltipArrowStyles:{},place:E}))},Ky=(n,l)=>!("CSS"in window&&"supports"in window.CSS)||window.CSS.supports(n,l),$y=(n,l,i)=>{let r=null;const u=function(...c){const d=()=>{r=null};!r&&(n.apply(this,c),r=setTimeout(d,l))};return u.cancel=()=>{r&&(clearTimeout(r),r=null)},u},Gy=n=>n!==null&&!Array.isArray(n)&&typeof n=="object",jd=(n,l)=>{if(n===l)return!0;if(Array.isArray(n)&&Array.isArray(l))return n.length===l.length&&n.every((u,c)=>jd(u,l[c]));if(Array.isArray(n)!==Array.isArray(l))return!1;if(!Gy(n)||!Gy(l))return n===l;const i=Object.keys(n),r=Object.keys(l);return i.length===r.length&&i.every(u=>jd(n[u],l[u]))},zC=n=>{if(!(n instanceof HTMLElement||n instanceof SVGElement))return!1;const l=getComputedStyle(n);return["overflow","overflow-x","overflow-y"].some(i=>{const r=l.getPropertyValue(i);return r==="auto"||r==="scroll"})},Xy=n=>{if(!n)return null;let l=n.parentElement;for(;l;){if(zC(l))return l;l=l.parentElement}return document.scrollingElement||document.documentElement},kC=typeof window<"u"?b.useLayoutEffect:b.useEffect,Tn=n=>{n.current&&(clearTimeout(n.current),n.current=null)},qC="DEFAULT_TOOLTIP_ID",BC={anchorRefs:new Set,activeAnchor:{current:null},attach:()=>{},detach:()=>{},setActiveAnchor:()=>{}},HC=b.createContext({getTooltipData:()=>BC});function Hg(n=qC){return b.useContext(HC).getTooltipData(n)}var Hs={tooltip:"core-styles-module_tooltip__3vRRp",fixed:"core-styles-module_fixed__pcSol",arrow:"core-styles-module_arrow__cvMwQ",noArrow:"core-styles-module_noArrow__xock6",clickable:"core-styles-module_clickable__ZuTTB",show:"core-styles-module_show__Nt9eE",closing:"core-styles-module_closing__sGnxF"},td={tooltip:"styles-module_tooltip__mnnfp",arrow:"styles-module_arrow__K0L3T",dark:"styles-module_dark__xNqje",light:"styles-module_light__Z6W-X",success:"styles-module_success__A2AKt",warning:"styles-module_warning__SCK0X",error:"styles-module_error__JvumD",info:"styles-module_info__BWdHW"};const QC=({forwardRef:n,id:l,className:i,classNameArrow:r,variant:u="dark",anchorId:c,anchorSelect:d,place:m="top",offset:p=10,events:y=["hover"],openOnClick:v=!1,positionStrategy:x="absolute",middlewares:E,wrapper:C,delayShow:w=0,delayHide:j=0,float:N=!1,hidden:T=!1,noArrow:_=!1,clickable:O=!1,closeOnEsc:H=!1,closeOnScroll:G=!1,closeOnResize:Y=!1,openEvents:K,closeEvents:Z,globalCloseEvents:te,imperativeModeOnly:ye,style:Ae,position:Ce,afterShow:$e,afterHide:me,disableTooltip:_e,content:q,contentWrapperRef:F,isOpen:J,defaultIsOpen:he=!1,setIsOpen:R,activeAnchor:Q,setActiveAnchor:I,border:W,opacity:ae,arrowColor:ve,arrowSize:oe=8,role:vt="tooltip"})=>{var Me;const Ge=b.useRef(null),Hn=b.useRef(null),Ct=b.useRef(null),dn=b.useRef(null),sa=b.useRef(null),[hn,oi]=b.useState({tooltipStyles:{},tooltipArrowStyles:{},place:m}),[Dt,Mt]=b.useState(!1),[ia,Qn]=b.useState(!1),[Ve,Yn]=b.useState(null),vl=b.useRef(!1),Oa=b.useRef(null),{anchorRefs:bl,setActiveAnchor:es}=Hg(l),mn=b.useRef(!1),[Je,Bt]=b.useState([]),tt=b.useRef(!1),Da=v||y.includes("click"),ui=Da||K?.click||K?.dblclick||K?.mousedown,Ma=K?{...K}:{mouseover:!0,focus:!0,mouseenter:!1,click:!1,dblclick:!1,mousedown:!1};!K&&Da&&Object.assign(Ma,{mouseenter:!1,focus:!1,mouseover:!1,click:!0});const pn=Z?{...Z}:{mouseout:!0,blur:!0,mouseleave:!1,click:!1,dblclick:!1,mouseup:!1};!Z&&Da&&Object.assign(pn,{mouseleave:!1,blur:!1,mouseout:!1});const _t=te?{...te}:{escape:H||!1,scroll:G||!1,resize:Y||!1,clickOutsideAnchor:ui||!1};ye&&(Object.assign(Ma,{mouseover:!1,focus:!1,mouseenter:!1,click:!1,dblclick:!1,mousedown:!1}),Object.assign(pn,{mouseout:!1,blur:!1,mouseleave:!1,click:!1,dblclick:!1,mouseup:!1}),Object.assign(_t,{escape:!1,scroll:!1,resize:!1,clickOutsideAnchor:!1})),kC(()=>(tt.current=!0,()=>{tt.current=!1}),[]);const ke=P=>{tt.current&&(P&&Qn(!0),setTimeout(()=>{tt.current&&(R?.(P),J===void 0&&Mt(P))},10))};b.useEffect(()=>{if(J===void 0)return()=>null;J&&Qn(!0);const P=setTimeout(()=>{Mt(J)},10);return()=>{clearTimeout(P)}},[J]),b.useEffect(()=>{if(Dt!==vl.current)if(Tn(sa),vl.current=Dt,Dt)$e?.();else{const P=(ne=>{const ce=ne.match(/^([\d.]+)(ms|s)$/);if(!ce)return 0;const[,Fe,ht]=ce;return Number(Fe)*(ht==="ms"?1:1e3)})(getComputedStyle(document.body).getPropertyValue("--rt-transition-show-delay"));sa.current=setTimeout(()=>{Qn(!1),Yn(null),me?.()},P+25)}},[Dt]);const ra=P=>{oi(ne=>jd(ne,P)?ne:P)},Rn=(P=w)=>{Tn(Ct),ia?ke(!0):Ct.current=setTimeout(()=>{ke(!0)},P)},La=(P=j)=>{Tn(dn),dn.current=setTimeout(()=>{mn.current||ke(!1)},P)},Ua=P=>{var ne;if(!P)return;const ce=(ne=P.currentTarget)!==null&&ne!==void 0?ne:P.target;if(!ce?.isConnected)return I(null),void es({current:null});w?Rn():ke(!0),I(ce),es({current:ce}),Tn(dn)},oa=()=>{O?La(j||100):j?La():ke(!1),Tn(Ct)},Vn=({x:P,y:ne})=>{var ce;const Fe={getBoundingClientRect:()=>({x:P,y:ne,width:0,height:0,top:ne,left:P,right:P,bottom:ne})};Vy({place:(ce=Ve?.place)!==null&&ce!==void 0?ce:m,offset:p,elementReference:Fe,tooltipReference:Ge.current,tooltipArrowReference:Hn.current,strategy:x,middlewares:E,border:W,arrowSize:oe}).then(ht=>{ra(ht)})},yn=P=>{if(!P)return;const ne=P,ce={x:ne.clientX,y:ne.clientY};Vn(ce),Oa.current=ce},xl=P=>{var ne;if(!Dt)return;const ce=P.target;ce.isConnected&&(!((ne=Ge.current)===null||ne===void 0)&&ne.contains(ce)||[document.querySelector(`[id='${c}']`),...Je].some(Fe=>Fe?.contains(ce))||(ke(!1),Tn(Ct)))},Sl=$y(Ua,50),nt=$y(oa,50),Nt=P=>{nt.cancel(),Sl(P)},ie=()=>{Sl.cancel(),nt()},Se=b.useCallback(()=>{var P,ne;const ce=(P=Ve?.position)!==null&&P!==void 0?P:Ce;ce?Vn(ce):N?Oa.current&&Vn(Oa.current):Q?.isConnected&&Vy({place:(ne=Ve?.place)!==null&&ne!==void 0?ne:m,offset:p,elementReference:Q,tooltipReference:Ge.current,tooltipArrowReference:Hn.current,strategy:x,middlewares:E,border:W,arrowSize:oe}).then(Fe=>{tt.current&&ra(Fe)})},[Dt,Q,q,Ae,m,Ve?.place,p,x,Ce,Ve?.position,N,oe]);b.useEffect(()=>{var P,ne;const ce=new Set(bl);Je.forEach(Oe=>{_e?.(Oe)||ce.add({current:Oe})});const Fe=document.querySelector(`[id='${c}']`);Fe&&!_e?.(Fe)&&ce.add({current:Fe});const ht=()=>{ke(!1)},gn=Xy(Q),It=Xy(Ge.current);_t.scroll&&(window.addEventListener("scroll",ht),gn?.addEventListener("scroll",ht),It?.addEventListener("scroll",ht));let at=null;_t.resize?window.addEventListener("resize",ht):Q&&Ge.current&&(at=jC(Q,Ge.current,Se,{ancestorResize:!0,elementResize:!0,layoutShift:!0}));const Tt=Oe=>{Oe.key==="Escape"&&ke(!1)};_t.escape&&window.addEventListener("keydown",Tt),_t.clickOutsideAnchor&&window.addEventListener("click",xl);const Re=[],Wt=Oe=>!!(Oe?.target&&Q?.contains(Oe.target)),wl=Oe=>{Dt&&Wt(Oe)||Ua(Oe)},za=Oe=>{Dt&&Wt(Oe)&&oa()},lt=["mouseover","mouseout","mouseenter","mouseleave","focus","blur"],ci=["click","dblclick","mousedown","mouseup"];Object.entries(Ma).forEach(([Oe,vn])=>{vn&&(lt.includes(Oe)?Re.push({event:Oe,listener:Nt}):ci.includes(Oe)&&Re.push({event:Oe,listener:wl}))}),Object.entries(pn).forEach(([Oe,vn])=>{vn&&(lt.includes(Oe)?Re.push({event:Oe,listener:ie}):ci.includes(Oe)&&Re.push({event:Oe,listener:za}))}),N&&Re.push({event:"pointermove",listener:yn});const fi=()=>{mn.current=!0},Kn=()=>{mn.current=!1,oa()},ua=O&&(pn.mouseout||pn.mouseleave);return ua&&((P=Ge.current)===null||P===void 0||P.addEventListener("mouseover",fi),(ne=Ge.current)===null||ne===void 0||ne.addEventListener("mouseout",Kn)),Re.forEach(({event:Oe,listener:vn})=>{ce.forEach(ts=>{var El;(El=ts.current)===null||El===void 0||El.addEventListener(Oe,vn)})}),()=>{var Oe,vn;_t.scroll&&(window.removeEventListener("scroll",ht),gn?.removeEventListener("scroll",ht),It?.removeEventListener("scroll",ht)),_t.resize?window.removeEventListener("resize",ht):at?.(),_t.clickOutsideAnchor&&window.removeEventListener("click",xl),_t.escape&&window.removeEventListener("keydown",Tt),ua&&((Oe=Ge.current)===null||Oe===void 0||Oe.removeEventListener("mouseover",fi),(vn=Ge.current)===null||vn===void 0||vn.removeEventListener("mouseout",Kn)),Re.forEach(({event:ts,listener:El})=>{ce.forEach(ns=>{var ka;(ka=ns.current)===null||ka===void 0||ka.removeEventListener(ts,El)})})}},[Q,Se,ia,bl,Je,K,Z,te,Da,w,j]),b.useEffect(()=>{var P,ne;let ce=(ne=(P=Ve?.anchorSelect)!==null&&P!==void 0?P:d)!==null&&ne!==void 0?ne:"";!ce&&l&&(ce=`[data-tooltip-id='${l.replace(/'/g,"\\'")}']`);const Fe=new MutationObserver(ht=>{const gn=[],It=[];ht.forEach(at=>{if(at.type==="attributes"&&at.attributeName==="data-tooltip-id"&&(at.target.getAttribute("data-tooltip-id")===l?gn.push(at.target):at.oldValue===l&&It.push(at.target)),at.type==="childList"){if(Q){const Tt=[...at.removedNodes].filter(Re=>Re.nodeType===1);if(ce)try{It.push(...Tt.filter(Re=>Re.matches(ce))),It.push(...Tt.flatMap(Re=>[...Re.querySelectorAll(ce)]))}catch{}Tt.some(Re=>{var Wt;return!!(!((Wt=Re?.contains)===null||Wt===void 0)&&Wt.call(Re,Q))&&(Qn(!1),ke(!1),I(null),Tn(Ct),Tn(dn),!0)})}if(ce)try{const Tt=[...at.addedNodes].filter(Re=>Re.nodeType===1);gn.push(...Tt.filter(Re=>Re.matches(ce))),gn.push(...Tt.flatMap(Re=>[...Re.querySelectorAll(ce)]))}catch{}}}),(gn.length||It.length)&&Bt(at=>[...at.filter(Tt=>!It.includes(Tt)),...gn])});return Fe.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-tooltip-id"],attributeOldValue:!0}),()=>{Fe.disconnect()}},[l,d,Ve?.anchorSelect,Q]),b.useEffect(()=>{Se()},[Se]),b.useEffect(()=>{if(!F?.current)return()=>null;const P=new ResizeObserver(()=>{setTimeout(()=>Se())});return P.observe(F.current),()=>{P.disconnect()}},[q,F?.current]),b.useEffect(()=>{var P;const ne=document.querySelector(`[id='${c}']`),ce=[...Je,ne];Q&&ce.includes(Q)||I((P=Je[0])!==null&&P!==void 0?P:ne)},[c,Je,Q]),b.useEffect(()=>(he&&ke(!0),()=>{Tn(Ct),Tn(dn)}),[]),b.useEffect(()=>{var P;let ne=(P=Ve?.anchorSelect)!==null&&P!==void 0?P:d;if(!ne&&l&&(ne=`[data-tooltip-id='${l.replace(/'/g,"\\'")}']`),ne)try{const ce=Array.from(document.querySelectorAll(ne));Bt(ce)}catch{Bt([])}},[l,d,Ve?.anchorSelect]),b.useEffect(()=>{Ct.current&&(Tn(Ct),Rn(w))},[w]);const Lt=(Me=Ve?.content)!==null&&Me!==void 0?Me:q,jt=Dt&&Object.keys(hn.tooltipStyles).length>0;return b.useImperativeHandle(n,()=>({open:P=>{if(P?.anchorSelect)try{document.querySelector(P.anchorSelect)}catch{return void console.warn(`[react-tooltip] "${P.anchorSelect}" is not a valid CSS selector`)}Yn(P??null),P?.delay?Rn(P.delay):ke(!0)},close:P=>{P?.delay?La(P.delay):ke(!1)},activeAnchor:Q,place:hn.place,isOpen:!!(ia&&!T&&Lt&&jt)})),ia&&!T&&Lt?rl.createElement(C,{id:l,role:vt,className:Nd("react-tooltip",Hs.tooltip,td.tooltip,td[u],i,`react-tooltip__place-${hn.place}`,Hs[jt?"show":"closing"],jt?"react-tooltip__show":"react-tooltip__closing",x==="fixed"&&Hs.fixed,O&&Hs.clickable),onTransitionEnd:P=>{Tn(sa),Dt||P.propertyName!=="opacity"||(Qn(!1),Yn(null),me?.())},style:{...Ae,...hn.tooltipStyles,opacity:ae!==void 0&&jt?ae:void 0},ref:Ge},Lt,rl.createElement(C,{className:Nd("react-tooltip-arrow",Hs.arrow,td.arrow,r,_&&Hs.noArrow),style:{...hn.tooltipArrowStyles,background:ve?`linear-gradient(to right bottom, transparent 50%, ${ve} 50%)`:void 0,"--rt-arrow-size":`${oe}px`},ref:Hn})):null},YC=({content:n})=>rl.createElement("span",{dangerouslySetInnerHTML:{__html:n}}),gu=rl.forwardRef(({id:n,anchorId:l,anchorSelect:i,content:r,html:u,render:c,className:d,classNameArrow:m,variant:p="dark",place:y="top",offset:v=10,wrapper:x="div",children:E=null,events:C=["hover"],openOnClick:w=!1,positionStrategy:j="absolute",middlewares:N,delayShow:T=0,delayHide:_=0,float:O=!1,hidden:H=!1,noArrow:G=!1,clickable:Y=!1,closeOnEsc:K=!1,closeOnScroll:Z=!1,closeOnResize:te=!1,openEvents:ye,closeEvents:Ae,globalCloseEvents:Ce,imperativeModeOnly:$e=!1,style:me,position:_e,isOpen:q,defaultIsOpen:F=!1,disableStyleInjection:J=!1,border:he,opacity:R,arrowColor:Q,arrowSize:I,setIsOpen:W,afterShow:ae,afterHide:ve,disableTooltip:oe,role:vt="tooltip"},Me)=>{const[Ge,Hn]=b.useState(r),[Ct,dn]=b.useState(u),[sa,hn]=b.useState(y),[oi,Dt]=b.useState(p),[Mt,ia]=b.useState(v),[Qn,Ve]=b.useState(T),[Yn,vl]=b.useState(_),[Oa,bl]=b.useState(O),[es,mn]=b.useState(H),[Je,Bt]=b.useState(x),[tt,Da]=b.useState(C),[ui,Ma]=b.useState(j),[pn,_t]=b.useState(null),[ke,ra]=b.useState(null),Rn=b.useRef(J),{anchorRefs:La,activeAnchor:Ua}=Hg(n),oa=nt=>nt?.getAttributeNames().reduce((Nt,ie)=>{var Se;return ie.startsWith("data-tooltip-")&&(Nt[ie.replace(/^data-tooltip-/,"")]=(Se=nt?.getAttribute(ie))!==null&&Se!==void 0?Se:null),Nt},{}),Vn=nt=>{const Nt={place:ie=>{var Se;hn((Se=ie)!==null&&Se!==void 0?Se:y)},content:ie=>{Hn(ie??r)},html:ie=>{dn(ie??u)},variant:ie=>{var Se;Dt((Se=ie)!==null&&Se!==void 0?Se:p)},offset:ie=>{ia(ie===null?v:Number(ie))},wrapper:ie=>{var Se;Bt((Se=ie)!==null&&Se!==void 0?Se:x)},events:ie=>{const Se=ie?.split(" ");Da(Se??C)},"position-strategy":ie=>{var Se;Ma((Se=ie)!==null&&Se!==void 0?Se:j)},"delay-show":ie=>{Ve(ie===null?T:Number(ie))},"delay-hide":ie=>{vl(ie===null?_:Number(ie))},float:ie=>{bl(ie===null?O:ie==="true")},hidden:ie=>{mn(ie===null?H:ie==="true")},"class-name":ie=>{_t(ie)}};Object.values(Nt).forEach(ie=>ie(null)),Object.entries(nt).forEach(([ie,Se])=>{var Lt;(Lt=Nt[ie])===null||Lt===void 0||Lt.call(Nt,Se)})};b.useEffect(()=>{Hn(r)},[r]),b.useEffect(()=>{dn(u)},[u]),b.useEffect(()=>{hn(y)},[y]),b.useEffect(()=>{Dt(p)},[p]),b.useEffect(()=>{ia(v)},[v]),b.useEffect(()=>{Ve(T)},[T]),b.useEffect(()=>{vl(_)},[_]),b.useEffect(()=>{bl(O)},[O]),b.useEffect(()=>{mn(H)},[H]),b.useEffect(()=>{Ma(j)},[j]),b.useEffect(()=>{Rn.current!==J&&console.warn("[react-tooltip] Do not change `disableStyleInjection` dynamically.")},[J]),b.useEffect(()=>{typeof window<"u"&&window.dispatchEvent(new CustomEvent("react-tooltip-inject-styles",{detail:{disableCore:J==="core",disableBase:J}}))},[]),b.useEffect(()=>{var nt;const Nt=new Set(La);let ie=i;if(!ie&&n&&(ie=`[data-tooltip-id='${n.replace(/'/g,"\\'")}']`),ie)try{document.querySelectorAll(ie).forEach(ne=>{Nt.add({current:ne})})}catch{console.warn(`[react-tooltip] "${ie}" is not a valid CSS selector`)}const Se=document.querySelector(`[id='${l}']`);if(Se&&Nt.add({current:Se}),!Nt.size)return()=>null;const Lt=(nt=ke??Se)!==null&&nt!==void 0?nt:Ua.current,jt=new MutationObserver(ne=>{ne.forEach(ce=>{var Fe;if(!Lt||ce.type!=="attributes"||!(!((Fe=ce.attributeName)===null||Fe===void 0)&&Fe.startsWith("data-tooltip-")))return;const ht=oa(Lt);Vn(ht)})}),P={attributes:!0,childList:!1,subtree:!1};if(Lt){const ne=oa(Lt);Vn(ne),jt.observe(Lt,P)}return()=>{jt.disconnect()}},[La,Ua,ke,l,i]),b.useEffect(()=>{me?.border&&console.warn("[react-tooltip] Do not set `style.border`. Use `border` prop instead."),he&&!Ky("border",`${he}`)&&console.warn(`[react-tooltip] "${he}" is not a valid \`border\`.`),me?.opacity&&console.warn("[react-tooltip] Do not set `style.opacity`. Use `opacity` prop instead."),R&&!Ky("opacity",`${R}`)&&console.warn(`[react-tooltip] "${R}" is not a valid \`opacity\`.`)},[]);let yn=E;const xl=b.useRef(null);if(c){const nt=c({content:ke?.getAttribute("data-tooltip-content")||Ge||null,activeAnchor:ke});yn=nt?rl.createElement("div",{ref:xl,className:"react-tooltip-content-wrapper"},nt):null}else Ge&&(yn=Ge);Ct&&(yn=rl.createElement(YC,{content:Ct}));const Sl={forwardRef:Me,id:n,anchorId:l,anchorSelect:i,className:Nd(d,pn),classNameArrow:m,content:yn,contentWrapperRef:xl,place:sa,variant:oi,offset:Mt,wrapper:Je,events:tt,openOnClick:w,positionStrategy:ui,middlewares:N,delayShow:Qn,delayHide:Yn,float:Oa,hidden:es,noArrow:G,clickable:Y,closeOnEsc:K,closeOnScroll:Z,closeOnResize:te,openEvents:ye,closeEvents:Ae,globalCloseEvents:Ce,imperativeModeOnly:$e,style:me,position:_e,isOpen:q,defaultIsOpen:F,border:he,opacity:R,arrowColor:Q,arrowSize:I,setIsOpen:W,afterShow:ae,afterHide:ve,disableTooltip:oe,activeAnchor:ke,setActiveAnchor:nt=>ra(nt),role:vt};return rl.createElement(QC,{...Sl})});typeof window<"u"&&window.addEventListener("react-tooltip-inject-styles",n=>{n.detail.disableCore||Yy({css:":root{--rt-color-white:#fff;--rt-color-dark:#222;--rt-color-success:#8dc572;--rt-color-error:#be6464;--rt-color-warning:#f0ad4e;--rt-color-info:#337ab7;--rt-opacity:0.9;--rt-transition-show-delay:0.15s;--rt-transition-closing-delay:0.15s;--rt-arrow-size:8px}.core-styles-module_tooltip__3vRRp{position:absolute;top:0;left:0;pointer-events:none;opacity:0;will-change:opacity}.core-styles-module_fixed__pcSol{position:fixed}.core-styles-module_arrow__cvMwQ{position:absolute;background:inherit;z-index:-1}.core-styles-module_noArrow__xock6{display:none}.core-styles-module_clickable__ZuTTB{pointer-events:auto}.core-styles-module_show__Nt9eE{opacity:var(--rt-opacity);transition:opacity var(--rt-transition-show-delay)ease-out}.core-styles-module_closing__sGnxF{opacity:0;transition:opacity var(--rt-transition-closing-delay)ease-in}",type:"core"}),n.detail.disableBase||Yy({css:`
193
- .styles-module_tooltip__mnnfp{padding:8px 16px;border-radius:3px;font-size:90%;width:max-content}.styles-module_arrow__K0L3T{width:var(--rt-arrow-size);height:var(--rt-arrow-size)}[class*='react-tooltip__place-top']>.styles-module_arrow__K0L3T{transform:rotate(45deg)}[class*='react-tooltip__place-right']>.styles-module_arrow__K0L3T{transform:rotate(135deg)}[class*='react-tooltip__place-bottom']>.styles-module_arrow__K0L3T{transform:rotate(225deg)}[class*='react-tooltip__place-left']>.styles-module_arrow__K0L3T{transform:rotate(315deg)}.styles-module_dark__xNqje{background:var(--rt-color-dark);color:var(--rt-color-white)}.styles-module_light__Z6W-X{background-color:var(--rt-color-white);color:var(--rt-color-dark)}.styles-module_success__A2AKt{background-color:var(--rt-color-success);color:var(--rt-color-white)}.styles-module_warning__SCK0X{background-color:var(--rt-color-warning);color:var(--rt-color-white)}.styles-module_error__JvumD{background-color:var(--rt-color-error);color:var(--rt-color-white)}.styles-module_info__BWdHW{background-color:var(--rt-color-info);color:var(--rt-color-white)}`,type:"base"})});const vr=n=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},b.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:48,d:"M184 112l144 144-144 144"})),Qg=n=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},b.createElement("path",{d:"M320 146s24.36-12-64-12a160 160 0 10160 160",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeMiterlimit:10,strokeWidth:32}),b.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32,d:"M256 58l80 80-80 80"})),Yg=n=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},b.createElement("rect",{x:128,y:128,width:336,height:336,rx:57,ry:57,fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:32}),b.createElement("path",{d:"M383.5 128l.5-24a56.16 56.16 0 00-56-56H112a64.19 64.19 0 00-64 64v216a56.16 56.16 0 0056 56h24M296 216v160M376 296H216",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32})),VC=n=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},b.createElement("circle",{cx:128,cy:256,r:48,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32}),b.createElement("circle",{cx:384,cy:112,r:48,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32}),b.createElement("circle",{cx:384,cy:400,r:48,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32}),b.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32,d:"M169.83 279.53l172.34 96.94M342.17 135.53l-172.34 96.94"})),KC=()=>{const n=Id(),l=k4();return{rename:async r=>{if(n){const u=await Or("New tab name",r);u&&await l.mutateAsync({id:n,payload:{name:u}})}return Promise.resolve()}}},Vg=["shift","alt","meta","mod","ctrl","control"],$C={esc:"escape",return:"enter",left:"arrowleft",right:"arrowright",up:"arrowup",down:"arrowdown",ShiftLeft:"shift",ShiftRight:"shift",AltLeft:"alt",AltRight:"alt",MetaLeft:"meta",MetaRight:"meta",OSLeft:"meta",OSRight:"meta",ControlLeft:"ctrl",ControlRight:"ctrl"};function fl(n){return($C[n.trim()]||n.trim()).toLowerCase().replace(/key|digit|numpad/,"")}function Kg(n){return Vg.includes(n)}function nd(n,l=","){return n.toLowerCase().split(l)}function ad(n,l="+",i=">",r=!1,u){let c=[],d=!1;n=n.trim(),n.includes(i)?(d=!0,c=n.toLocaleLowerCase().split(i).map(y=>fl(y))):c=n.toLocaleLowerCase().split(l).map(y=>fl(y));const m={alt:c.includes("alt"),ctrl:c.includes("ctrl")||c.includes("control"),shift:c.includes("shift"),meta:c.includes("meta"),mod:c.includes("mod"),useKey:r},p=c.filter(y=>!Vg.includes(y));return{...m,keys:p,description:u,isSequence:d,hotkey:n}}typeof document<"u"&&(document.addEventListener("keydown",n=>{n.code!==void 0&&$g([fl(n.code)])}),document.addEventListener("keyup",n=>{n.code!==void 0&&Gg([fl(n.code)])})),typeof window<"u"&&(window.addEventListener("blur",()=>{Na.clear()}),window.addEventListener("contextmenu",()=>{setTimeout(()=>{Na.clear()},0)}));const Na=new Set;function oh(n){return Array.isArray(n)}function GC(n,l=","){return(oh(n)?n:n.split(l)).every(i=>Na.has(i.trim().toLowerCase()))}function $g(n){const l=Array.isArray(n)?n:[n];Na.has("meta")&&Na.forEach(i=>!Kg(i)&&Na.delete(i.toLowerCase())),l.forEach(i=>Na.add(i.toLowerCase()))}function Gg(n){const l=Array.isArray(n)?n:[n];n==="meta"?Na.clear():l.forEach(i=>Na.delete(i.toLowerCase()))}function XC(n,l,i){(typeof i=="function"&&i(n,l)||i===!0)&&n.preventDefault()}function FC(n,l,i){return typeof i=="function"?i(n,l):i===!0||i===void 0}const ZC=["input","textarea","select","searchbox","slider","spinbutton","menuitem","menuitemcheckbox","menuitemradio","option","radio","textbox"];function PC(n){return Xg(n,ZC)}function Xg(n,l=!1){const{target:i,composed:r}=n;let u,c;return JC(i)&&r?(u=n.composedPath()[0]&&n.composedPath()[0].tagName,c=n.composedPath()[0]&&n.composedPath()[0].role):(u=i&&i.tagName,c=i&&i.role),oh(l)?!!(u&&l&&l.some(d=>d.toLowerCase()===u.toLowerCase()||d===c)):!!(u&&l&&l)}function JC(n){return!!n.tagName&&!n.tagName.startsWith("-")&&n.tagName.includes("-")}function IC(n,l){return n.length===0&&l?(console.warn('A hotkey has the "scopes" option set, however no active scopes were found. If you want to use the global scopes feature, you need to wrap your app in a <HotkeysProvider>'),!0):l?n.some(i=>l.includes(i))||n.includes("*"):!0}const WC=(n,l,i=!1)=>{const{alt:r,meta:u,mod:c,shift:d,ctrl:m,keys:p,useKey:y}=l,{code:v,key:x,ctrlKey:E,metaKey:C,shiftKey:w,altKey:j}=n,N=fl(v);if(y&&p?.length===1&&p.includes(x))return!0;if(!p?.includes(N)&&!["ctrl","control","unknown","meta","alt","shift","os"].includes(N))return!1;if(!i){if(r!==j&&N!=="alt"||d!==w&&N!=="shift")return!1;if(c){if(!C&&!E)return!1}else if(u!==C&&N!=="meta"&&N!=="os"||m!==E&&N!=="ctrl"&&N!=="control")return!1}return p&&p.length===1&&p.includes(N)?!0:p?GC(p):!p},e_=b.createContext(void 0),t_=()=>b.useContext(e_);function Fg(n,l){return n&&l&&typeof n=="object"&&typeof l=="object"?Object.keys(n).length===Object.keys(l).length&&Object.keys(n).reduce((i,r)=>i&&Fg(n[r],l[r]),!0):n===l}const n_=b.createContext({hotkeys:[],activeScopes:[],toggleScope:()=>{},enableScope:()=>{},disableScope:()=>{}}),a_=()=>b.useContext(n_);function l_(n){const l=b.useRef(void 0);return Fg(l.current,n)||(l.current=n),l.current}const Fy=n=>{n.stopPropagation(),n.preventDefault(),n.stopImmediatePropagation()},s_=typeof window<"u"?b.useLayoutEffect:b.useEffect;function un(n,l,i,r){const u=b.useRef(null),c=b.useRef(!1),d=Array.isArray(i)?Array.isArray(r)?void 0:r:i,m=oh(n)?n.join(d?.delimiter):n,p=Array.isArray(i)?i:Array.isArray(r)?r:void 0,y=b.useCallback(l,p??[]),v=b.useRef(y);p?v.current=y:v.current=l;const x=l_(d),{activeScopes:E}=a_(),C=t_();return s_(()=>{if(x?.enabled===!1||!IC(E,x?.scopes))return;let w=[],j;const N=(H,G=!1)=>{if(!(PC(H)&&!Xg(H,x?.enableOnFormTags))){if(u.current!==null){const Y=u.current.getRootNode();if((Y instanceof Document||Y instanceof ShadowRoot)&&Y.activeElement!==u.current&&!u.current.contains(Y.activeElement)){Fy(H);return}}H.target?.isContentEditable&&!x?.enableOnContentEditable||nd(m,x?.delimiter).forEach(Y=>{if(Y.includes(x?.splitKey??"+")&&Y.includes(x?.sequenceSplitKey??">")){console.warn(`Hotkey ${Y} contains both ${x?.splitKey??"+"} and ${x?.sequenceSplitKey??">"} which is not supported.`);return}const K=ad(Y,x?.splitKey,x?.sequenceSplitKey,x?.useKey,x?.description);if(K.isSequence){j=setTimeout(()=>{w=[]},x?.sequenceTimeoutMs??1e3);const Z=K.useKey?H.key:fl(H.code);if(Kg(Z.toLowerCase()))return;w.push(Z);const te=K.keys?.[w.length-1];if(Z!==te){w=[],j&&clearTimeout(j);return}w.length===K.keys?.length&&(v.current(H,K),j&&clearTimeout(j),w=[])}else if(WC(H,K,x?.ignoreModifiers)||K.keys?.includes("*")){if(x?.ignoreEventWhen?.(H)||G&&c.current)return;if(XC(H,K,x?.preventDefault),!FC(H,K,x?.enabled)){Fy(H);return}v.current(H,K),G||(c.current=!0)}})}},T=H=>{H.code!==void 0&&($g(fl(H.code)),(x?.keydown===void 0&&x?.keyup!==!0||x?.keydown)&&N(H))},_=H=>{H.code!==void 0&&(Gg(fl(H.code)),c.current=!1,x?.keyup&&N(H,!0))},O=u.current||d?.document||document;return O.addEventListener("keyup",_,d?.eventListenerOptions),O.addEventListener("keydown",T,d?.eventListenerOptions),C&&nd(m,x?.delimiter).forEach(H=>C.addHotkey(ad(H,x?.splitKey,x?.sequenceSplitKey,x?.useKey,x?.description))),()=>{O.removeEventListener("keyup",_,d?.eventListenerOptions),O.removeEventListener("keydown",T,d?.eventListenerOptions),C&&nd(m,x?.delimiter).forEach(H=>C.removeHotkey(ad(H,x?.splitKey,x?.sequenceSplitKey,x?.useKey,x?.description))),w=[],j&&clearTimeout(j)}},[m,x,E]),u}function i_(){return h.jsxs("div",{className:"flex items-center bg-white border-b border-gray-200 overflow-auto no-scrollbar",children:[h.jsx(r_,{}),h.jsx(u_,{})]})}function r_(){const{dataSourceId:n,name:l}=b.useContext(gl),{data:i}=Nu(n),{data:r}=b.useContext(Ra),u=Ar(Gt.EDITOR),c=F6(),{rename:d}=KC(),m=()=>{r?.result.columns?.[0].table&&Pd({table:r?.result.columns?.[0].table,dataSourceId:n})},p=async()=>{const v=await Or("Query name",l);!v||!r?.result.queryHistoryId||c.mutate({name:v,queryId:r.result.queryHistoryId})},y=()=>d(l);return un("s",p),un("r",y),h.jsxs("div",{className:se.tableConfig,children:[h.jsx("button",{"data-tooltip-id":"default","data-tooltip-content":"Rename tab",onClick:y,className:re(se.tableAction,se.blue,"block"),children:h.jsxs("span",{className:se.tabName,children:["🛠️ ",l]})}),h.jsxs("button",{"data-tooltip-id":"explorer-more-actions",className:re(se.tableAction,se.blue),children:[h.jsx("span",{className:"whitespace-nowrap",children:"Options"}),h.jsx(vr,{width:16,height:16,className:"rotate-90"})]}),h.jsxs(gu,{id:"explorer-more-actions",className:"z-10 shadow-md flex flex-col",clickable:!0,variant:"light",opacity:1,children:[h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Manage filters",onClick:()=>Ln("filters"),className:re(se.tableAction,se.modal,se.blue),children:[h.jsx("span",{children:"Filters"}),h.jsx("span",{className:"hotkey",children:"F"})]}),h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Join tables",onClick:()=>Ln("joins"),className:re(se.tableAction,se.modal,se.blue),children:[h.jsx("span",{children:"Joins"}),h.jsx("span",{className:"hotkey",children:"J"})]}),h.jsxs("button",{onClick:()=>Ln("columns"),className:re(se.tableAction,se.modal,se.blue,"justify-between"),children:[h.jsx("span",{children:"Columns"}),h.jsx("span",{className:"hotkey",children:"C"})]}),h.jsxs("button",{onClick:()=>Ln("groupBy"),className:re(se.tableAction,se.modal,se.blue,"justify-between"),children:[h.jsx("span",{children:"Group by"}),h.jsx("span",{className:"hotkey",children:"G"})]}),h.jsxs("button",{onClick:()=>Ln("aggregate"),className:re(se.tableAction,se.modal,se.blue,"justify-between"),children:[h.jsx("span",{children:"Aggregate"}),h.jsx("span",{className:"hotkey",children:"A"})]}),u&&h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"h-0.5 my-2 bg-gray-100"}),h.jsxs("button",{onClick:p,className:re(se.tableAction,se.modal,se.blue),children:[h.jsx("span",{children:"Save query"}),h.jsx("span",{className:"hotkey",children:"S"})]}),i?.allowInsert===!0&&h.jsx("button",{onClick:m,className:re(se.tableAction,se.modal,se.blue),children:"Insert new row"})]})]})]})}const o_=[5,10,20,50,100,200];function u_(){const{page:n,size:l,setPage:i,setSize:r}=X6(),{data:u,refetch:c,isFetching:d}=b.useContext(Ra),{name:m}=b.useContext(gl),{state:p}=b.useContext(Jt),y=si(),v=Et(),x=()=>{y.mutateAsync({name:m,opts:p}).then(_=>{v(`${Ye.workbench.path}/tab/${_.id}`)})},E=()=>{if(u?.result.queryHistoryId){const _=new URL(window.location.href);_.pathname=Ye.share.path,_.searchParams.set("shareId",u.result.queryHistoryId),navigator.clipboard.writeText(_.toString()),Zt.success("Share link copied to clipboard")}};un("d",x);const C=n*l,w=!d&&!!u?.result.hasMore,j=u?.result.rows.length||0,N=()=>{n>0&&i(n-1)},T=()=>{w&&i(n+1)};return h.jsxs("div",{className:se.tableConfig,children:[h.jsxs("span",{"data-tooltip-id":"rows-num",className:se.paginationIndicator,children:[C+1," - ",C+j,w&&"+"]}),h.jsx("span",{"data-tooltip-content":"Previous page","data-tooltip-id":"default",className:re(se.tableAction,se.blue,n<1&&"opacity-30"),onClick:N,role:"button",children:h.jsx(vr,{width:16,height:16,className:"rotate-180"})}),h.jsx("span",{"data-tooltip-content":"Next page","data-tooltip-id":"default",className:re(se.tableAction,w?se.blue:"opacity-30"),onClick:T,role:"button",children:h.jsx(vr,{width:16,height:16})}),h.jsx("span",{"data-tooltip-content":"Refresh data","data-tooltip-id":"default",className:re(se.tableAction,se.blue),onClick:()=>c(),role:"button",children:h.jsx(Qg,{width:16,height:16})}),h.jsx("span",{"data-tooltip-content":"Share query","data-tooltip-id":"default",className:re(se.tableAction,se.blue),onClick:E,role:"button",children:h.jsx(VC,{width:16,height:16})}),h.jsx("span",{"data-tooltip-content":"Duplicate tab","data-tooltip-id":"default",className:re(se.tableAction,se.blue),onClick:x,role:"button",children:h.jsx(Yg,{width:16,height:16})}),h.jsx(gu,{id:"rows-num",className:"z-10 shadow-md flex gap-1",clickable:!0,variant:"light",opacity:1,children:o_.map(_=>h.jsx("button",{onClick:()=>r(_,!0),className:re(se.tableAction,se.blue,_===l&&se.selectedSize),children:h.jsx("span",{children:_})},_))})]})}const c_="_drop-container_ee5e3_2",f_="_item_ee5e3_2",Zy={dropContainer:c_,item:f_},Td=({dataSourceId:n,focusId:l,placeholder:i="Column",onChange:r,value:u,autoFocus:c,allowTables:d})=>{const{data:m}=ai(n),p=b.useRef(null),y=b.useMemo(()=>{if(!m)return[];let T=m;return d&&(T=m.filter(_=>d.includes(_.tableName))),T.flatMap(_=>_.columns.map(O=>({value:_.tableName+"."+O.name,label:O.name,table:_.tableName,searchValue:O.name.toLowerCase()})))},[m,d]),v=b.useMemo(()=>{const T=u.toLowerCase()||"",_=[];for(let O=0;O<y.length&&_.length<10;O++)y[O].searchValue.includes(T)&&_.push(y[O]);return _},[y,u]),[x,E]=b.useState(!1),[C,w]=b.useState(0),j=T=>{if(T.key==="ArrowDown")T.preventDefault(),w(_=>(_+1)%v.length);else if(T.key==="ArrowUp")T.preventDefault(),w(_=>(_-1+v.length)%v.length);else if(T.key==="Enter"&&C>=0&&C<v.length){T.preventDefault();const _=v[C].value;E(!1);const O=y.findIndex(H=>H.value===_)>-1;r(v[C]?.value||_,O,!0)}};b.useEffect(()=>{const T=p.current?.querySelector('[data-is-active="true"]');T&&T.scrollIntoView({behavior:"smooth",block:"nearest"})},[C]);const N=T=>{const _=T.currentTarget.value,O=y.findIndex(H=>H.value===_)>-1;r(_,O,!1)};return h.jsxs("div",{className:"relative",onFocus:()=>E(!0),onBlur:()=>E(!1),children:[h.jsx("input",{autoFocus:c,onKeyDown:j,value:u,onChange:N,className:"input w-full",placeholder:i,"data-focus":l}),x&&v.length>0&&h.jsx("div",{className:Zy.dropContainer,ref:p,tabIndex:-1,children:v.map((T,_)=>h.jsxs("div",{className:Zy.item,"data-is-active":C===_,onMouseDownCapture:O=>{O.preventDefault(),E(!1),r(T.value,!0,!0)},children:[h.jsx("span",{className:"text-xs font-semibold truncate",children:T.table}),h.jsx("p",{className:"truncate text-sm",children:T.label})]},_))})]})},d_="_drop-container_1rgb9_2",h_="_item_1rgb9_2",Py={dropContainer:d_,item:h_};function m_(n){return j4.includes(n)?C4:T4.includes(n)?E4:A4.includes(n)?_4:Gd}const p_=({value:n,onChange:l,autoFocus:i,focusId:r,colType:u})=>{const c=b.useMemo(()=>{const E=n.toLowerCase()||"";return m_(u||"").filter(C=>C.label.includes(E))},[n,u]),d=b.useRef(null),[m,p]=b.useState(!1),[y,v]=b.useState(0),x=E=>{E.key==="ArrowDown"?(E.preventDefault(),v(C=>(C+1)%c.length)):E.key==="ArrowUp"?(E.preventDefault(),v(C=>(C-1+c.length)%c.length)):E.key==="Enter"&&(y>=0&&y<c.length?(E.preventDefault(),p(!1),l(c[y]?.label||"",!0)):l(n,!0))};return b.useEffect(()=>{const E=d.current?.querySelector('[data-is-active="true"]');E&&E.scrollIntoView({behavior:"smooth",block:"nearest"})},[y]),h.jsxs("div",{className:"relative",children:[h.jsx("input",{onKeyDown:x,value:n,onChange:E=>l(E.target.value,!1),className:"input w-full",placeholder:"Operator",autoFocus:i,onFocus:()=>p(!0),onBlur:()=>p(!1),"data-focus":r}),m&&c.length>0&&h.jsx("ul",{className:Py.dropContainer,ref:d,tabIndex:-1,children:c.map((E,C)=>h.jsx("li",{className:Py.item,"data-is-active":y===C,onMouseDownCapture:w=>{w.preventDefault(),p(!1),l(E.label,!0)},children:E.label},C))})]})},Zg=()=>{const{state:n,setState:l}=b.useContext(Jt),i=b.useCallback((u,c=!1)=>{l(d=>({...d,page:c?0:d.page,filters:u}))},[l]),r=b.useCallback(u=>{l(c=>({...c,filters:c.filters.filter(d=>d.id!==u)}))},[l]);return{filters:n.filters,removeFilter:r,setFilters:i}},y_="_actions_4u23n_2",g_="_filter-actions_4u23n_2",Pg={actions:y_,filterActions:g_},v_=["=","<",">",">=","<>","!=","<="];function b_(n){for(let l=0;l<n.length;l++){const i=n[l];if(!i.operator.length&&!i.value.length&&!i.column.length)continue;if(!i.column.includes("."))return Zt.error(`Filter #${l+1} has invalid column value`),!1;const r=Xd[i.operator];if(!r)return Zt.error(`Filter #${l+1} has invalid operator`),!1;if(i.isColumnRef&&!v_.includes(r))return Zt.error(`Filter #${l+1} cannot reference another column because it uses '${i.operator}' operator`),!1}return!0}function x_(n){const l=[];return n.forEach(i=>{if(!i.operator.length||!i.column.length||i.operator!=="is null"&&i.operator!=="is not null"&&!i.value.length)return;const r=Xd[i.operator];l.push({id:i.id,value:i.isColumnRef?[{value:i.value,isColumn:!0}]:N4(r,i.value),operator:r,column:i.column,isEnabled:i.isEnabled,connector:"AND"})}),l}function S_(n){let l="";if(n.value)for(let i=0;i<n.value.length;i++)l+=n.value[i].value,i<n.value.length-1&&(l+=", ");return l}const w_=({filter:n,dataSourceId:l,allowedTables:i,inspections:r,autoFocus:u,onChangeColumn:c,onChangeOperator:d,onChangeValue:m,onRemoveFilter:p,triggerIsEnabled:y,onIsColumnChange:v})=>{const x=b.useMemo(()=>{if(!r)return"";let E=null;for(const C of r)for(const w of C.columns)C.tableName+"."+w.name===n.column&&(E=w);return E?.type?E.type:""},[n.column,r]);return h.jsxs("div",{className:"flex gap-2 items-center",children:[h.jsx("label",{children:h.jsx("input",{type:"checkbox",checked:n.isEnabled!==!1,onClick:()=>y(n.id)})}),h.jsx("label",{className:"w-full",children:h.jsx(Td,{dataSourceId:l,onChange:E=>c(n.id,E),value:n.column,allowTables:i,focusId:"column",autoFocus:u})}),h.jsx("label",{children:h.jsx(p_,{onChange:E=>d(n.id,E),focusId:"operator",colType:x,value:n.operator})}),yg(Xd[n.operator])&&h.jsx("label",{className:"w-full",children:n.isColumnRef?h.jsx(Td,{dataSourceId:l,onChange:E=>m(n.id,E),value:n.value,allowTables:i,focusId:"value",placeholder:"Search column"}):h.jsx("input",{className:"input w-full",placeholder:"Filter value",value:n.value,onChange:E=>m(n.id,E.currentTarget.value),"data-focus":"value"})}),h.jsxs("div",{className:Pg.filterActions,children:[h.jsx("button",{tabIndex:-1,"data-tooltip-id":"default","data-tooltip-content":"If enabled, the value will reference another column instead of being raw string",className:re("p-0.5 cursor-pointer rounded-lg border",n.isColumnRef?"bg-blue-50 border-blue-200":"bg-white border-white"),onClick:()=>v(n.id,!n.isColumnRef),children:"🏷️"}),h.jsx("button",{tabIndex:-1,"data-tooltip-id":"default","data-tooltip-content":"Remove filter",className:"p-0.5 text-sm cursor-pointer",onClick:()=>p(n.id),children:h.jsx(Pl,{width:20,height:20,className:"text-red-600"})})]})]})},E_=()=>{const{state:n}=b.useContext(Jt),{setFilters:l}=Zg(),i=ju(N=>N.filters),{data:r}=ai(n.dataSourceId),u=b.useMemo(()=>[n.table,...n.joins.map(N=>N.table)],[n.table,n.joins]),[c,d]=b.useState([]),m=(N,T)=>{d(_=>[..._.map(O=>O.id===N?{...O,column:T}:O)])},p=(N,T)=>{d(_=>[..._.map(O=>O.id===N?{...O,operator:T}:O)])},y=(N,T)=>{d(_=>[..._.map(O=>O.id===N?{...O,value:T}:O)])},v=()=>{d(N=>[...N,{id:dl(),value:"",column:"",operator:"",isColumnRef:!1,isEnabled:!0}])},x=(N,T)=>{d(_=>[..._.map(O=>O.id===N?{...O,isColumnRef:T}:O)])},E=N=>{d(T=>T.filter(_=>_.id!==N))},C=()=>Tu("filters"),w=()=>{b_(c)&&(l(x_(c)),C())},j=N=>{d(T=>T.map(_=>_.id===N?{..._,isEnabled:!_.isEnabled}:_))};return b.useEffect(()=>{i&&d(()=>{const N=n.filters.map(T=>({id:T.id,value:S_(T),column:T.column,operator:pg[T.operator],isColumnRef:!!T.value?.[0]?.isColumn,isEnabled:T.isEnabled}));return N.push({id:dl(),value:"",column:"",operator:"",isColumnRef:!1,isEnabled:!0}),N})},[i]),un("f",()=>{hu("filters")}),un("ctrl+f",()=>{alert("Save filters")}),h.jsxs(fn,{isVisible:i,onClose:C,portal:!0,onClosed:()=>d([]),children:[h.jsx(aa,{onClick:C}),h.jsx("h2",{className:"text-lg font-semibold",children:"Filters"}),h.jsxs("div",{className:"flex gap-4 flex-col w-full lg:w-lg my-4",children:[c.length<1&&h.jsx("p",{className:"p-1 text-center rounded-lg bg-gray-50 border border-gray-200",children:"No filters"}),c.map((N,T)=>h.jsx(w_,{filter:N,dataSourceId:n.dataSourceId,allowedTables:u,inspections:r||[],onChangeColumn:m,onChangeOperator:p,onChangeValue:y,onRemoveFilter:E,onIsColumnChange:x,triggerIsEnabled:j,autoFocus:T===c.length-1},N.id))]}),h.jsxs("div",{className:Pg.actions,children:[h.jsx("button",{className:"button tertiary",onClick:v,children:"Add filter"}),h.jsx("button",{className:"button primary",onClick:w,children:"Apply filters"})]})]})},C_="_join-modal_zzevr_2",__={joinModal:C_},N_=(n,l)=>n.type!==l.type||n.on!==l.on||n.table!==l.table,j_=(n,l)=>n.type===l.type&&n.on===l.on&&n.table===l.table,Jg=()=>{const{state:n,setState:l}=b.useContext(Jt),i=b.useCallback(r=>{l(u=>{const c=u.joins;if(c.some(m=>j_(m,r))){const m=r.table+".";return{...u,joins:c.filter(p=>N_(p,r)),columns:u.columns.filter(p=>!p.value.startsWith(m)),groupBy:u.groupBy.filter(p=>!p.value.startsWith(m)),orderBy:u.orderBy.filter(p=>!p.column.startsWith(m)),aggregations:u.aggregations.filter(p=>!p.value.startsWith(m)),filters:u.filters.filter(p=>!p.column.startsWith(m))}}return{...u,joins:[...c,r]}})},[l]);return{joins:n.joins,toggle:i}},T_=()=>{const{isFetching:n}=b.useContext(Ra),l=ju(p=>p.joins),{toggle:i}=Jg(),{availableJoins:r}=b.useContext(gl),[u,c]=b.useState(""),d=b.useMemo(()=>{const p=u.toLowerCase();return r.filter(y=>y.on.toTable.toLowerCase().includes(p))},[r,u]),m=()=>Tu("joins");return un("j",()=>{r.length>0?Ln("joins"):Zt.error("No available tables to join")}),h.jsxs(fn,{isVisible:l,onClose:m,portal:!0,children:[h.jsx(aa,{onClick:m}),h.jsxs("div",{className:__.joinModal,children:[h.jsx("h2",{className:"text-lg font-semibold mb-4",children:"Join table"}),r.length>0?h.jsx("input",{className:"input w-full",placeholder:"Filter",autoFocus:!0,onChange:p=>c(p.target.value),value:u,disabled:n}):h.jsx(wt,{variant:"warning",children:h.jsx("p",{className:"text-sm truncate",children:"There is nothing else to join"})}),h.jsx("div",{className:`flex flex-col mt-2 overflow-y-auto ${n?"opacity-40":""}`,children:d.map(p=>h.jsx(Tg,{hook:p,onClick:()=>{n||(i({table:p.on.toTable,type:"LEFT",on:p.where}),c(""),m())}},p.where))})]})]})};function A_(n){return n.reduce((l,i)=>(l[i]=!0,l),{})}function Jy(n){return n.reduce((l,i)=>(l[i]=!0,l),{})}const R_="_container_1a3k0_2",O_="_column-label_1a3k0_2",D_="_not-active_1a3k0_2",iu={container:R_,columnLabel:O_,notActive:D_};function M_(n){if(!n)return[];const l={};return n.forEach(i=>{l[i.table]?l[i.table].push({value:i.full,ogColumn:i.column,label:ol(i.column),type:i.type}):l[i.table]=[{value:i.full,ogColumn:i.column,label:ol(i.column),type:i.type}],R4[i.type]&&["YEAR","MONTH","DAY"].forEach(r=>{l[i.table].push({value:r+" "+i.full,ogColumn:i.column,label:r+" "+ol(i.column),type:"number",nested:!0})})}),Object.entries(l).reduce((i,[r,u])=>(i.push({name:ol(r),columns:u}),i),[])}function L_(n,l){const i=l.toLowerCase();return n.map(r=>{const u=r.columns.filter(c=>c.label.toLowerCase().includes(i)||c.ogColumn.toLowerCase().includes(i));return{...r,columns:u}}).filter(r=>r.columns.length>0)}const U_=({column:n,selected:l,onCheck:i})=>h.jsxs("label",{className:re(iu.columnLabel,l?iu.active:iu.notActive,n.nested&&"pl-5!"),children:[h.jsx("input",{type:"checkbox",checked:l[n.value],name:n.value,onChange:i}),h.jsxs("p",{className:"flex justify-between w-full",children:[h.jsx("span",{"data-tooltip-content":n.value,"data-tooltip-id":"default",children:n.label}),h.jsx("span",{className:"text-blue-600",children:n.type})]})]},n.value),z_={columns:"c",groupBy:"g"},Iy=({mode:n})=>{const l=ju(_=>_[n]),{allColumns:i}=b.useContext(gl),{state:r,setState:u}=b.useContext(Jt),[c,d]=b.useState({}),[m,p]=b.useState(""),y=b.useMemo(()=>M_(i),[i]),v=r.aggregations.length>0||r.groupBy.length>0,x=b.useMemo(()=>m?L_(y,m):y,[m,y]),E=_=>{d(O=>({...O,[_.target.name]:_.target.checked}))},C=_=>{const O=_.target.checked;d(H=>{for(const G of i)H[G.full]=O;return{...H}})},w=()=>{Tu(n)},j=()=>{const _=[];for(const[O,H]of Object.entries(c))if(H){const[G,Y]=O.split(" ");_.push({value:Y||G,fn:Y?G:void 0})}u(O=>({...O,[n]:_})),w()},N=b.useMemo(()=>{for(const _ of i)if(!c[_.full])return!1;return!0},[c,i]);un(z_[n],()=>{n==="columns"?v?Zt.error("Columns are ignored when there is at least one aggregation or group by"):hu("columns"):hu("groupBy")}),b.useEffect(()=>{l&&d(()=>A_(r[n].map(_=>_.fn?_.fn+" "+_.value:_.value)))},[l,d]);const T=()=>{p(""),d({})};return h.jsxs(fn,{isVisible:l,onClose:w,portal:!0,onClosed:T,children:[h.jsx(aa,{onClick:w}),h.jsxs("div",{className:iu.container,children:[h.jsx("h2",{className:"text-lg font-semibold",children:n==="groupBy"?"Group by":"Show columns"}),h.jsx("input",{autoFocus:!0,className:"input my-2",placeholder:"Filter",value:m,onChange:_=>p(_.target.value)}),h.jsx("div",{className:"overflow-y-auto",children:x.map(_=>h.jsxs("div",{className:"my-2",children:[h.jsxs("p",{className:"font-semibold sticky top-0 bg-white p-1 z-1",children:["📄 ",_.name]}),_.columns.map(O=>h.jsx(U_,{column:O,selected:c,onCheck:E},O.value))]},_.name))}),h.jsxs("div",{className:"flex justify-end gap-2 mt-2",children:[h.jsxs("label",{className:"button tertiary flex gap-2 items-center",children:[h.jsx("input",{type:"checkbox",checked:N,onChange:C}),h.jsx("span",{children:"Select all"})]}),h.jsx("span",{className:"flex-1"}),h.jsx("button",{className:"button tertiary",onClick:w,children:"Cancel"}),h.jsx("button",{className:"button primary",onClick:j,children:"Apply"})]})]})]})},k_="_options-container_zt8yv_2",q_={optionsContainer:k_},ld="COUNT all",B_=()=>{const n=ju(w=>w.aggregate),{dataSourceId:l}=b.useContext(gl),{setState:i,state:r}=b.useContext(Jt),{data:u}=b.useContext(Ra),[c,d]=b.useState({fn:"",col:""}),m=w=>d({...c,fn:w.currentTarget.value}),p=w=>d({...c,col:w}),y=()=>Tu("aggregate"),v=()=>{const w=c.fn===ld?{value:"*",fn:"COUNT"}:{fn:c.fn,value:c.col,distinct:c.fn==="COUNT"};i(j=>({...j,aggregations:[...j.aggregations,w]}))},x=c.fn===ld,E=x?!1:!c.col||!c.fn,C=w=>{const j=gg(w);i(N=>({...N,aggregations:N.aggregations.filter(T=>T.fn!==w.fn||T.value!==w.value),orderBy:N.orderBy.filter(T=>T.column!==j)}))};return un("a",()=>{hu("aggregate")}),h.jsxs(fn,{isVisible:n,onClose:y,backdropClose:!0,portal:!0,children:[h.jsx(aa,{onClick:y}),h.jsxs("div",{children:[h.jsx("h2",{className:"text-lg font-semibold",children:"Aggregate"}),hl(r.aggregations.length,0)&&h.jsx("div",{className:"flex flex-col gap-1 mt-4",children:r.aggregations.map((w,j)=>h.jsxs("p",{className:"p-2 rounded-md bg-gray-50 flex items-center justify-between",children:[h.jsx("span",{children:lu(w)}),h.jsx("button",{tabIndex:-1,"data-tooltip-id":"default","data-tooltip-content":"Remove aggregation",className:"p-0.5 text-sm cursor-pointer",onClick:()=>C(w),children:h.jsx(Pl,{width:20,height:20,className:"text-red-600"})})]},j))}),h.jsxs("div",{className:q_.optionsContainer,children:[h.jsxs("label",{className:re(x&&"col-span-2"),children:[h.jsx("p",{className:"font-semibold text-xs",children:"Function"}),h.jsxs("select",{className:"input w-full",value:c.fn,onChange:m,autoFocus:!0,children:[h.jsx("option",{value:"",disabled:!0,children:"Select function"}),h.jsx("option",{value:ld,children:"Count all rows"}),h.jsx("option",{value:"COUNT",children:"Count"}),h.jsx("option",{value:"SUM",children:"Sum"}),h.jsx("option",{value:"MAX",children:"Max"}),h.jsx("option",{value:"MIN",children:"Min"}),h.jsx("option",{value:"AVG",children:"Avg"})]})]}),!x&&h.jsxs("label",{children:[h.jsx("p",{className:"font-semibold text-xs",children:"Column"}),h.jsx(Td,{dataSourceId:l,allowTables:u?.result.tables||[],onChange:p,value:c.col})]}),h.jsx("button",{className:"button primary",disabled:E,onClick:v,children:"Add"})]})]})]})},H_="_container_xly2t_2",Q_="_yellow-pill_xly2t_2 _pill_xly2t_2",Y_="_yellow-outline-pill_xly2t_2 _pill_xly2t_2",V_="_green-pill_xly2t_2 _pill_xly2t_2",K_="_blue-pill_xly2t_2 _pill_xly2t_2",$_="_blue-outline-pill_xly2t_2 _pill_xly2t_2",G_="_purple-pill_xly2t_2 _pill_xly2t_2",X_="_red-pill_xly2t_2 _pill_xly2t_2",F_="_black-pill_xly2t_2 _pill_xly2t_2",Z_="_disabled-pill_xly2t_2",Jn={container:H_,yellowPill:Q_,yellowOutlinePill:Y_,greenPill:V_,bluePill:K_,blueOutlinePill:$_,purplePill:G_,redPill:X_,blackPill:F_,disabledPill:Z_},Wy=n=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},b.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32,d:"M256 112v288M400 256H112"}));function Ig(n,l=500,i){const[r,u]=b.useState(n),c=b.useRef(i);return c.current=i,b.useEffect(()=>{const d=setTimeout(()=>{u(n),c.current&&c.current(n)},l);return()=>clearTimeout(d)},[n,l]),r}function P_(n){return!(n===!0||n===void 0)}const J_=()=>{const{state:{table:n,dataSourceId:l,aggregations:i,columns:r,groupBy:u}}=b.useContext(Jt),{filters:c,setFilters:d,removeFilter:m}=Zg(),{toggle:p,joins:y}=Jg(),{data:v}=Nu(l),x=()=>Ln("joins"),E=()=>Ln("filters"),C=()=>Ln("aggregate"),w=()=>Ln("columns"),j=()=>Ln("groupBy"),N=O=>{d(c.map(H=>({...H,isEnabled:O===H.id?P_(H.isEnabled):H.isEnabled})),!0)},T=O=>{O.preventDefault(),O.stopPropagation(),p(y[y.length-1])},_=O=>H=>{H.preventDefault(),H.stopPropagation(),m(O)};return h.jsxs("div",{className:Jn.container,children:[v&&h.jsxs("button",{onClick:x,className:Jn.greenPill,"data-tooltip-id":"default","data-tooltip-content":n,children:[h.jsx(ii,{size:18,type:v.dbType}),h.jsx("p",{className:"text-sm",children:v.name}),h.jsx(vr,{width:12,height:12}),h.jsx("p",{className:"text-sm",children:n})]}),h.jsxs("button",{onClick:x,className:Jn.yellowOutlinePill,"data-tooltip-id":"default","data-tooltip-content":"Join table, hotkey J",children:[h.jsx(Wy,{width:18,height:18}),h.jsx("p",{className:"text-sm",children:"Table"})]}),y.map((O,H)=>h.jsxs("button",{onClick:x,className:Jn.yellowPill,"data-tooltip-id":"default","data-tooltip-content":`Joins ${O.table} on ${O.on}`,children:[h.jsx("p",{className:"text-sm",children:O.table}),H===y.length-1&&h.jsx(Pl,{onClick:T,width:18,height:18})]},O.table)),h.jsxs("button",{onClick:E,className:Jn.blueOutlinePill,"data-tooltip-id":"default","data-tooltip-content":"Add filters, hotkey F",children:[h.jsx(Wy,{width:18,height:18}),h.jsx("p",{className:"text-sm",children:"Filter"})]}),c.map(O=>h.jsxs("button",{onClick:()=>N(O.id),onAuxClick:()=>m(O.id),className:re(Jn.bluePill,O.isEnabled===!1&&Jn.disabledPill),"data-tooltip-id":"default","data-tooltip-content":xE(O),children:[h.jsx("p",{className:"text-sm",children:O.column}),h.jsx("p",{className:"text-sm",children:O.operator}),h.jsx("p",{className:"text-sm",children:SE(O)}),h.jsx(Pl,{onClick:_(O.id),width:18,height:18})]},O.id)),i.map(O=>h.jsx("button",{onClick:C,className:re(Jn.purplePill),"data-tooltip-id":"default","data-tooltip-content":lu(O),children:h.jsx("p",{className:"text-sm",children:lu(O)})},lu(O))),r.length>0&&h.jsx("button",{onClick:w,className:re(Jn.redPill),"data-tooltip-id":"default","data-tooltip-content":"Has hidden columns",children:h.jsx("p",{className:"text-sm",children:"Hidden columns"})}),u.length>0&&h.jsx("button",{onClick:j,className:re(Jn.blackPill),"data-tooltip-id":"default","data-tooltip-content":"Has GROUP BY",children:h.jsx("p",{className:"text-sm",children:"GROUP BY"})}),h.jsx(I_,{})]})};function I_(){const{state:n,setState:l}=b.useContext(Jt),[i,r]=b.useState(()=>n.searchAll);return un("k",()=>{Or("Search all text values for",n.searchAll||"",{type:"info",message:"This will search all text values using LIKE operator (numbers, dates and other non string values are not searched)."}).then(c=>{c!==void 0&&(l(d=>({...d,searchAll:c.length>0?c:void 0})),r(c.length>0?c:void 0))})}),Ig(i,500,c=>{l(d=>({...d,searchAll:c&&c.length>0?c:void 0}))}),h.jsx("input",{className:"input text-sm","data-tooltip-id":"default","data-tooltip-content":"Search text in all columns. Can be slow when using a lot of columns.",placeholder:"Search text in all columns",value:i||"",onChange:c=>r(c.currentTarget.value)})}const W_=({options:n,updater:l,name:i,tabId:r})=>{const u=M4(n,l),c=q4(r,u.state),d=D4(c.data,u.state.dataSourceId,i,r);return c.isError?h.jsx("div",{className:"flex-1",children:h.jsx(wt,{variant:"danger",children:"Failed to load query"})}):h.jsx(gl,{value:d,children:h.jsx(Jt,{value:u,children:h.jsxs(Ra,{value:c,children:[h.jsx(i_,{}),h.jsx(J_,{}),h.jsxs("div",{className:"flex-1 flex overflow-hidden border-t border-gray-200",children:[h.jsx("div",{className:"flex-1 overflow-auto pb-24 lg:pb-12 no-scrollbar",children:h.jsx(G6,{})}),h.jsx(E_,{}),h.jsx(T_,{}),h.jsx(Iy,{mode:"columns"}),h.jsx(Iy,{mode:"groupBy"}),h.jsx(B_,{})]})]})})})},Wg=()=>h.jsxs("div",{role:"status",children:[h.jsxs("svg",{"aria-hidden":"true",className:"w-8 h-8 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600",viewBox:"0 0 100 101",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[h.jsx("path",{d:"M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z",fill:"currentColor"}),h.jsx("path",{d:"M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z",fill:"currentFill"})]}),h.jsx("span",{className:"sr-only",children:"Loading..."})]}),e5=({id:n})=>{const{data:l}=U4(n),i=b.useCallback(r=>{if(!l)return;const u=r($s(l.opts));rt.setQueryData(["workbench-tabs",l.id],{...l,opts:{...l.opts,...u}})},[l]);return l?h.jsx(W_,{updater:i,options:l.opts,name:l.name,tabId:l.id}):h.jsx("div",{className:"flex-1 flex justify-center items-center",children:h.jsx(Wg,{})})},t5=n=>{setTimeout(l=>{const i=document.querySelector(`[data-tab-id="${l}"]`);i&&i.scrollIntoView({behavior:"smooth"})},50,n)},n5=()=>{const{id:n}=W2(),l=Et(),{data:i}=Zd(),r=z4(),u=Cg(eh.laptop),c=p=>{if(p===n&&i){if(i.length===1)return l(Ye.home.path);if(i.length>1){const y=i.find(v=>v.id!==p);if(y)return l(`/workbench/tab/${y.id}`)}}},d=p=>{p.stopPropagation(),p.preventDefault();const y=p.currentTarget.getAttribute("data-tab-id");y&&(r.mutate(y),c(y))},m=p=>{r.mutate(p),c(p)};return b.useEffect(()=>{n&&t5(n)},[n]),h.jsxs("div",{className:"h-screen max-h-screen bg-(--bg) flex flex-col",children:[n&&h.jsx(e5,{id:n}),h.jsx("div",{className:re(cr.tabs,"no-scrollbar",!u&&cr.mobile),children:i?.map(p=>h.jsxs("div",{onClick:()=>l(`${Ye.workbench.path}/tab/${p.id}`),className:re(cr.tab,p.id===n&&cr.active),"data-tooltip-id":"default","data-tab-id":p.id,"data-tooltip-content":p.name,onAuxClick:()=>m(p.id),children:[h.jsxs("span",{className:"truncate w-full",children:["🛠️ ",p.name]}),h.jsx("button",{"data-tab-id":p.id,className:cr.closeButton,onClick:d,children:h.jsx(Pl,{width:20,height:20})})]},p.id))})]})},a5="_root_z8w66_2",l5="_up_z8w66_2",s5="_down_z8w66_2",i5="_chevron_z8w66_2",r5="_table-name-container_z8w66_2",o5="_link_z8w66_2",u5="_table-name_z8w66_2",c5="_ul_z8w66_2",f5="_column-type_z8w66_2",d5="_action-blue_z8w66_2 _action_z8w66_2",h5="_action-red_z8w66_2 _action_z8w66_2",Kt={root:a5,up:l5,down:s5,chevron:i5,tableNameContainer:r5,link:o5,tableName:u5,ul:c5,columnType:f5,actionBlue:d5,actionRed:h5},[IN,m5]=cn(!1),ev=()=>m5(!1),p5="_sidebar_1f06u_2",y5="_sidebar-visible_1f06u_2",g5="_sidebar-container_1f06u_2",v5="_sidebar-invisible_1f06u_2",b5="_backdrop_1f06u_2",fr={sidebar:p5,sidebarVisible:y5,sidebarContainer:g5,sidebarInvisible:v5,backdrop:b5},tv=({children:n,backdropClose:l,isVisible:i,onClose:r,onClosed:u,contentClassName:c})=>{const[d,m]=b.useState(!1),p=b.useRef(r);p.current=r;const y=()=>{l&&r()},v=x=>{i||getComputedStyle(x.currentTarget).opacity==="0"&&(m(!1),u&&u())};return b.useEffect(()=>{i&&m(!0)},[i]),b.useEffect(()=>{const x=E=>{i&&E.key==="Escape"&&p.current()};return window.addEventListener("keydown",x),()=>{window.removeEventListener("keydown",x)}},[i]),h.jsxs("div",{onTransitionEnd:v,className:re(fr.sidebar,i?fr.sidebarVisible:fr.sidebarInvisible),children:[h.jsx("div",{onClick:y,className:fr.backdrop}),h.jsx("div",{className:re(fr.sidebarContainer,c),children:d&&n})]})},x5=n=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},b.createElement("path",{d:"M384 224v184a40 40 0 01-40 40H104a40 40 0 01-40-40V168a40 40 0 0140-40h167.48M336 64h112v112M224 288L440 72",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32})),S5=n=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},b.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32,d:"M364.13 125.25L87 403l-23 45 44.99-23 277.76-277.13-22.62-22.62zM420.69 68.69l-22.62 22.62 22.62 22.63 22.62-22.63a16 16 0 000-22.62h0a16 16 0 00-22.62 0z"})),w5=n=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},b.createElement("path",{d:"M432 144l-28.67 275.74A32 32 0 01371.55 448H140.46a32 32 0 01-31.78-28.26L80 144",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32}),b.createElement("rect",{x:32,y:64,width:448,height:80,rx:16,ry:16,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32}),b.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32,d:"M312 240L200 352M312 352L200 240"})),nv=(n,l=!0)=>{const i=navigator.clipboard.writeText(n);l&&i.then(()=>{Zt.success(`Copied "${n}"`)})},E5=new Intl.DateTimeFormat("en",{dateStyle:"full",timeStyle:"long"}),Jo=18;function C5(n,l){return l&&n.toLowerCase().includes(l)?"bg-yellow-200 cursor-pointer":"cursor-pointer"}const _5=({insp:n,filter:l,expanded:i})=>{const r=b.useMemo(()=>i?n.columns:l.length<1?[]:n.columns.filter(u=>u.name.toLowerCase().includes(l)),[n,l,i]);return h.jsx("ul",{className:Kt.ul,children:r.map(u=>h.jsx(h.Fragment,{children:h.jsxs("li",{children:[u.isPrimary?"🔐":"🏷️"," ",h.jsx("span",{onClick:()=>nv(u.name),className:C5(u.name,l),children:u.name})," ",h.jsxs("span",{className:Kt.columnType,children:["[",u.type,"]"]}),u.ref&&h.jsxs("span",{children:[" ➡️ ",h.jsx("span",{className:Kt.columnType,children:u.ref.table}),".",u.ref.field]})]},u.name+u.type)}))},n.id)};function N5({id:n}){const{data:l}=Nu(n),{data:i}=ai(n),r=Et(),u=f4(),c=dg(),d=d4(),m=si(),p=b.useMemo(()=>l?.lastInspected?E5.format(new Date(l.lastInspected)):"--",[l]),[y,v]=b.useState({}),[x,E]=b.useState(""),[C,w]=b.useState("table"),j=Ar(Gt.EDITOR),N=x.toLowerCase(),T=b.useMemo(()=>{if(!N||!i)return i||[];const Z=[];for(const te of i){if(te.tableName.toLowerCase().includes(N)){Z.push(te);continue}C!=="table"&&te.columns.findIndex(ye=>ye.name.toLowerCase().includes(N))>=0&&Z.push(te)}return Z},[N,i,C]),_=Z=>{v(te=>({...te,[Z]:!te[Z]}))},O=Z=>{m.mutateAsync({name:Z,opts:$s({table:Z,dataSourceId:n})}).then(te=>{Gs(void 0),ev(),r(`${Ye.workbench.path}/tab/${te.id}`)})},H=()=>{c.mutate(n)},G=async()=>{const Z=await Or("Enter name",l?.name);Z&&u.mutate({id:n,dataSource:{name:Z}})},Y=async()=>{await wg("Are you sure you want to delete this data source?")&&(d.mutate(n),Gs(void 0))},K=C==="column";return h.jsxs("div",{className:Kt.root,children:[h.jsxs("div",{className:"sticky top-0 bg-white border-b border-gray-200 p-4",children:[h.jsxs("h3",{className:"page-head flex gap-2",children:[l&&h.jsx(ii,{size:32,type:l.dbType}),h.jsx("span",{className:"truncate",children:l?.name})]}),h.jsx("p",{className:"mt-2 text-xs text-gray-800",children:"Last DB inspection"}),h.jsx("p",{className:"text-sm font-semibold",children:p}),j&&h.jsxs("div",{className:"mt-2 flex gap-2",children:[h.jsxs("button",{disabled:c.isPending,onClick:H,className:Kt.actionBlue,children:[h.jsx(Qg,{width:16,height:16}),"INSPECT"]}),h.jsxs("button",{disabled:c.isPending,onClick:G,className:Kt.actionBlue,children:[h.jsx(S5,{width:16,height:16}),"RENAME"]}),h.jsxs("button",{disabled:c.isPending,onClick:Y,className:Kt.actionRed,children:[h.jsx(w5,{width:16,height:16}),"DELETE"]})]}),h.jsxs("div",{className:"flex gap-2 items-center mb-2 mt-4",children:[h.jsxs("select",{className:"input",value:C,onChange:Z=>w(Z.currentTarget.value),children:[h.jsx("option",{value:"table",children:"Table"}),h.jsx("option",{value:"column",children:"Column"})]}),h.jsx("input",{className:"input flex-1 bg-gray-50",placeholder:K?"Search column":"Search table",value:x,onChange:Z=>E(Z.target.value),autoFocus:!0})]})]}),h.jsx("div",{className:"overflow-y-auto p-4",children:T?.map(Z=>h.jsxs("div",{children:[h.jsxs("div",{className:Kt.tableNameContainer,children:[h.jsx("button",{className:re(Kt.chevron,y[Z.id]?Kt.down:Kt.up),onClick:()=>_(Z.id),children:h.jsx(vr,{width:16,height:16})}),h.jsx("button",{className:re(Kt.tableName,"flex-1"),onClick:()=>_(Z.id),children:Z.tableName}),h.jsx("button",{className:Kt.link,onClick:()=>O(Z.tableName),"data-tooltip-id":"default-xs","data-tooltip-content":"Explore table data",children:h.jsx(x5,{width:Jo,height:Jo})}),h.jsx("button",{className:Kt.link,onClick:()=>nv(Z.tableName),"data-tooltip-id":"default-xs","data-tooltip-content":"Copy table name",children:h.jsx(Yg,{width:Jo,height:Jo})})]}),(y[Z.id]||x.length>0)&&h.jsx(_5,{insp:Z,filter:K?N:"",expanded:y[Z.id]})]},Z.id))})]})}const j5=()=>{const n=cE(),[l,i]=b.useState(void 0);b.useEffect(()=>{n&&i(n)},[n]);const r=()=>Gs(void 0);return h.jsx(tv,{isVisible:n!=null,onClose:r,onClosed:()=>i(void 0),backdropClose:!0,children:l&&h.jsx(N5,{id:l})})},T5="_search_lk8p7_2",A5="_entry_lk8p7_2",R5="_ds_lk8p7_2",O5="_ds-container_lk8p7_2",D5="_ds-entry_lk8p7_2",M5="_enabled_lk8p7_2",Qs={search:T5,entry:A5,ds:R5,dsContainer:O5,dsEntry:D5,enabled:M5};function L5(n,l,i){try{const r=i.getItem(n);if(r)return JSON.parse(r)}catch(r){console.warn("Failed to restore tabs",r)}return l}const U5=({storage:n=localStorage,localStorageKey:l,initialData:i})=>{const r=cn(L5(l,i,n));return r[2].subscribe(u=>{n.setItem(l,JSON.stringify(u))}),r},[z5,k5]=U5({initialData:[],localStorageKey:"selected-data-sources-v1"}),q5=n=>k5(l=>{const i=l.indexOf(n);return i>-1?(l.splice(i,1),[...l]):[...l,n]}),B5={table:"📄",query:"📖",tab:"🛠️"},H5=({onTable:n,onQuery:l,onWorkbenchTab:i,autoFocus:r})=>{const[u,c]=b.useState(""),[d,m]=b.useState(-1),p=Ig(u,200),y=z5(),{data:v}=Bn(),{data:x}=$d({teamId:v?.teamId}),E=b.useMemo(()=>{const _=[],O=Jy(y);if(!x||x.length===0)return[];for(const H of x)O[H.id]&&_.push(H.id);return _},[y,x]),{data:C}=l4(p,{teamId:v?.teamId,selectedDataSources:E}),w=_=>{_.type==="table"?n(_.name,_.dataSourceId):_.type==="query"?l(_.id,_.dataSourceId):_.type==="tab"&&i(_.id,_.dataSourceId)},j=_=>{C&&(_.key==="ArrowDown"?(_.preventDefault(),m(O=>(O+1)%C.length)):_.key==="ArrowUp"?(_.preventDefault(),m(O=>(O-1+C.length)%C.length)):_.key==="Enter"&&d>=0&&C[d]?.name&&(_.preventDefault(),w(C[d])))},N=_=>{const O=_.currentTarget.dataset.tableId,H=C?.find(G=>G.id===O);H&&w(H)},T=b.useMemo(()=>Jy(y),[y]);return h.jsxs("div",{className:"overflow-hidden flex flex-col w-full lg:w-lg",children:[hl(x?.length,0)&&h.jsx("div",{className:Qs.dsContainer,children:x.map(_=>h.jsxs("button",{className:re(Qs.dsEntry,T[_.id]&&Qs.enabled),onClick:()=>q5(_.id),children:[h.jsx(ii,{size:24,type:_.dbType}),h.jsx("span",{children:_.name})]},_.id))}),h.jsx("input",{className:Qs.search,placeholder:"Search table or saved query to start from",value:u,onChange:_=>c(_.target.value),onKeyDown:j,autoFocus:r}),hl(C?.length,0)&&h.jsx("div",{className:"overflow-y-auto max-h-full mt-2",children:C.map((_,O)=>h.jsxs("button",{className:Qs.entry,"data-is-active":d===O,"data-table-id":_.id,onClick:N,children:[h.jsxs("p",{className:"font-semibold truncate",children:[B5[_.type]," ",_.name]}),h.jsxs("p",{className:Qs.ds,children:["📦 ",_.dataSourceName]})]},_.id))})]})},Q5=()=>{const n=H4(),l=(c,d)=>{n?.onConfirm("table",c,d)},i=(c,d)=>{n?.onConfirm("query",c,d)},r=(c,d)=>{n?.onConfirm("tab",c,d)},u=()=>{n?.onCancel()};return h.jsxs(fn,{isVisible:!!n,onClose:u,children:[h.jsx(aa,{onClick:u}),h.jsx(H5,{autoFocus:!0,onTable:l,onQuery:i,onWorkbenchTab:r})]})},Y5=()=>{const n=Tr("Hotkey"),l=Et(),{pathname:i}=qt(),{data:r}=Bn(),{data:u}=Zd(),c=i===Ye.home.path;un("n",()=>{r&&n()}),un("w",()=>{r&&(u&&u.length>0?l(`${Ye.workbench.path}/tab/${u[0].id}`):n())},{enabled:c}),un("h",()=>{Xs({show:!0})})},V5=()=>{const n=qt();b.useEffect(()=>{},[n.pathname])},[K5,av]=cn(!1),sd=()=>av(!1),lv=()=>av(!0),$5=({repeatPassword:n,password:l})=>l.length<1?null:l.length<8?h.jsx(wt,{variant:"warning",children:"New password should be at least 8 characters long"}):l!==n?h.jsx(wt,{variant:"warning",children:"Repeat password should match new password"}):null,G5=()=>{const n=K5(),{data:l}=Bn(),{mutateAsync:i,isPending:r}=h4(),u=Et(),[{password:c,repeatPassword:d},{change:m,touched:p,reset:y}]=Rr({password:"",repeatPassword:""}),v=()=>{u("/"),jr.logout().then(()=>{sd()})},x=()=>{i({password:c}).then(()=>{y(),Zt.success("Password successfully updated!")})},E=c.length<8||c!==d||r,C=p.includes("password");return h.jsxs(fn,{isVisible:n,onClose:sd,children:[h.jsx(aa,{onClick:sd}),h.jsxs("div",{className:"w-full lg:w-lg flex flex-col gap-2",children:[h.jsx(Sg,{children:"Account settings"}),h.jsxs("label",{children:[h.jsx("p",{className:"text-xs font-semibold mb-1",children:"Username"}),h.jsx("input",{className:"input w-full",readOnly:!0,disabled:!0,value:l?.username})]}),h.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[h.jsxs("label",{children:[h.jsx("p",{className:"text-xs font-semibold mb-1",children:"Change password"}),h.jsx("input",{className:"input w-full",type:"password",name:"newPassword",autoComplete:"new-password",value:c,onChange:m("password")})]}),h.jsxs("label",{children:[h.jsx("p",{className:"text-xs font-semibold mb-1",children:"Repeat password"}),h.jsx("input",{className:"input w-full",type:"password",value:d,onChange:m("repeatPassword")})]})]}),C&&h.jsx($5,{password:c,repeatPassword:d}),h.jsxs("div",{className:"flex justify-end gap-2 mt-2",children:[h.jsx("button",{className:"button tertiary",disabled:E,onClick:x,children:"Update password"}),h.jsx("button",{className:"button danger",onClick:v,children:"Log out"})]})]})]})},[X5,sv]=cn(!1),iv=()=>sv(!0),e1=()=>sv(!1),F5=n=>Pt({queryKey:["team-users"],queryFn:async()=>{const{data:l}=await je.get("/teams/"+n+"/users");return l.data},enabled:!!n}),Z5=()=>gt({mutationFn:async({role:n,teamId:l,userId:i})=>(await je.patch("/teams/"+l+"/user-role",{role:n,userId:i}),!0),onSuccess:()=>{rt.invalidateQueries({queryKey:["team-users"]})}}),P5=()=>gt({mutationFn:async({teamId:n,userId:l})=>(await je.delete("/teams/"+n,{params:{userId:l}}),!0),onSuccess:()=>{rt.invalidateQueries({queryKey:["team-users"]})}}),J5="_user-entry_1dt1j_2",I5="_select-container_1dt1j_2",t1={userEntry:J5,selectContainer:I5},W5=()=>{const n=X5(),{data:l}=Bn(),{data:i}=F5(l?.teamId),{mutate:r,isPending:u}=m4(),{mutate:c,isPending:d}=Z5(),{mutate:m,isPending:p}=P5(),[y,{change:v,reset:x}]=Rr({password:"",username:""}),E=()=>{r({username:y.username,password:y.password,teamId:l?.teamId||""}),x()},C=(T,_)=>{c({teamId:l.teamId,role:_,userId:T})},w=T=>{wg("Are you sure you want to remove this user?").then(_=>{_&&m({userId:T,teamId:l.teamId})})},j=Ar(Gt.ADMIN),N=u||d||p;return h.jsxs(fn,{isVisible:n,onClose:e1,backdropClose:!0,children:[h.jsx(aa,{onClick:e1}),h.jsxs("div",{className:"w-full lg:w-lg flex flex-col overflow-hidden",children:[h.jsx(Sg,{children:"Manage users"}),hl(i?.length,0)&&h.jsx("div",{className:"mt-4 overflow-y-auto flex-1",children:i.map(T=>h.jsxs("div",{className:t1.userEntry,children:[h.jsx("div",{className:t1.selectContainer,children:h.jsxs("select",{value:T.role,disabled:!j||N,onChange:_=>C(T.id,_.currentTarget.value),children:[h.jsx("option",{value:Gt.OWNER,children:"Owner"}),h.jsx("option",{value:Gt.ADMIN,children:"Admin"}),h.jsx("option",{value:Gt.EDITOR,children:"Editor"}),h.jsx("option",{value:Gt.READ_ONLY,children:"Reader"})]})}),h.jsx("p",{className:"flex-1 mx-2",children:T.name}),j&&h.jsx("button",{className:"p-1 cursor-pointer text-red-500 text-sm",onClick:()=>w(T.id),children:"❌"})]},T.id))}),j&&h.jsxs("div",{className:"mt-4",children:[h.jsx("p",{className:"font-semibold",children:"Create new user"}),h.jsxs("div",{className:"flex flex-col lg:flex-row gap-2 lg:items-center mt-2",children:[h.jsx("input",{className:"input flex-1",onChange:v("username"),value:y.username,placeholder:"Username",disabled:N}),h.jsx("input",{className:"input",onChange:v("password"),value:y.password,type:"password",name:"newPassword",autoComplete:"new-password",placeholder:"Password",disabled:N}),h.jsx("button",{className:"button primary",onClick:E,disabled:N,children:"Create user"})]}),h.jsx("p",{className:"text-xs mt-1 text-gray-600",children:"You should create default password for the new account. The user should change it after the first login."})]})]})]})},eN=()=>{const[n,l]=b.useState(""),[i,r]=b.useState(""),[u,c]=b.useState(),[d,m]=b.useState(!1),p=Et(),y=v=>{v.preventDefault(),c(void 0),jr.login({password:i,username:n}).then(()=>{p("/",{replace:!0})}).catch(c)};return h.jsx("div",{className:"page-container bg-(--bg) h-screen",children:h.jsx("div",{className:"page-content items-center",children:h.jsxs("form",{className:"flex flex-col gap-2 w-full lg:w-lg",onSubmit:y,children:[h.jsx("p",{className:"font-semibold text-xl min-w-md",children:"Login"}),u&&h.jsx(wt,{variant:"danger",children:"Failed to login. Please verify your credentials"}),h.jsx("input",{value:n,onChange:v=>l(v.currentTarget.value),className:"input",placeholder:"User name"}),h.jsx("input",{value:i,onChange:v=>r(v.currentTarget.value),className:"input",type:"password",placeholder:"Password"}),h.jsx("button",{type:"submit",className:"button primary",children:"Login"}),d?h.jsxs(wt,{className:"w-full border border-blue-500",children:[h.jsx("p",{children:"If this is your first login, the default credentials are:"}),h.jsxs("ul",{className:"mt-2",children:[h.jsxs("li",{children:["Username: ",h.jsx("strong",{children:"admin"})]}),h.jsxs("li",{children:["Password: ",h.jsx("strong",{children:"admin"})]})]}),h.jsx("p",{className:"mt-2",children:"Please make sure to change the default password to a secure one."})]}):h.jsx("button",{className:"button tertiary",onClick:()=>m(!0),children:"First login?"})]})})})},tN=()=>{const n=Et(),{pathname:l}=qt(),{data:i,isLoading:r}=hg();b.useEffect(()=>{!i&&!r&&l!==Ye.login.path&&n(Ye.login.path)},[i,r,n,l])},nN=()=>{const[n]=Kx(),l=Et(),i=si(),r=n.get("shareId");return b.useEffect(()=>{r&&i.mutateAsync({queryId:r}).then(u=>{l(`${Ye.workbench.path}/tab/${u.id}`,{replace:!0})})},[r]),h.jsxs("div",{className:"page-container flex items-center justify-center h-screen",children:[i.isPending&&h.jsxs("div",{className:"flex items-center flex-col gap-2",children:[h.jsx(Wg,{}),h.jsx("p",{children:"Fetching query information"})]}),i.isError&&h.jsx(wt,{variant:"danger",children:"Failed to load query information"})]})},aN="_container_14dtx_2",lN="_header_14dtx_2",sN="_close-button_14dtx_2",iN="_tab-container_14dtx_2",rN="_tab-name_14dtx_2",oN="_archived-badge_14dtx_2 _badge_14dtx_2",uN="_active-badge_14dtx_2 _badge_14dtx_2",cN="_action-blue_14dtx_2 _action_14dtx_2",fN="_action-red_14dtx_2 _action_14dtx_2",dN="_load-more-btn_14dtx_2",In={container:aN,header:lN,closeButton:sN,tabContainer:iN,tabName:rN,archivedBadge:oN,activeBadge:uN,actionBlue:cN,actionRed:fN,loadMoreBtn:dN},hN=new Intl.DateTimeFormat,mN=()=>{const{data:n}=Bn(),{data:l,fetchNextPage:i,hasNextPage:r,isFetching:u}=s4(n?.teamId,25),c=Et(),d=vg(),m=B4(),p=x=>{d.mutate(x),Xs({show:!1}),c(`${Ye.workbench.path}/tab/${x}`)},y=x=>{m.mutate(x)},v=l&&l?.length>0;return h.jsxs("div",{className:In.container,children:[h.jsxs("div",{className:In.header,children:[h.jsx("h3",{className:"text-lg",children:"Tabs history"}),h.jsx("button",{className:In.closeButton,onClick:()=>Xs({show:!1}),children:h.jsx(Pl,{width:24,height:24})})]}),!v&&h.jsx(wt,{variant:"warning",children:"History is empty."}),l?.map(x=>h.jsxs("div",{className:In.tabContainer,children:[h.jsxs("div",{className:"flex gap-2 items-center",children:[h.jsx("p",{className:In.tabName,children:x.name}),x.dataSourceType&&h.jsx(ii,{size:16,type:x.dataSourceType}),h.jsx("p",{className:"text-sm",children:x.dataSourceName})]}),h.jsxs("div",{className:"flex gap-2 items-center mt-1",children:[h.jsx("p",{className:"text-sm italic",children:hN.format(new Date(x.updatedAt))}),x.archived?h.jsx("span",{className:In.archivedBadge,children:"Archived"}):h.jsx("span",{className:In.activeBadge,children:"Active"}),h.jsx("span",{className:"flex-1"}),h.jsx("button",{onClick:()=>p(x.id),className:In.actionBlue,children:"Open"}),h.jsx("button",{onClick:()=>y(x.id),className:In.actionRed,children:"Delete"})]})]},x.id)),r&&!u&&h.jsx("div",{className:"flex justify-center my-2",children:h.jsx("button",{className:In.loadMoreBtn,onClick:()=>i(),children:"Load more"})})]})},pN=()=>{const n=fE(l=>l.show);return h.jsx(tv,{isVisible:n,onClose:()=>Xs({show:!1}),backdropClose:!0,children:h.jsx(mN,{})})};function yN(){return Y5(),V5(),tN(),h.jsxs(h.Fragment,{children:[h.jsxs(mx,{children:[h.jsx(dr,{path:Ye.home.path,element:h.jsx(gE,{})}),h.jsx(dr,{path:`${Ye.workbench.path}/tab/:id`,element:h.jsx(n5,{})}),h.jsx(dr,{path:Ye.login.path,element:h.jsx(eN,{})}),h.jsx(dr,{path:Ye.share.path,element:h.jsx(nN,{})})]}),h.jsx(OE,{}),h.jsx(QE,{}),h.jsx(e6,{}),h.jsx(j5,{}),h.jsx(Q5,{}),h.jsx(G5,{}),h.jsx(W5,{}),h.jsx(pN,{}),h.jsx(ZE,{}),h.jsx(KE,{})]})}const gN="_desktop-layout_zjyhz_2",vN="_mobile-layout_zjyhz_2",bN="_nav_zjyhz_2",xN="_main_zjyhz_2",SN="_header_zjyhz_2",Ps={desktopLayout:gN,mobileLayout:vN,nav:bN,main:xN,header:SN},wN="_container_111rk_2",EN="_menu_111rk_2",uh={container:wN,menu:EN},CN=({name:n,id:l,onRename:i,onDelete:r,onOpen:u})=>{const c=Ng();return h.jsxs("button",{className:uh.menu,onContextMenu:c.open,onClick:()=>u(l),children:[h.jsx(jg,{handler:c,children:h.jsxs("div",{className:"context-menu-container",children:[h.jsx("button",{onClick:d=>{d.preventDefault(),d.stopPropagation(),c.close(),i(l)},className:"context-menu-item",children:"✏️ Rename"}),h.jsx("button",{onClick:d=>{d.preventDefault(),d.stopPropagation(),c.close(),r(l)},className:"context-menu-item",children:"🗑️ Delete"})]})}),h.jsxs("span",{children:["📖 ",n]})]})},_N=({dataSource:n,index:l})=>{const i=()=>{Gs(n.id)};return un(l.toString(),()=>{Gs(r=>{if(r!==n.id)return n.id})}),h.jsxs("button",{className:uh.menu,onClick:i,children:[h.jsx(ii,{size:20,type:n.dbType}),h.jsx("p",{className:"truncate flex-1 text-left mx-1.5",children:n.name}),h.jsx("span",{className:"hotkey",children:l})]})},NN=()=>{const n=Et(),{data:l}=Bn(),{data:i}=t4(l?.teamId),{data:r}=n4(l?.teamId),u=si(),c=P6(),d=Z6(),m=v=>{u.mutateAsync({queryId:v}).then(x=>{n(`${Ye.workbench.path}/tab/${x.id}`)})},p=async v=>{const x=r?.find(C=>C.id===v);if(!x)return;const E=await Or("New name?",x?.name);E&&c.mutate({id:x.savedQueryId,payload:{name:E}})},y=v=>{const x=r?.find(E=>E.id===v)?.savedQueryId;x&&d.mutate(x)};return h.jsx("div",{className:uh.container,children:h.jsxs("div",{className:"flex-1 overflow-y-auto",children:[hl(i?.length,0)&&h.jsxs("div",{className:"mt-4",children:[h.jsx("p",{className:"font-semibold text-sm text-gray-600 mb-2",children:"DATA SOURCES"}),i.map((v,x)=>h.jsx(_N,{dataSource:v,index:x+1},v.id))]}),hl(r?.length,0)&&h.jsxs("div",{className:"mt-4",children:[h.jsx("p",{className:"font-semibold text-sm text-gray-600 mb-2",children:"SAVED QUERIES"}),r.map(v=>h.jsx(CN,{onDelete:y,onRename:p,onOpen:m,name:v.name,id:v.id},v.savedQueryId))]})]})})},jN=()=>{const n=Et(),{pathname:l}=qt(),{data:i}=Bn(),r=Tr("Desktop nav"),u=()=>{ev(),l!==Ye.home.path&&n(Ye.home.path)},c=()=>Xs({show:!0});return h.jsxs("nav",{className:Ps.nav,children:[i&&h.jsxs("div",{className:Ps.header,children:[h.jsx("button",{onClick:u,className:"flex justify-between items-center",children:h.jsx("span",{children:"🏠 Home"})}),h.jsxs("button",{onClick:r,className:"flex justify-between items-center",children:[h.jsx("span",{children:"🔎 New query"}),h.jsx("span",{className:"hotkey",children:"N"})]}),h.jsxs("button",{onClick:c,className:"flex justify-between items-center",children:[h.jsx("span",{children:"⌛ Recent tabs"}),h.jsx("span",{className:"hotkey",children:"H"})]}),h.jsxs("button",{onClick:lv,children:["🪪 ",i.username]}),h.jsx("button",{onClick:iv,children:"👥 Manage users"})]}),h.jsx(NN,{})]})},TN="_root_x5xkr_2",AN={root:TN},RN=()=>{const{pathname:n}=qt(),l=Et(),i=Tr("Mobile nav"),r=()=>{n!==Ye.home.path&&l(Ye.home.path)};return h.jsxs("div",{className:AN.root,children:[h.jsxs("button",{onClick:r,children:[h.jsx("p",{children:"🏠"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Home"})]}),h.jsxs("button",{onClick:i,children:[h.jsx("p",{children:"🔎"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"New query"})]}),h.jsxs("button",{onClick:lv,children:[h.jsx("p",{children:"🪪"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Account"})]}),h.jsxs("button",{onClick:iv,children:[h.jsx("p",{children:"👥"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Users"})]})]})},ON=({children:n,isLogin:l})=>h.jsxs("div",{className:Ps.desktopLayout,children:[h.jsx(gu,{id:"default",className:"z-100"}),h.jsx(gu,{id:"default-xs",className:"z-100 text-xs!"}),!l&&h.jsx(jN,{}),h.jsx("main",{className:Ps.main,children:n})]}),DN=({children:n,isLogin:l})=>h.jsxs("div",{className:Ps.mobileLayout,children:[h.jsx("main",{className:Ps.main,children:n}),!l&&h.jsx(RN,{})]}),MN=({children:n})=>{const l=Cg(eh.laptop),{pathname:i}=qt(),r=i===Ye.login.path;return l?h.jsx(ON,{isLogin:r,children:n}):h.jsx(DN,{isLogin:r,children:n})};w2.createRoot(document.getElementById("root")).render(h.jsxs(rl.StrictMode,{children:[h.jsx(I3,{}),h.jsx(xS,{client:rt,children:h.jsx(Bx,{children:h.jsx(MN,{children:h.jsx(yN,{})})})})]}));
193
+ .styles-module_tooltip__mnnfp{padding:8px 16px;border-radius:3px;font-size:90%;width:max-content}.styles-module_arrow__K0L3T{width:var(--rt-arrow-size);height:var(--rt-arrow-size)}[class*='react-tooltip__place-top']>.styles-module_arrow__K0L3T{transform:rotate(45deg)}[class*='react-tooltip__place-right']>.styles-module_arrow__K0L3T{transform:rotate(135deg)}[class*='react-tooltip__place-bottom']>.styles-module_arrow__K0L3T{transform:rotate(225deg)}[class*='react-tooltip__place-left']>.styles-module_arrow__K0L3T{transform:rotate(315deg)}.styles-module_dark__xNqje{background:var(--rt-color-dark);color:var(--rt-color-white)}.styles-module_light__Z6W-X{background-color:var(--rt-color-white);color:var(--rt-color-dark)}.styles-module_success__A2AKt{background-color:var(--rt-color-success);color:var(--rt-color-white)}.styles-module_warning__SCK0X{background-color:var(--rt-color-warning);color:var(--rt-color-white)}.styles-module_error__JvumD{background-color:var(--rt-color-error);color:var(--rt-color-white)}.styles-module_info__BWdHW{background-color:var(--rt-color-info);color:var(--rt-color-white)}`,type:"base"})});const vr=n=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},b.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:48,d:"M184 112l144 144-144 144"})),Qg=n=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},b.createElement("path",{d:"M320 146s24.36-12-64-12a160 160 0 10160 160",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeMiterlimit:10,strokeWidth:32}),b.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32,d:"M256 58l80 80-80 80"})),Yg=n=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},b.createElement("rect",{x:128,y:128,width:336,height:336,rx:57,ry:57,fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:32}),b.createElement("path",{d:"M383.5 128l.5-24a56.16 56.16 0 00-56-56H112a64.19 64.19 0 00-64 64v216a56.16 56.16 0 0056 56h24M296 216v160M376 296H216",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32})),VC=n=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},b.createElement("circle",{cx:128,cy:256,r:48,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32}),b.createElement("circle",{cx:384,cy:112,r:48,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32}),b.createElement("circle",{cx:384,cy:400,r:48,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32}),b.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32,d:"M169.83 279.53l172.34 96.94M342.17 135.53l-172.34 96.94"})),KC=()=>{const n=Id(),l=k4();return{rename:async r=>{if(n){const u=await Or("New tab name",r);u&&await l.mutateAsync({id:n,payload:{name:u}})}return Promise.resolve()}}},Vg=["shift","alt","meta","mod","ctrl","control"],$C={esc:"escape",return:"enter",left:"arrowleft",right:"arrowright",up:"arrowup",down:"arrowdown",ShiftLeft:"shift",ShiftRight:"shift",AltLeft:"alt",AltRight:"alt",MetaLeft:"meta",MetaRight:"meta",OSLeft:"meta",OSRight:"meta",ControlLeft:"ctrl",ControlRight:"ctrl"};function fl(n){return($C[n.trim()]||n.trim()).toLowerCase().replace(/key|digit|numpad/,"")}function Kg(n){return Vg.includes(n)}function nd(n,l=","){return n.toLowerCase().split(l)}function ad(n,l="+",i=">",r=!1,u){let c=[],d=!1;n=n.trim(),n.includes(i)?(d=!0,c=n.toLocaleLowerCase().split(i).map(y=>fl(y))):c=n.toLocaleLowerCase().split(l).map(y=>fl(y));const m={alt:c.includes("alt"),ctrl:c.includes("ctrl")||c.includes("control"),shift:c.includes("shift"),meta:c.includes("meta"),mod:c.includes("mod"),useKey:r},p=c.filter(y=>!Vg.includes(y));return{...m,keys:p,description:u,isSequence:d,hotkey:n}}typeof document<"u"&&(document.addEventListener("keydown",n=>{n.code!==void 0&&$g([fl(n.code)])}),document.addEventListener("keyup",n=>{n.code!==void 0&&Gg([fl(n.code)])})),typeof window<"u"&&(window.addEventListener("blur",()=>{Na.clear()}),window.addEventListener("contextmenu",()=>{setTimeout(()=>{Na.clear()},0)}));const Na=new Set;function oh(n){return Array.isArray(n)}function GC(n,l=","){return(oh(n)?n:n.split(l)).every(i=>Na.has(i.trim().toLowerCase()))}function $g(n){const l=Array.isArray(n)?n:[n];Na.has("meta")&&Na.forEach(i=>!Kg(i)&&Na.delete(i.toLowerCase())),l.forEach(i=>Na.add(i.toLowerCase()))}function Gg(n){const l=Array.isArray(n)?n:[n];n==="meta"?Na.clear():l.forEach(i=>Na.delete(i.toLowerCase()))}function XC(n,l,i){(typeof i=="function"&&i(n,l)||i===!0)&&n.preventDefault()}function FC(n,l,i){return typeof i=="function"?i(n,l):i===!0||i===void 0}const ZC=["input","textarea","select","searchbox","slider","spinbutton","menuitem","menuitemcheckbox","menuitemradio","option","radio","textbox"];function PC(n){return Xg(n,ZC)}function Xg(n,l=!1){const{target:i,composed:r}=n;let u,c;return JC(i)&&r?(u=n.composedPath()[0]&&n.composedPath()[0].tagName,c=n.composedPath()[0]&&n.composedPath()[0].role):(u=i&&i.tagName,c=i&&i.role),oh(l)?!!(u&&l&&l.some(d=>d.toLowerCase()===u.toLowerCase()||d===c)):!!(u&&l&&l)}function JC(n){return!!n.tagName&&!n.tagName.startsWith("-")&&n.tagName.includes("-")}function IC(n,l){return n.length===0&&l?(console.warn('A hotkey has the "scopes" option set, however no active scopes were found. If you want to use the global scopes feature, you need to wrap your app in a <HotkeysProvider>'),!0):l?n.some(i=>l.includes(i))||n.includes("*"):!0}const WC=(n,l,i=!1)=>{const{alt:r,meta:u,mod:c,shift:d,ctrl:m,keys:p,useKey:y}=l,{code:v,key:x,ctrlKey:E,metaKey:C,shiftKey:w,altKey:j}=n,N=fl(v);if(y&&p?.length===1&&p.includes(x))return!0;if(!p?.includes(N)&&!["ctrl","control","unknown","meta","alt","shift","os"].includes(N))return!1;if(!i){if(r!==j&&N!=="alt"||d!==w&&N!=="shift")return!1;if(c){if(!C&&!E)return!1}else if(u!==C&&N!=="meta"&&N!=="os"||m!==E&&N!=="ctrl"&&N!=="control")return!1}return p&&p.length===1&&p.includes(N)?!0:p?GC(p):!p},e_=b.createContext(void 0),t_=()=>b.useContext(e_);function Fg(n,l){return n&&l&&typeof n=="object"&&typeof l=="object"?Object.keys(n).length===Object.keys(l).length&&Object.keys(n).reduce((i,r)=>i&&Fg(n[r],l[r]),!0):n===l}const n_=b.createContext({hotkeys:[],activeScopes:[],toggleScope:()=>{},enableScope:()=>{},disableScope:()=>{}}),a_=()=>b.useContext(n_);function l_(n){const l=b.useRef(void 0);return Fg(l.current,n)||(l.current=n),l.current}const Fy=n=>{n.stopPropagation(),n.preventDefault(),n.stopImmediatePropagation()},s_=typeof window<"u"?b.useLayoutEffect:b.useEffect;function un(n,l,i,r){const u=b.useRef(null),c=b.useRef(!1),d=Array.isArray(i)?Array.isArray(r)?void 0:r:i,m=oh(n)?n.join(d?.delimiter):n,p=Array.isArray(i)?i:Array.isArray(r)?r:void 0,y=b.useCallback(l,p??[]),v=b.useRef(y);p?v.current=y:v.current=l;const x=l_(d),{activeScopes:E}=a_(),C=t_();return s_(()=>{if(x?.enabled===!1||!IC(E,x?.scopes))return;let w=[],j;const N=(H,G=!1)=>{if(!(PC(H)&&!Xg(H,x?.enableOnFormTags))){if(u.current!==null){const Y=u.current.getRootNode();if((Y instanceof Document||Y instanceof ShadowRoot)&&Y.activeElement!==u.current&&!u.current.contains(Y.activeElement)){Fy(H);return}}H.target?.isContentEditable&&!x?.enableOnContentEditable||nd(m,x?.delimiter).forEach(Y=>{if(Y.includes(x?.splitKey??"+")&&Y.includes(x?.sequenceSplitKey??">")){console.warn(`Hotkey ${Y} contains both ${x?.splitKey??"+"} and ${x?.sequenceSplitKey??">"} which is not supported.`);return}const K=ad(Y,x?.splitKey,x?.sequenceSplitKey,x?.useKey,x?.description);if(K.isSequence){j=setTimeout(()=>{w=[]},x?.sequenceTimeoutMs??1e3);const Z=K.useKey?H.key:fl(H.code);if(Kg(Z.toLowerCase()))return;w.push(Z);const te=K.keys?.[w.length-1];if(Z!==te){w=[],j&&clearTimeout(j);return}w.length===K.keys?.length&&(v.current(H,K),j&&clearTimeout(j),w=[])}else if(WC(H,K,x?.ignoreModifiers)||K.keys?.includes("*")){if(x?.ignoreEventWhen?.(H)||G&&c.current)return;if(XC(H,K,x?.preventDefault),!FC(H,K,x?.enabled)){Fy(H);return}v.current(H,K),G||(c.current=!0)}})}},T=H=>{H.code!==void 0&&($g(fl(H.code)),(x?.keydown===void 0&&x?.keyup!==!0||x?.keydown)&&N(H))},_=H=>{H.code!==void 0&&(Gg(fl(H.code)),c.current=!1,x?.keyup&&N(H,!0))},O=u.current||d?.document||document;return O.addEventListener("keyup",_,d?.eventListenerOptions),O.addEventListener("keydown",T,d?.eventListenerOptions),C&&nd(m,x?.delimiter).forEach(H=>C.addHotkey(ad(H,x?.splitKey,x?.sequenceSplitKey,x?.useKey,x?.description))),()=>{O.removeEventListener("keyup",_,d?.eventListenerOptions),O.removeEventListener("keydown",T,d?.eventListenerOptions),C&&nd(m,x?.delimiter).forEach(H=>C.removeHotkey(ad(H,x?.splitKey,x?.sequenceSplitKey,x?.useKey,x?.description))),w=[],j&&clearTimeout(j)}},[m,x,E]),u}function i_(){return h.jsxs("div",{className:"flex items-center bg-white border-b border-gray-200 overflow-auto no-scrollbar",children:[h.jsx(r_,{}),h.jsx(u_,{})]})}function r_(){const{dataSourceId:n,name:l}=b.useContext(gl),{data:i}=Nu(n),{data:r}=b.useContext(Ra),u=Ar(Gt.EDITOR),c=F6(),{rename:d}=KC(),m=()=>{r?.result.columns?.[0].table&&Pd({table:r?.result.columns?.[0].table,dataSourceId:n})},p=async()=>{const v=await Or("Query name",l);!v||!r?.result.queryHistoryId||c.mutate({name:v,queryId:r.result.queryHistoryId})},y=()=>d(l);return un("s",p),un("r",y),h.jsxs("div",{className:se.tableConfig,children:[h.jsx("button",{"data-tooltip-id":"default","data-tooltip-content":"Rename tab",onClick:y,className:re(se.tableAction,se.blue,"block"),children:h.jsxs("span",{className:se.tabName,children:["🛠️ ",l]})}),h.jsxs("button",{"data-tooltip-id":"explorer-more-actions",className:re(se.tableAction,se.blue),children:[h.jsx("span",{className:"whitespace-nowrap",children:"Options"}),h.jsx(vr,{width:16,height:16,className:"rotate-90"})]}),h.jsxs(gu,{id:"explorer-more-actions",className:"z-10 shadow-md flex flex-col",clickable:!0,variant:"light",opacity:1,children:[h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Manage filters",onClick:()=>Ln("filters"),className:re(se.tableAction,se.modal,se.blue),children:[h.jsx("span",{children:"Filters"}),h.jsx("span",{className:"hotkey",children:"F"})]}),h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Join tables",onClick:()=>Ln("joins"),className:re(se.tableAction,se.modal,se.blue),children:[h.jsx("span",{children:"Joins"}),h.jsx("span",{className:"hotkey",children:"J"})]}),h.jsxs("button",{onClick:()=>Ln("columns"),className:re(se.tableAction,se.modal,se.blue,"justify-between"),children:[h.jsx("span",{children:"Columns"}),h.jsx("span",{className:"hotkey",children:"C"})]}),h.jsxs("button",{onClick:()=>Ln("groupBy"),className:re(se.tableAction,se.modal,se.blue,"justify-between"),children:[h.jsx("span",{children:"Group by"}),h.jsx("span",{className:"hotkey",children:"G"})]}),h.jsxs("button",{onClick:()=>Ln("aggregate"),className:re(se.tableAction,se.modal,se.blue,"justify-between"),children:[h.jsx("span",{children:"Aggregate"}),h.jsx("span",{className:"hotkey",children:"A"})]}),u&&h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"h-0.5 my-2 bg-gray-100"}),h.jsxs("button",{onClick:p,className:re(se.tableAction,se.modal,se.blue),children:[h.jsx("span",{children:"Save query"}),h.jsx("span",{className:"hotkey",children:"S"})]}),i?.allowInsert===!0&&h.jsx("button",{onClick:m,className:re(se.tableAction,se.modal,se.blue),children:"Insert new row"})]})]})]})}const o_=[5,10,20,50,100,200];function u_(){const{page:n,size:l,setPage:i,setSize:r}=X6(),{data:u,refetch:c,isFetching:d}=b.useContext(Ra),{name:m}=b.useContext(gl),{state:p}=b.useContext(Jt),y=si(),v=Et(),x=()=>{y.mutateAsync({name:m,opts:p}).then(_=>{v(`${Ye.workbench.path}/tab/${_.id}`)})},E=()=>{if(u?.result.queryHistoryId){const _=new URL(window.location.href);_.pathname=Ye.share.path,_.searchParams.set("shareId",u.result.queryHistoryId),navigator.clipboard.writeText(_.toString()),Zt.success("Share link copied to clipboard")}};un("d",x);const C=n*l,w=!d&&!!u?.result.hasMore,j=u?.result.rows.length||0,N=()=>{n>0&&i(n-1)},T=()=>{w&&i(n+1)};return h.jsxs("div",{className:se.tableConfig,children:[h.jsxs("span",{"data-tooltip-id":"rows-num",className:se.paginationIndicator,children:[C+1," - ",C+j,w&&"+"]}),h.jsx("span",{"data-tooltip-content":"Previous page","data-tooltip-id":"default",className:re(se.tableAction,se.blue,n<1&&"opacity-30"),onClick:N,role:"button",children:h.jsx(vr,{width:16,height:16,className:"rotate-180"})}),h.jsx("span",{"data-tooltip-content":"Next page","data-tooltip-id":"default",className:re(se.tableAction,w?se.blue:"opacity-30"),onClick:T,role:"button",children:h.jsx(vr,{width:16,height:16})}),h.jsx("span",{"data-tooltip-content":"Refresh data","data-tooltip-id":"default",className:re(se.tableAction,se.blue),onClick:()=>c(),role:"button",children:h.jsx(Qg,{width:16,height:16})}),h.jsx("span",{"data-tooltip-content":"Share query","data-tooltip-id":"default",className:re(se.tableAction,se.blue),onClick:E,role:"button",children:h.jsx(VC,{width:16,height:16})}),h.jsx("span",{"data-tooltip-content":"Duplicate tab","data-tooltip-id":"default",className:re(se.tableAction,se.blue),onClick:x,role:"button",children:h.jsx(Yg,{width:16,height:16})}),h.jsx(gu,{id:"rows-num",className:"z-10 shadow-md flex gap-1",clickable:!0,variant:"light",opacity:1,children:o_.map(_=>h.jsx("button",{onClick:()=>r(_,!0),className:re(se.tableAction,se.blue,_===l&&se.selectedSize),children:h.jsx("span",{children:_})},_))})]})}const c_="_drop-container_ee5e3_2",f_="_item_ee5e3_2",Zy={dropContainer:c_,item:f_},Td=({dataSourceId:n,focusId:l,placeholder:i="Column",onChange:r,value:u,autoFocus:c,allowTables:d})=>{const{data:m}=ai(n),p=b.useRef(null),y=b.useMemo(()=>{if(!m)return[];let T=m;return d&&(T=m.filter(_=>d.includes(_.tableName))),T.flatMap(_=>_.columns.map(O=>({value:_.tableName+"."+O.name,label:O.name,table:_.tableName,searchValue:O.name.toLowerCase()})))},[m,d]),v=b.useMemo(()=>{const T=u.toLowerCase()||"",_=[];for(let O=0;O<y.length&&_.length<10;O++)y[O].searchValue.includes(T)&&_.push(y[O]);return _},[y,u]),[x,E]=b.useState(!1),[C,w]=b.useState(0),j=T=>{if(T.key==="ArrowDown")T.preventDefault(),w(_=>(_+1)%v.length);else if(T.key==="ArrowUp")T.preventDefault(),w(_=>(_-1+v.length)%v.length);else if(T.key==="Enter"&&C>=0&&C<v.length){T.preventDefault();const _=v[C].value;E(!1);const O=y.findIndex(H=>H.value===_)>-1;r(v[C]?.value||_,O,!0)}};b.useEffect(()=>{const T=p.current?.querySelector('[data-is-active="true"]');T&&T.scrollIntoView({behavior:"smooth",block:"nearest"})},[C]);const N=T=>{const _=T.currentTarget.value,O=y.findIndex(H=>H.value===_)>-1;r(_,O,!1)};return h.jsxs("div",{className:"relative",onFocus:()=>E(!0),onBlur:()=>E(!1),children:[h.jsx("input",{autoFocus:c,onKeyDown:j,value:u,onChange:N,className:"input w-full",placeholder:i,"data-focus":l}),x&&v.length>0&&h.jsx("div",{className:Zy.dropContainer,ref:p,tabIndex:-1,children:v.map((T,_)=>h.jsxs("div",{className:Zy.item,"data-is-active":C===_,onMouseDownCapture:O=>{O.preventDefault(),E(!1),r(T.value,!0,!0)},children:[h.jsx("span",{className:"text-xs font-semibold truncate",children:T.table}),h.jsx("p",{className:"truncate text-sm",children:T.label})]},_))})]})},d_="_drop-container_1rgb9_2",h_="_item_1rgb9_2",Py={dropContainer:d_,item:h_};function m_(n){return j4.includes(n)?C4:T4.includes(n)?E4:A4.includes(n)?_4:Gd}const p_=({value:n,onChange:l,autoFocus:i,focusId:r,colType:u})=>{const c=b.useMemo(()=>{const E=n.toLowerCase()||"";return m_(u||"").filter(C=>C.label.includes(E))},[n,u]),d=b.useRef(null),[m,p]=b.useState(!1),[y,v]=b.useState(0),x=E=>{E.key==="ArrowDown"?(E.preventDefault(),v(C=>(C+1)%c.length)):E.key==="ArrowUp"?(E.preventDefault(),v(C=>(C-1+c.length)%c.length)):E.key==="Enter"&&(y>=0&&y<c.length?(E.preventDefault(),p(!1),l(c[y]?.label||"",!0)):l(n,!0))};return b.useEffect(()=>{const E=d.current?.querySelector('[data-is-active="true"]');E&&E.scrollIntoView({behavior:"smooth",block:"nearest"})},[y]),h.jsxs("div",{className:"relative",children:[h.jsx("input",{onKeyDown:x,value:n,onChange:E=>l(E.target.value,!1),className:"input w-full",placeholder:"Operator",autoFocus:i,onFocus:()=>p(!0),onBlur:()=>p(!1),"data-focus":r}),m&&c.length>0&&h.jsx("ul",{className:Py.dropContainer,ref:d,tabIndex:-1,children:c.map((E,C)=>h.jsx("li",{className:Py.item,"data-is-active":y===C,onMouseDownCapture:w=>{w.preventDefault(),p(!1),l(E.label,!0)},children:E.label},C))})]})},Zg=()=>{const{state:n,setState:l}=b.useContext(Jt),i=b.useCallback((u,c=!1)=>{l(d=>({...d,page:c?0:d.page,filters:u}))},[l]),r=b.useCallback(u=>{l(c=>({...c,filters:c.filters.filter(d=>d.id!==u)}))},[l]);return{filters:n.filters,removeFilter:r,setFilters:i}},y_="_actions_4u23n_2",g_="_filter-actions_4u23n_2",Pg={actions:y_,filterActions:g_},v_=["=","<",">",">=","<>","!=","<="];function b_(n){for(let l=0;l<n.length;l++){const i=n[l];if(!i.operator.length&&!i.value.length&&!i.column.length)continue;if(!i.column.includes("."))return Zt.error(`Filter #${l+1} has invalid column value`),!1;const r=Xd[i.operator];if(!r)return Zt.error(`Filter #${l+1} has invalid operator`),!1;if(i.isColumnRef&&!v_.includes(r))return Zt.error(`Filter #${l+1} cannot reference another column because it uses '${i.operator}' operator`),!1}return!0}function x_(n){const l=[];return n.forEach(i=>{if(!i.operator.length||!i.column.length||i.operator!=="is null"&&i.operator!=="is not null"&&!i.value.length)return;const r=Xd[i.operator];l.push({id:i.id,value:i.isColumnRef?[{value:i.value,isColumn:!0}]:N4(r,i.value),operator:r,column:i.column,isEnabled:i.isEnabled,connector:"AND"})}),l}function S_(n){let l="";if(n.value)for(let i=0;i<n.value.length;i++)l+=n.value[i].value,i<n.value.length-1&&(l+=", ");return l}const w_=({filter:n,dataSourceId:l,allowedTables:i,inspections:r,autoFocus:u,onChangeColumn:c,onChangeOperator:d,onChangeValue:m,onRemoveFilter:p,triggerIsEnabled:y,onIsColumnChange:v})=>{const x=b.useMemo(()=>{if(!r)return"";let E=null;for(const C of r)for(const w of C.columns)C.tableName+"."+w.name===n.column&&(E=w);return E?.type?E.type:""},[n.column,r]);return h.jsxs("div",{className:"flex gap-2 items-center",children:[h.jsx("label",{children:h.jsx("input",{type:"checkbox",checked:n.isEnabled!==!1,onClick:()=>y(n.id)})}),h.jsx("label",{className:"w-full",children:h.jsx(Td,{dataSourceId:l,onChange:E=>c(n.id,E),value:n.column,allowTables:i,focusId:"column",autoFocus:u})}),h.jsx("label",{children:h.jsx(p_,{onChange:E=>d(n.id,E),focusId:"operator",colType:x,value:n.operator})}),yg(Xd[n.operator])&&h.jsx("label",{className:"w-full",children:n.isColumnRef?h.jsx(Td,{dataSourceId:l,onChange:E=>m(n.id,E),value:n.value,allowTables:i,focusId:"value",placeholder:"Search column"}):h.jsx("input",{className:"input w-full",placeholder:"Filter value",value:n.value,onChange:E=>m(n.id,E.currentTarget.value),"data-focus":"value"})}),h.jsxs("div",{className:Pg.filterActions,children:[h.jsx("button",{tabIndex:-1,"data-tooltip-id":"default","data-tooltip-content":"If enabled, the value will reference another column instead of being raw string",className:re("p-0.5 cursor-pointer rounded-lg border",n.isColumnRef?"bg-blue-50 border-blue-200":"bg-white border-white"),onClick:()=>v(n.id,!n.isColumnRef),children:"🏷️"}),h.jsx("button",{tabIndex:-1,"data-tooltip-id":"default","data-tooltip-content":"Remove filter",className:"p-0.5 text-sm cursor-pointer",onClick:()=>p(n.id),children:h.jsx(Pl,{width:20,height:20,className:"text-red-600"})})]})]})},E_=()=>{const{state:n}=b.useContext(Jt),{setFilters:l}=Zg(),i=ju(N=>N.filters),{data:r}=ai(n.dataSourceId),u=b.useMemo(()=>[n.table,...n.joins.map(N=>N.table)],[n.table,n.joins]),[c,d]=b.useState([]),m=(N,T)=>{d(_=>[..._.map(O=>O.id===N?{...O,column:T}:O)])},p=(N,T)=>{d(_=>[..._.map(O=>O.id===N?{...O,operator:T}:O)])},y=(N,T)=>{d(_=>[..._.map(O=>O.id===N?{...O,value:T}:O)])},v=()=>{d(N=>[...N,{id:dl(),value:"",column:"",operator:"",isColumnRef:!1,isEnabled:!0}])},x=(N,T)=>{d(_=>[..._.map(O=>O.id===N?{...O,isColumnRef:T}:O)])},E=N=>{d(T=>T.filter(_=>_.id!==N))},C=()=>Tu("filters"),w=()=>{b_(c)&&(l(x_(c)),C())},j=N=>{d(T=>T.map(_=>_.id===N?{..._,isEnabled:!_.isEnabled}:_))};return b.useEffect(()=>{i&&d(()=>{const N=n.filters.map(T=>({id:T.id,value:S_(T),column:T.column,operator:pg[T.operator],isColumnRef:!!T.value?.[0]?.isColumn,isEnabled:T.isEnabled}));return N.push({id:dl(),value:"",column:"",operator:"",isColumnRef:!1,isEnabled:!0}),N})},[i]),un("f",()=>{hu("filters")}),un("ctrl+f",()=>{alert("Save filters")}),h.jsxs(fn,{isVisible:i,onClose:C,portal:!0,onClosed:()=>d([]),children:[h.jsx(aa,{onClick:C}),h.jsx("h2",{className:"text-lg font-semibold",children:"Filters"}),h.jsxs("div",{className:"flex gap-4 flex-col w-full lg:w-lg my-4",children:[c.length<1&&h.jsx("p",{className:"p-1 text-center rounded-lg bg-gray-50 border border-gray-200",children:"No filters"}),c.map((N,T)=>h.jsx(w_,{filter:N,dataSourceId:n.dataSourceId,allowedTables:u,inspections:r||[],onChangeColumn:m,onChangeOperator:p,onChangeValue:y,onRemoveFilter:E,onIsColumnChange:x,triggerIsEnabled:j,autoFocus:T===c.length-1},N.id))]}),h.jsxs("div",{className:Pg.actions,children:[h.jsx("button",{className:"button tertiary",onClick:v,children:"Add filter"}),h.jsx("button",{className:"button primary",onClick:w,children:"Apply filters"})]})]})},C_="_join-modal_zzevr_2",__={joinModal:C_},N_=(n,l)=>n.type!==l.type||n.on!==l.on||n.table!==l.table,j_=(n,l)=>n.type===l.type&&n.on===l.on&&n.table===l.table,Jg=()=>{const{state:n,setState:l}=b.useContext(Jt),i=b.useCallback(r=>{l(u=>{const c=u.joins;if(c.some(m=>j_(m,r))){const m=r.table+".";return{...u,joins:c.filter(p=>N_(p,r)),columns:u.columns.filter(p=>!p.value.startsWith(m)),groupBy:u.groupBy.filter(p=>!p.value.startsWith(m)),orderBy:u.orderBy.filter(p=>!p.column.startsWith(m)),aggregations:u.aggregations.filter(p=>!p.value.startsWith(m)),filters:u.filters.filter(p=>!p.column.startsWith(m))}}return{...u,joins:[...c,r]}})},[l]);return{joins:n.joins,toggle:i}},T_=()=>{const{isFetching:n}=b.useContext(Ra),l=ju(p=>p.joins),{toggle:i}=Jg(),{availableJoins:r}=b.useContext(gl),[u,c]=b.useState(""),d=b.useMemo(()=>{const p=u.toLowerCase();return r.filter(y=>y.on.toTable.toLowerCase().includes(p))},[r,u]),m=()=>Tu("joins");return un("j",()=>{r.length>0?Ln("joins"):Zt.error("No available tables to join")}),h.jsxs(fn,{isVisible:l,onClose:m,portal:!0,children:[h.jsx(aa,{onClick:m}),h.jsxs("div",{className:__.joinModal,children:[h.jsx("h2",{className:"text-lg font-semibold mb-4",children:"Join table"}),r.length>0?h.jsx("input",{className:"input w-full",placeholder:"Filter",autoFocus:!0,onChange:p=>c(p.target.value),value:u,disabled:n}):h.jsx(wt,{variant:"warning",children:h.jsx("p",{className:"text-sm truncate",children:"There is nothing else to join"})}),h.jsx("div",{className:`flex flex-col mt-2 overflow-y-auto ${n?"opacity-40":""}`,children:d.map(p=>h.jsx(Tg,{hook:p,onClick:()=>{n||(i({table:p.on.toTable,type:"LEFT",on:p.where}),c(""),m())}},p.where))})]})]})};function A_(n){return n.reduce((l,i)=>(l[i]=!0,l),{})}function Jy(n){return n.reduce((l,i)=>(l[i]=!0,l),{})}const R_="_container_1a3k0_2",O_="_column-label_1a3k0_2",D_="_not-active_1a3k0_2",iu={container:R_,columnLabel:O_,notActive:D_};function M_(n){if(!n)return[];const l={};return n.forEach(i=>{l[i.table]?l[i.table].push({value:i.full,ogColumn:i.column,label:ol(i.column),type:i.type}):l[i.table]=[{value:i.full,ogColumn:i.column,label:ol(i.column),type:i.type}],R4[i.type]&&["YEAR","MONTH","DAY"].forEach(r=>{l[i.table].push({value:r+" "+i.full,ogColumn:i.column,label:r+" "+ol(i.column),type:"number",nested:!0})})}),Object.entries(l).reduce((i,[r,u])=>(i.push({name:ol(r),columns:u}),i),[])}function L_(n,l){const i=l.toLowerCase();return n.map(r=>{const u=r.columns.filter(c=>c.label.toLowerCase().includes(i)||c.ogColumn.toLowerCase().includes(i));return{...r,columns:u}}).filter(r=>r.columns.length>0)}const U_=({column:n,selected:l,onCheck:i})=>h.jsxs("label",{className:re(iu.columnLabel,l?iu.active:iu.notActive,n.nested&&"pl-5!"),children:[h.jsx("input",{type:"checkbox",checked:l[n.value],name:n.value,onChange:i}),h.jsxs("p",{className:"flex justify-between w-full",children:[h.jsx("span",{"data-tooltip-content":n.value,"data-tooltip-id":"default",children:n.label}),h.jsx("span",{className:"text-blue-600",children:n.type})]})]},n.value),z_={columns:"c",groupBy:"g"},Iy=({mode:n})=>{const l=ju(_=>_[n]),{allColumns:i}=b.useContext(gl),{state:r,setState:u}=b.useContext(Jt),[c,d]=b.useState({}),[m,p]=b.useState(""),y=b.useMemo(()=>M_(i),[i]),v=r.aggregations.length>0||r.groupBy.length>0,x=b.useMemo(()=>m?L_(y,m):y,[m,y]),E=_=>{d(O=>({...O,[_.target.name]:_.target.checked}))},C=_=>{const O=_.target.checked;d(H=>{for(const G of i)H[G.full]=O;return{...H}})},w=()=>{Tu(n)},j=()=>{const _=[];for(const[O,H]of Object.entries(c))if(H){const[G,Y]=O.split(" ");_.push({value:Y||G,fn:Y?G:void 0})}u(O=>({...O,[n]:_})),w()},N=b.useMemo(()=>{for(const _ of i)if(!c[_.full])return!1;return!0},[c,i]);un(z_[n],()=>{n==="columns"?v?Zt.error("Columns are ignored when there is at least one aggregation or group by"):hu("columns"):hu("groupBy")}),b.useEffect(()=>{l&&d(()=>A_(r[n].map(_=>_.fn?_.fn+" "+_.value:_.value)))},[l,d]);const T=()=>{p(""),d({})};return h.jsxs(fn,{isVisible:l,onClose:w,portal:!0,onClosed:T,children:[h.jsx(aa,{onClick:w}),h.jsxs("div",{className:iu.container,children:[h.jsx("h2",{className:"text-lg font-semibold",children:n==="groupBy"?"Group by":"Show columns"}),h.jsx("input",{autoFocus:!0,className:"input my-2",placeholder:"Filter",value:m,onChange:_=>p(_.target.value)}),h.jsx("div",{className:"overflow-y-auto",children:x.map(_=>h.jsxs("div",{className:"my-2",children:[h.jsxs("p",{className:"font-semibold sticky top-0 bg-white p-1 z-1",children:["📄 ",_.name]}),_.columns.map(O=>h.jsx(U_,{column:O,selected:c,onCheck:E},O.value))]},_.name))}),h.jsxs("div",{className:"flex justify-end gap-2 mt-2",children:[h.jsxs("label",{className:"button tertiary flex gap-2 items-center",children:[h.jsx("input",{type:"checkbox",checked:N,onChange:C}),h.jsx("span",{children:"Select all"})]}),h.jsx("span",{className:"flex-1"}),h.jsx("button",{className:"button tertiary",onClick:w,children:"Cancel"}),h.jsx("button",{className:"button primary",onClick:j,children:"Apply"})]})]})]})},k_="_options-container_zt8yv_2",q_={optionsContainer:k_},ld="COUNT all",B_=()=>{const n=ju(w=>w.aggregate),{dataSourceId:l}=b.useContext(gl),{setState:i,state:r}=b.useContext(Jt),{data:u}=b.useContext(Ra),[c,d]=b.useState({fn:"",col:""}),m=w=>d({...c,fn:w.currentTarget.value}),p=w=>d({...c,col:w}),y=()=>Tu("aggregate"),v=()=>{const w=c.fn===ld?{value:"*",fn:"COUNT"}:{fn:c.fn,value:c.col,distinct:c.fn==="COUNT"};i(j=>({...j,aggregations:[...j.aggregations,w]}))},x=c.fn===ld,E=x?!1:!c.col||!c.fn,C=w=>{const j=gg(w);i(N=>({...N,aggregations:N.aggregations.filter(T=>T.fn!==w.fn||T.value!==w.value),orderBy:N.orderBy.filter(T=>T.column!==j)}))};return un("a",()=>{hu("aggregate")}),h.jsxs(fn,{isVisible:n,onClose:y,backdropClose:!0,portal:!0,children:[h.jsx(aa,{onClick:y}),h.jsxs("div",{children:[h.jsx("h2",{className:"text-lg font-semibold",children:"Aggregate"}),hl(r.aggregations.length,0)&&h.jsx("div",{className:"flex flex-col gap-1 mt-4",children:r.aggregations.map((w,j)=>h.jsxs("p",{className:"p-2 rounded-md bg-gray-50 flex items-center justify-between",children:[h.jsx("span",{children:lu(w)}),h.jsx("button",{tabIndex:-1,"data-tooltip-id":"default","data-tooltip-content":"Remove aggregation",className:"p-0.5 text-sm cursor-pointer",onClick:()=>C(w),children:h.jsx(Pl,{width:20,height:20,className:"text-red-600"})})]},j))}),h.jsxs("div",{className:q_.optionsContainer,children:[h.jsxs("label",{className:re(x&&"col-span-2"),children:[h.jsx("p",{className:"font-semibold text-xs",children:"Function"}),h.jsxs("select",{className:"input w-full",value:c.fn,onChange:m,autoFocus:!0,children:[h.jsx("option",{value:"",disabled:!0,children:"Select function"}),h.jsx("option",{value:ld,children:"Count all rows"}),h.jsx("option",{value:"COUNT",children:"Count"}),h.jsx("option",{value:"SUM",children:"Sum"}),h.jsx("option",{value:"MAX",children:"Max"}),h.jsx("option",{value:"MIN",children:"Min"}),h.jsx("option",{value:"AVG",children:"Avg"})]})]}),!x&&h.jsxs("label",{children:[h.jsx("p",{className:"font-semibold text-xs",children:"Column"}),h.jsx(Td,{dataSourceId:l,allowTables:u?.result.tables||[],onChange:p,value:c.col})]}),h.jsx("button",{className:"button primary",disabled:E,onClick:v,children:"Add"})]})]})]})},H_="_container_xly2t_2",Q_="_yellow-pill_xly2t_2 _pill_xly2t_2",Y_="_yellow-outline-pill_xly2t_2 _pill_xly2t_2",V_="_green-pill_xly2t_2 _pill_xly2t_2",K_="_blue-pill_xly2t_2 _pill_xly2t_2",$_="_blue-outline-pill_xly2t_2 _pill_xly2t_2",G_="_purple-pill_xly2t_2 _pill_xly2t_2",X_="_red-pill_xly2t_2 _pill_xly2t_2",F_="_black-pill_xly2t_2 _pill_xly2t_2",Z_="_disabled-pill_xly2t_2",Jn={container:H_,yellowPill:Q_,yellowOutlinePill:Y_,greenPill:V_,bluePill:K_,blueOutlinePill:$_,purplePill:G_,redPill:X_,blackPill:F_,disabledPill:Z_},Wy=n=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},b.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32,d:"M256 112v288M400 256H112"}));function Ig(n,l=500,i){const[r,u]=b.useState(n),c=b.useRef(i);return c.current=i,b.useEffect(()=>{const d=setTimeout(()=>{u(n),c.current&&c.current(n)},l);return()=>clearTimeout(d)},[n,l]),r}function P_(n){return!(n===!0||n===void 0)}const J_=()=>{const{state:{table:n,dataSourceId:l,aggregations:i,columns:r,groupBy:u}}=b.useContext(Jt),{filters:c,setFilters:d,removeFilter:m}=Zg(),{toggle:p,joins:y}=Jg(),{data:v}=Nu(l),x=()=>Ln("joins"),E=()=>Ln("filters"),C=()=>Ln("aggregate"),w=()=>Ln("columns"),j=()=>Ln("groupBy"),N=O=>{d(c.map(H=>({...H,isEnabled:O===H.id?P_(H.isEnabled):H.isEnabled})),!0)},T=O=>{O.preventDefault(),O.stopPropagation(),p(y[y.length-1])},_=O=>H=>{H.preventDefault(),H.stopPropagation(),m(O)};return h.jsxs("div",{className:Jn.container,children:[v&&h.jsxs("button",{onClick:x,className:Jn.greenPill,"data-tooltip-id":"default","data-tooltip-content":n,children:[h.jsx(ii,{size:18,type:v.dbType}),h.jsx("p",{className:"text-sm",children:v.name}),h.jsx(vr,{width:12,height:12}),h.jsx("p",{className:"text-sm",children:n})]}),h.jsxs("button",{onClick:x,className:Jn.yellowOutlinePill,"data-tooltip-id":"default","data-tooltip-content":"Join table, hotkey J",children:[h.jsx(Wy,{width:18,height:18}),h.jsx("p",{className:"text-sm",children:"Table"})]}),y.map((O,H)=>h.jsxs("button",{onClick:x,className:Jn.yellowPill,"data-tooltip-id":"default","data-tooltip-content":`Joins ${O.table} on ${O.on}`,children:[h.jsx("p",{className:"text-sm",children:O.table}),H===y.length-1&&h.jsx(Pl,{onClick:T,width:18,height:18})]},O.table)),h.jsxs("button",{onClick:E,className:Jn.blueOutlinePill,"data-tooltip-id":"default","data-tooltip-content":"Add filters, hotkey F",children:[h.jsx(Wy,{width:18,height:18}),h.jsx("p",{className:"text-sm",children:"Filter"})]}),c.map(O=>h.jsxs("button",{onClick:()=>N(O.id),onAuxClick:()=>m(O.id),className:re(Jn.bluePill,O.isEnabled===!1&&Jn.disabledPill),"data-tooltip-id":"default","data-tooltip-content":xE(O),children:[h.jsx("p",{className:"text-sm",children:O.column}),h.jsx("p",{className:"text-sm",children:O.operator}),h.jsx("p",{className:"text-sm",children:SE(O)}),h.jsx(Pl,{onClick:_(O.id),width:18,height:18})]},O.id)),i.map(O=>h.jsx("button",{onClick:C,className:re(Jn.purplePill),"data-tooltip-id":"default","data-tooltip-content":lu(O),children:h.jsx("p",{className:"text-sm",children:lu(O)})},lu(O))),r.length>0&&h.jsx("button",{onClick:w,className:re(Jn.redPill),"data-tooltip-id":"default","data-tooltip-content":"Has hidden columns",children:h.jsx("p",{className:"text-sm",children:"Hidden columns"})}),u.length>0&&h.jsx("button",{onClick:j,className:re(Jn.blackPill),"data-tooltip-id":"default","data-tooltip-content":"Has GROUP BY",children:h.jsx("p",{className:"text-sm",children:"GROUP BY"})}),h.jsx(I_,{})]})};function I_(){const{state:n,setState:l}=b.useContext(Jt),[i,r]=b.useState(()=>n.searchAll);return un("k",()=>{Or("Search all text values for",n.searchAll||"",{type:"info",message:"This will search all text values using LIKE operator (numbers, dates and other non string values are not searched)."}).then(c=>{c!==void 0&&(l(d=>({...d,searchAll:c.length>0?c:void 0})),r(c.length>0?c:void 0))})}),Ig(i,500,c=>{l(d=>({...d,searchAll:c&&c.length>0?c:void 0}))}),h.jsx("input",{className:"input text-sm","data-tooltip-id":"default","data-tooltip-content":"Search text in all columns. Can be slow when using a lot of columns.",placeholder:"Search text in all columns",value:i||"",onChange:c=>r(c.currentTarget.value)})}const W_=({options:n,updater:l,name:i,tabId:r})=>{const u=M4(n,l),c=q4(r,u.state),d=D4(c.data,u.state.dataSourceId,i,r);return c.isError?h.jsx("div",{className:"flex-1",children:h.jsx(wt,{variant:"danger",children:"Failed to load query"})}):h.jsx(gl,{value:d,children:h.jsx(Jt,{value:u,children:h.jsxs(Ra,{value:c,children:[h.jsx(i_,{}),h.jsx(J_,{}),h.jsxs("div",{className:"flex-1 flex overflow-hidden border-t border-gray-200",children:[h.jsx("div",{className:"flex-1 overflow-auto pb-24 lg:pb-12 no-scrollbar",children:h.jsx(G6,{})}),h.jsx(E_,{}),h.jsx(T_,{}),h.jsx(Iy,{mode:"columns"}),h.jsx(Iy,{mode:"groupBy"}),h.jsx(B_,{})]})]})})})},Wg=()=>h.jsxs("div",{role:"status",children:[h.jsxs("svg",{"aria-hidden":"true",className:"w-8 h-8 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600",viewBox:"0 0 100 101",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[h.jsx("path",{d:"M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z",fill:"currentColor"}),h.jsx("path",{d:"M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z",fill:"currentFill"})]}),h.jsx("span",{className:"sr-only",children:"Loading..."})]}),e5=({id:n})=>{const{data:l}=U4(n),i=b.useCallback(r=>{if(!l)return;const u=r($s(l.opts));rt.setQueryData(["workbench-tabs",l.id],{...l,opts:{...l.opts,...u}})},[l]);return l?h.jsx(W_,{updater:i,options:l.opts,name:l.name,tabId:l.id}):h.jsx("div",{className:"flex-1 flex justify-center items-center",children:h.jsx(Wg,{})})},t5=n=>{setTimeout(l=>{const i=document.querySelector(`[data-tab-id="${l}"]`);i&&i.scrollIntoView({behavior:"smooth"})},50,n)},n5=()=>{const{id:n}=W2(),l=Et(),{data:i}=Zd(),r=z4(),u=Cg(eh.laptop),c=p=>{if(p===n&&i){if(i.length===1)return l(Ye.home.path);if(i.length>1){const y=i.find(v=>v.id!==p);if(y)return l(`/workbench/tab/${y.id}`)}}},d=p=>{p.stopPropagation(),p.preventDefault();const y=p.currentTarget.getAttribute("data-tab-id");y&&(r.mutate(y),c(y))},m=p=>{r.mutate(p),c(p)};return b.useEffect(()=>{n&&t5(n)},[n]),h.jsxs("div",{className:"h-screen max-h-screen bg-(--bg) flex flex-col",children:[n&&h.jsx(e5,{id:n}),h.jsx("div",{className:re(cr.tabs,"no-scrollbar",!u&&cr.mobile),children:i?.map(p=>h.jsxs("div",{onClick:()=>l(`${Ye.workbench.path}/tab/${p.id}`),className:re(cr.tab,p.id===n&&cr.active),"data-tooltip-id":"default","data-tab-id":p.id,"data-tooltip-content":p.name,onAuxClick:()=>m(p.id),children:[h.jsxs("span",{className:"truncate w-full",children:["🛠️ ",p.name]}),h.jsx("button",{"data-tab-id":p.id,className:cr.closeButton,onClick:d,children:h.jsx(Pl,{width:20,height:20})})]},p.id))})]})},a5="_root_z8w66_2",l5="_up_z8w66_2",s5="_down_z8w66_2",i5="_chevron_z8w66_2",r5="_table-name-container_z8w66_2",o5="_link_z8w66_2",u5="_table-name_z8w66_2",c5="_ul_z8w66_2",f5="_column-type_z8w66_2",d5="_action-blue_z8w66_2 _action_z8w66_2",h5="_action-red_z8w66_2 _action_z8w66_2",Kt={root:a5,up:l5,down:s5,chevron:i5,tableNameContainer:r5,link:o5,tableName:u5,ul:c5,columnType:f5,actionBlue:d5,actionRed:h5},[IN,m5]=cn(!1),ev=()=>m5(!1),p5="_sidebar_1f06u_2",y5="_sidebar-visible_1f06u_2",g5="_sidebar-container_1f06u_2",v5="_sidebar-invisible_1f06u_2",b5="_backdrop_1f06u_2",fr={sidebar:p5,sidebarVisible:y5,sidebarContainer:g5,sidebarInvisible:v5,backdrop:b5},tv=({children:n,backdropClose:l,isVisible:i,onClose:r,onClosed:u,contentClassName:c})=>{const[d,m]=b.useState(!1),p=b.useRef(r);p.current=r;const y=()=>{l&&r()},v=x=>{i||getComputedStyle(x.currentTarget).opacity==="0"&&(m(!1),u&&u())};return b.useEffect(()=>{i&&m(!0)},[i]),b.useEffect(()=>{const x=E=>{i&&E.key==="Escape"&&p.current()};return window.addEventListener("keydown",x),()=>{window.removeEventListener("keydown",x)}},[i]),h.jsxs("div",{onTransitionEnd:v,className:re(fr.sidebar,i?fr.sidebarVisible:fr.sidebarInvisible),children:[h.jsx("div",{onClick:y,className:fr.backdrop}),h.jsx("div",{className:re(fr.sidebarContainer,c),children:d&&n})]})},x5=n=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},b.createElement("path",{d:"M384 224v184a40 40 0 01-40 40H104a40 40 0 01-40-40V168a40 40 0 0140-40h167.48M336 64h112v112M224 288L440 72",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32})),S5=n=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},b.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32,d:"M364.13 125.25L87 403l-23 45 44.99-23 277.76-277.13-22.62-22.62zM420.69 68.69l-22.62 22.62 22.62 22.63 22.62-22.63a16 16 0 000-22.62h0a16 16 0 00-22.62 0z"})),w5=n=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},b.createElement("path",{d:"M432 144l-28.67 275.74A32 32 0 01371.55 448H140.46a32 32 0 01-31.78-28.26L80 144",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32}),b.createElement("rect",{x:32,y:64,width:448,height:80,rx:16,ry:16,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32}),b.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32,d:"M312 240L200 352M312 352L200 240"})),nv=(n,l=!0)=>{const i=navigator.clipboard.writeText(n);l&&i.then(()=>{Zt.success(`Copied "${n}"`)})},E5=new Intl.DateTimeFormat("en",{dateStyle:"full",timeStyle:"long"}),Jo=18;function C5(n,l){return l&&n.toLowerCase().includes(l)?"bg-yellow-200 cursor-pointer":"cursor-pointer"}const _5=({insp:n,filter:l,expanded:i})=>{const r=b.useMemo(()=>i?n.columns:l.length<1?[]:n.columns.filter(u=>u.name.toLowerCase().includes(l)),[n,l,i]);return h.jsx("ul",{className:Kt.ul,children:r.map(u=>h.jsx(h.Fragment,{children:h.jsxs("li",{children:[u.isPrimary?"🔐":"🏷️"," ",h.jsx("span",{onClick:()=>nv(u.name),className:C5(u.name,l),children:u.name})," ",h.jsxs("span",{className:Kt.columnType,children:["[",u.type,"]"]}),u.ref&&h.jsxs("span",{children:[" ➡️ ",h.jsx("span",{className:Kt.columnType,children:u.ref.table}),".",u.ref.field]})]},u.name+u.type)}))},n.id)};function N5({id:n}){const{data:l}=Nu(n),{data:i}=ai(n),r=Et(),u=f4(),c=dg(),d=d4(),m=si(),p=b.useMemo(()=>l?.lastInspected?E5.format(new Date(l.lastInspected)):"--",[l]),[y,v]=b.useState({}),[x,E]=b.useState(""),[C,w]=b.useState("table"),j=Ar(Gt.EDITOR),N=x.toLowerCase(),T=b.useMemo(()=>{if(!N||!i)return i||[];const Z=[];for(const te of i){if(te.tableName.toLowerCase().includes(N)){Z.push(te);continue}C!=="table"&&te.columns.findIndex(ye=>ye.name.toLowerCase().includes(N))>=0&&Z.push(te)}return Z},[N,i,C]),_=Z=>{v(te=>({...te,[Z]:!te[Z]}))},O=Z=>{m.mutateAsync({name:Z,opts:$s({table:Z,dataSourceId:n})}).then(te=>{Gs(void 0),ev(),r(`${Ye.workbench.path}/tab/${te.id}`)})},H=()=>{c.mutate(n)},G=async()=>{const Z=await Or("Enter name",l?.name);Z&&u.mutate({id:n,dataSource:{name:Z}})},Y=async()=>{await wg("Are you sure you want to delete this data source?")&&(d.mutate(n),Gs(void 0))},K=C==="column";return h.jsxs("div",{className:Kt.root,children:[h.jsxs("div",{className:"sticky top-0 bg-white border-b border-gray-200 p-4 z-1",children:[h.jsxs("h3",{className:"page-head flex gap-2",children:[l&&h.jsx(ii,{size:32,type:l.dbType}),h.jsx("span",{className:"truncate",children:l?.name})]}),h.jsx("p",{className:"mt-2 text-xs text-gray-800",children:"Last DB inspection"}),h.jsx("p",{className:"text-sm font-semibold",children:p}),j&&h.jsxs("div",{className:"mt-2 flex gap-2",children:[h.jsxs("button",{disabled:c.isPending,onClick:H,className:Kt.actionBlue,children:[h.jsx(Qg,{width:16,height:16}),"INSPECT"]}),h.jsxs("button",{disabled:c.isPending,onClick:G,className:Kt.actionBlue,children:[h.jsx(S5,{width:16,height:16}),"RENAME"]}),h.jsxs("button",{disabled:c.isPending,onClick:Y,className:Kt.actionRed,children:[h.jsx(w5,{width:16,height:16}),"DELETE"]})]}),h.jsxs("div",{className:"flex gap-2 items-center mb-2 mt-4",children:[h.jsxs("select",{className:"input",value:C,onChange:Z=>w(Z.currentTarget.value),children:[h.jsx("option",{value:"table",children:"Table"}),h.jsx("option",{value:"column",children:"Column"})]}),h.jsx("input",{className:"input flex-1 bg-gray-50",placeholder:K?"Search column":"Search table",value:x,onChange:Z=>E(Z.target.value),autoFocus:!0})]})]}),h.jsx("div",{className:"overflow-y-auto p-4",children:T?.map(Z=>h.jsxs("div",{children:[h.jsxs("div",{className:Kt.tableNameContainer,children:[h.jsx("button",{className:re(Kt.chevron,y[Z.id]?Kt.down:Kt.up),onClick:()=>_(Z.id),children:h.jsx(vr,{width:16,height:16})}),h.jsx("button",{className:re(Kt.tableName,"flex-1"),onClick:()=>_(Z.id),children:Z.tableName}),h.jsx("button",{className:Kt.link,onClick:()=>O(Z.tableName),"data-tooltip-id":"default-xs","data-tooltip-content":"Explore table data",children:h.jsx(x5,{width:Jo,height:Jo})}),h.jsx("button",{className:Kt.link,onClick:()=>nv(Z.tableName),"data-tooltip-id":"default-xs","data-tooltip-content":"Copy table name",children:h.jsx(Yg,{width:Jo,height:Jo})})]}),(y[Z.id]||x.length>0)&&h.jsx(_5,{insp:Z,filter:K?N:"",expanded:y[Z.id]})]},Z.id))})]})}const j5=()=>{const n=cE(),[l,i]=b.useState(void 0);b.useEffect(()=>{n&&i(n)},[n]);const r=()=>Gs(void 0);return h.jsx(tv,{isVisible:n!=null,onClose:r,onClosed:()=>i(void 0),backdropClose:!0,children:l&&h.jsx(N5,{id:l})})},T5="_search_lk8p7_2",A5="_entry_lk8p7_2",R5="_ds_lk8p7_2",O5="_ds-container_lk8p7_2",D5="_ds-entry_lk8p7_2",M5="_enabled_lk8p7_2",Qs={search:T5,entry:A5,ds:R5,dsContainer:O5,dsEntry:D5,enabled:M5};function L5(n,l,i){try{const r=i.getItem(n);if(r)return JSON.parse(r)}catch(r){console.warn("Failed to restore tabs",r)}return l}const U5=({storage:n=localStorage,localStorageKey:l,initialData:i})=>{const r=cn(L5(l,i,n));return r[2].subscribe(u=>{n.setItem(l,JSON.stringify(u))}),r},[z5,k5]=U5({initialData:[],localStorageKey:"selected-data-sources-v1"}),q5=n=>k5(l=>{const i=l.indexOf(n);return i>-1?(l.splice(i,1),[...l]):[...l,n]}),B5={table:"📄",query:"📖",tab:"🛠️"},H5=({onTable:n,onQuery:l,onWorkbenchTab:i,autoFocus:r})=>{const[u,c]=b.useState(""),[d,m]=b.useState(-1),p=Ig(u,200),y=z5(),{data:v}=Bn(),{data:x}=$d({teamId:v?.teamId}),E=b.useMemo(()=>{const _=[],O=Jy(y);if(!x||x.length===0)return[];for(const H of x)O[H.id]&&_.push(H.id);return _},[y,x]),{data:C}=l4(p,{teamId:v?.teamId,selectedDataSources:E}),w=_=>{_.type==="table"?n(_.name,_.dataSourceId):_.type==="query"?l(_.id,_.dataSourceId):_.type==="tab"&&i(_.id,_.dataSourceId)},j=_=>{C&&(_.key==="ArrowDown"?(_.preventDefault(),m(O=>(O+1)%C.length)):_.key==="ArrowUp"?(_.preventDefault(),m(O=>(O-1+C.length)%C.length)):_.key==="Enter"&&d>=0&&C[d]?.name&&(_.preventDefault(),w(C[d])))},N=_=>{const O=_.currentTarget.dataset.tableId,H=C?.find(G=>G.id===O);H&&w(H)},T=b.useMemo(()=>Jy(y),[y]);return h.jsxs("div",{className:"overflow-hidden flex flex-col w-full lg:w-lg",children:[hl(x?.length,0)&&h.jsx("div",{className:Qs.dsContainer,children:x.map(_=>h.jsxs("button",{className:re(Qs.dsEntry,T[_.id]&&Qs.enabled),onClick:()=>q5(_.id),children:[h.jsx(ii,{size:24,type:_.dbType}),h.jsx("span",{children:_.name})]},_.id))}),h.jsx("input",{className:Qs.search,placeholder:"Search table or saved query to start from",value:u,onChange:_=>c(_.target.value),onKeyDown:j,autoFocus:r}),hl(C?.length,0)&&h.jsx("div",{className:"overflow-y-auto max-h-full mt-2",children:C.map((_,O)=>h.jsxs("button",{className:Qs.entry,"data-is-active":d===O,"data-table-id":_.id,onClick:N,children:[h.jsxs("p",{className:"font-semibold truncate",children:[B5[_.type]," ",_.name]}),h.jsxs("p",{className:Qs.ds,children:["📦 ",_.dataSourceName]})]},_.id))})]})},Q5=()=>{const n=H4(),l=(c,d)=>{n?.onConfirm("table",c,d)},i=(c,d)=>{n?.onConfirm("query",c,d)},r=(c,d)=>{n?.onConfirm("tab",c,d)},u=()=>{n?.onCancel()};return h.jsxs(fn,{isVisible:!!n,onClose:u,children:[h.jsx(aa,{onClick:u}),h.jsx(H5,{autoFocus:!0,onTable:l,onQuery:i,onWorkbenchTab:r})]})},Y5=()=>{const n=Tr("Hotkey"),l=Et(),{pathname:i}=qt(),{data:r}=Bn(),{data:u}=Zd(),c=i===Ye.home.path;un("n",()=>{r&&n()}),un("w",()=>{r&&(u&&u.length>0?l(`${Ye.workbench.path}/tab/${u[0].id}`):n())},{enabled:c}),un("h",()=>{Xs({show:!0})})},V5=()=>{const n=qt();b.useEffect(()=>{},[n.pathname])},[K5,av]=cn(!1),sd=()=>av(!1),lv=()=>av(!0),$5=({repeatPassword:n,password:l})=>l.length<1?null:l.length<8?h.jsx(wt,{variant:"warning",children:"New password should be at least 8 characters long"}):l!==n?h.jsx(wt,{variant:"warning",children:"Repeat password should match new password"}):null,G5=()=>{const n=K5(),{data:l}=Bn(),{mutateAsync:i,isPending:r}=h4(),u=Et(),[{password:c,repeatPassword:d},{change:m,touched:p,reset:y}]=Rr({password:"",repeatPassword:""}),v=()=>{u("/"),jr.logout().then(()=>{sd()})},x=()=>{i({password:c}).then(()=>{y(),Zt.success("Password successfully updated!")})},E=c.length<8||c!==d||r,C=p.includes("password");return h.jsxs(fn,{isVisible:n,onClose:sd,children:[h.jsx(aa,{onClick:sd}),h.jsxs("div",{className:"w-full lg:w-lg flex flex-col gap-2",children:[h.jsx(Sg,{children:"Account settings"}),h.jsxs("label",{children:[h.jsx("p",{className:"text-xs font-semibold mb-1",children:"Username"}),h.jsx("input",{className:"input w-full",readOnly:!0,disabled:!0,value:l?.username})]}),h.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[h.jsxs("label",{children:[h.jsx("p",{className:"text-xs font-semibold mb-1",children:"Change password"}),h.jsx("input",{className:"input w-full",type:"password",name:"newPassword",autoComplete:"new-password",value:c,onChange:m("password")})]}),h.jsxs("label",{children:[h.jsx("p",{className:"text-xs font-semibold mb-1",children:"Repeat password"}),h.jsx("input",{className:"input w-full",type:"password",value:d,onChange:m("repeatPassword")})]})]}),C&&h.jsx($5,{password:c,repeatPassword:d}),h.jsxs("div",{className:"flex justify-end gap-2 mt-2",children:[h.jsx("button",{className:"button tertiary",disabled:E,onClick:x,children:"Update password"}),h.jsx("button",{className:"button danger",onClick:v,children:"Log out"})]})]})]})},[X5,sv]=cn(!1),iv=()=>sv(!0),e1=()=>sv(!1),F5=n=>Pt({queryKey:["team-users"],queryFn:async()=>{const{data:l}=await je.get("/teams/"+n+"/users");return l.data},enabled:!!n}),Z5=()=>gt({mutationFn:async({role:n,teamId:l,userId:i})=>(await je.patch("/teams/"+l+"/user-role",{role:n,userId:i}),!0),onSuccess:()=>{rt.invalidateQueries({queryKey:["team-users"]})}}),P5=()=>gt({mutationFn:async({teamId:n,userId:l})=>(await je.delete("/teams/"+n,{params:{userId:l}}),!0),onSuccess:()=>{rt.invalidateQueries({queryKey:["team-users"]})}}),J5="_user-entry_1dt1j_2",I5="_select-container_1dt1j_2",t1={userEntry:J5,selectContainer:I5},W5=()=>{const n=X5(),{data:l}=Bn(),{data:i}=F5(l?.teamId),{mutate:r,isPending:u}=m4(),{mutate:c,isPending:d}=Z5(),{mutate:m,isPending:p}=P5(),[y,{change:v,reset:x}]=Rr({password:"",username:""}),E=()=>{r({username:y.username,password:y.password,teamId:l?.teamId||""}),x()},C=(T,_)=>{c({teamId:l.teamId,role:_,userId:T})},w=T=>{wg("Are you sure you want to remove this user?").then(_=>{_&&m({userId:T,teamId:l.teamId})})},j=Ar(Gt.ADMIN),N=u||d||p;return h.jsxs(fn,{isVisible:n,onClose:e1,backdropClose:!0,children:[h.jsx(aa,{onClick:e1}),h.jsxs("div",{className:"w-full lg:w-lg flex flex-col overflow-hidden",children:[h.jsx(Sg,{children:"Manage users"}),hl(i?.length,0)&&h.jsx("div",{className:"mt-4 overflow-y-auto flex-1",children:i.map(T=>h.jsxs("div",{className:t1.userEntry,children:[h.jsx("div",{className:t1.selectContainer,children:h.jsxs("select",{value:T.role,disabled:!j||N,onChange:_=>C(T.id,_.currentTarget.value),children:[h.jsx("option",{value:Gt.OWNER,children:"Owner"}),h.jsx("option",{value:Gt.ADMIN,children:"Admin"}),h.jsx("option",{value:Gt.EDITOR,children:"Editor"}),h.jsx("option",{value:Gt.READ_ONLY,children:"Reader"})]})}),h.jsx("p",{className:"flex-1 mx-2",children:T.name}),j&&h.jsx("button",{className:"p-1 cursor-pointer text-red-500 text-sm",onClick:()=>w(T.id),children:"❌"})]},T.id))}),j&&h.jsxs("div",{className:"mt-4",children:[h.jsx("p",{className:"font-semibold",children:"Create new user"}),h.jsxs("div",{className:"flex flex-col lg:flex-row gap-2 lg:items-center mt-2",children:[h.jsx("input",{className:"input flex-1",onChange:v("username"),value:y.username,placeholder:"Username",disabled:N}),h.jsx("input",{className:"input",onChange:v("password"),value:y.password,type:"password",name:"newPassword",autoComplete:"new-password",placeholder:"Password",disabled:N}),h.jsx("button",{className:"button primary",onClick:E,disabled:N,children:"Create user"})]}),h.jsx("p",{className:"text-xs mt-1 text-gray-600",children:"You should create default password for the new account. The user should change it after the first login."})]})]})]})},eN=()=>{const[n,l]=b.useState(""),[i,r]=b.useState(""),[u,c]=b.useState(),[d,m]=b.useState(!1),p=Et(),y=v=>{v.preventDefault(),c(void 0),jr.login({password:i,username:n}).then(()=>{p("/",{replace:!0})}).catch(c)};return h.jsx("div",{className:"page-container bg-(--bg) h-screen",children:h.jsx("div",{className:"page-content items-center",children:h.jsxs("form",{className:"flex flex-col gap-2 w-full lg:w-lg",onSubmit:y,children:[h.jsx("p",{className:"font-semibold text-xl min-w-md",children:"Login"}),u&&h.jsx(wt,{variant:"danger",children:"Failed to login. Please verify your credentials"}),h.jsx("input",{value:n,onChange:v=>l(v.currentTarget.value),className:"input",placeholder:"User name"}),h.jsx("input",{value:i,onChange:v=>r(v.currentTarget.value),className:"input",type:"password",placeholder:"Password"}),h.jsx("button",{type:"submit",className:"button primary",children:"Login"}),d?h.jsxs(wt,{className:"w-full border border-blue-500",children:[h.jsx("p",{children:"If this is your first login, the default credentials are:"}),h.jsxs("ul",{className:"mt-2",children:[h.jsxs("li",{children:["Username: ",h.jsx("strong",{children:"admin"})]}),h.jsxs("li",{children:["Password: ",h.jsx("strong",{children:"admin"})]})]}),h.jsx("p",{className:"mt-2",children:"Please make sure to change the default password to a secure one."})]}):h.jsx("button",{className:"button tertiary",onClick:()=>m(!0),children:"First login?"})]})})})},tN=()=>{const n=Et(),{pathname:l}=qt(),{data:i,isLoading:r}=hg();b.useEffect(()=>{!i&&!r&&l!==Ye.login.path&&n(Ye.login.path)},[i,r,n,l])},nN=()=>{const[n]=Kx(),l=Et(),i=si(),r=n.get("shareId");return b.useEffect(()=>{r&&i.mutateAsync({queryId:r}).then(u=>{l(`${Ye.workbench.path}/tab/${u.id}`,{replace:!0})})},[r]),h.jsxs("div",{className:"page-container flex items-center justify-center h-screen",children:[i.isPending&&h.jsxs("div",{className:"flex items-center flex-col gap-2",children:[h.jsx(Wg,{}),h.jsx("p",{children:"Fetching query information"})]}),i.isError&&h.jsx(wt,{variant:"danger",children:"Failed to load query information"})]})},aN="_container_14dtx_2",lN="_header_14dtx_2",sN="_close-button_14dtx_2",iN="_tab-container_14dtx_2",rN="_tab-name_14dtx_2",oN="_archived-badge_14dtx_2 _badge_14dtx_2",uN="_active-badge_14dtx_2 _badge_14dtx_2",cN="_action-blue_14dtx_2 _action_14dtx_2",fN="_action-red_14dtx_2 _action_14dtx_2",dN="_load-more-btn_14dtx_2",In={container:aN,header:lN,closeButton:sN,tabContainer:iN,tabName:rN,archivedBadge:oN,activeBadge:uN,actionBlue:cN,actionRed:fN,loadMoreBtn:dN},hN=new Intl.DateTimeFormat,mN=()=>{const{data:n}=Bn(),{data:l,fetchNextPage:i,hasNextPage:r,isFetching:u}=s4(n?.teamId,25),c=Et(),d=vg(),m=B4(),p=x=>{d.mutate(x),Xs({show:!1}),c(`${Ye.workbench.path}/tab/${x}`)},y=x=>{m.mutate(x)},v=l&&l?.length>0;return h.jsxs("div",{className:In.container,children:[h.jsxs("div",{className:In.header,children:[h.jsx("h3",{className:"text-lg",children:"Tabs history"}),h.jsx("button",{className:In.closeButton,onClick:()=>Xs({show:!1}),children:h.jsx(Pl,{width:24,height:24})})]}),!v&&h.jsx(wt,{variant:"warning",children:"History is empty."}),l?.map(x=>h.jsxs("div",{className:In.tabContainer,children:[h.jsxs("div",{className:"flex gap-2 items-center",children:[h.jsx("p",{className:In.tabName,children:x.name}),x.dataSourceType&&h.jsx(ii,{size:16,type:x.dataSourceType}),h.jsx("p",{className:"text-sm",children:x.dataSourceName})]}),h.jsxs("div",{className:"flex gap-2 items-center mt-1",children:[h.jsx("p",{className:"text-sm italic",children:hN.format(new Date(x.updatedAt))}),x.archived?h.jsx("span",{className:In.archivedBadge,children:"Archived"}):h.jsx("span",{className:In.activeBadge,children:"Active"}),h.jsx("span",{className:"flex-1"}),h.jsx("button",{onClick:()=>p(x.id),className:In.actionBlue,children:"Open"}),h.jsx("button",{onClick:()=>y(x.id),className:In.actionRed,children:"Delete"})]})]},x.id)),r&&!u&&h.jsx("div",{className:"flex justify-center my-2",children:h.jsx("button",{className:In.loadMoreBtn,onClick:()=>i(),children:"Load more"})})]})},pN=()=>{const n=fE(l=>l.show);return h.jsx(tv,{isVisible:n,onClose:()=>Xs({show:!1}),backdropClose:!0,children:h.jsx(mN,{})})};function yN(){return Y5(),V5(),tN(),h.jsxs(h.Fragment,{children:[h.jsxs(mx,{children:[h.jsx(dr,{path:Ye.home.path,element:h.jsx(gE,{})}),h.jsx(dr,{path:`${Ye.workbench.path}/tab/:id`,element:h.jsx(n5,{})}),h.jsx(dr,{path:Ye.login.path,element:h.jsx(eN,{})}),h.jsx(dr,{path:Ye.share.path,element:h.jsx(nN,{})})]}),h.jsx(OE,{}),h.jsx(QE,{}),h.jsx(e6,{}),h.jsx(j5,{}),h.jsx(Q5,{}),h.jsx(G5,{}),h.jsx(W5,{}),h.jsx(pN,{}),h.jsx(ZE,{}),h.jsx(KE,{})]})}const gN="_desktop-layout_zjyhz_2",vN="_mobile-layout_zjyhz_2",bN="_nav_zjyhz_2",xN="_main_zjyhz_2",SN="_header_zjyhz_2",Ps={desktopLayout:gN,mobileLayout:vN,nav:bN,main:xN,header:SN},wN="_container_111rk_2",EN="_menu_111rk_2",uh={container:wN,menu:EN},CN=({name:n,id:l,onRename:i,onDelete:r,onOpen:u})=>{const c=Ng();return h.jsxs("button",{className:uh.menu,onContextMenu:c.open,onClick:()=>u(l),children:[h.jsx(jg,{handler:c,children:h.jsxs("div",{className:"context-menu-container",children:[h.jsx("button",{onClick:d=>{d.preventDefault(),d.stopPropagation(),c.close(),i(l)},className:"context-menu-item",children:"✏️ Rename"}),h.jsx("button",{onClick:d=>{d.preventDefault(),d.stopPropagation(),c.close(),r(l)},className:"context-menu-item",children:"🗑️ Delete"})]})}),h.jsxs("span",{children:["📖 ",n]})]})},_N=({dataSource:n,index:l})=>{const i=()=>{Gs(n.id)};return un(l.toString(),()=>{Gs(r=>{if(r!==n.id)return n.id})}),h.jsxs("button",{className:uh.menu,onClick:i,children:[h.jsx(ii,{size:20,type:n.dbType}),h.jsx("p",{className:"truncate flex-1 text-left mx-1.5",children:n.name}),h.jsx("span",{className:"hotkey",children:l})]})},NN=()=>{const n=Et(),{data:l}=Bn(),{data:i}=t4(l?.teamId),{data:r}=n4(l?.teamId),u=si(),c=P6(),d=Z6(),m=v=>{u.mutateAsync({queryId:v}).then(x=>{n(`${Ye.workbench.path}/tab/${x.id}`)})},p=async v=>{const x=r?.find(C=>C.id===v);if(!x)return;const E=await Or("New name?",x?.name);E&&c.mutate({id:x.savedQueryId,payload:{name:E}})},y=v=>{const x=r?.find(E=>E.id===v)?.savedQueryId;x&&d.mutate(x)};return h.jsx("div",{className:uh.container,children:h.jsxs("div",{className:"flex-1 overflow-y-auto",children:[hl(i?.length,0)&&h.jsxs("div",{className:"mt-4",children:[h.jsx("p",{className:"font-semibold text-sm text-gray-600 mb-2",children:"DATA SOURCES"}),i.map((v,x)=>h.jsx(_N,{dataSource:v,index:x+1},v.id))]}),hl(r?.length,0)&&h.jsxs("div",{className:"mt-4",children:[h.jsx("p",{className:"font-semibold text-sm text-gray-600 mb-2",children:"SAVED QUERIES"}),r.map(v=>h.jsx(CN,{onDelete:y,onRename:p,onOpen:m,name:v.name,id:v.id},v.savedQueryId))]})]})})},jN=()=>{const n=Et(),{pathname:l}=qt(),{data:i}=Bn(),r=Tr("Desktop nav"),u=()=>{ev(),l!==Ye.home.path&&n(Ye.home.path)},c=()=>Xs({show:!0});return h.jsxs("nav",{className:Ps.nav,children:[i&&h.jsxs("div",{className:Ps.header,children:[h.jsx("button",{onClick:u,className:"flex justify-between items-center",children:h.jsx("span",{children:"🏠 Home"})}),h.jsxs("button",{onClick:r,className:"flex justify-between items-center",children:[h.jsx("span",{children:"🔎 New query"}),h.jsx("span",{className:"hotkey",children:"N"})]}),h.jsxs("button",{onClick:c,className:"flex justify-between items-center",children:[h.jsx("span",{children:"⌛ Recent tabs"}),h.jsx("span",{className:"hotkey",children:"H"})]}),h.jsxs("button",{onClick:lv,children:["🪪 ",i.username]}),h.jsx("button",{onClick:iv,children:"👥 Manage users"})]}),h.jsx(NN,{})]})},TN="_root_x5xkr_2",AN={root:TN},RN=()=>{const{pathname:n}=qt(),l=Et(),i=Tr("Mobile nav"),r=()=>{n!==Ye.home.path&&l(Ye.home.path)};return h.jsxs("div",{className:AN.root,children:[h.jsxs("button",{onClick:r,children:[h.jsx("p",{children:"🏠"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Home"})]}),h.jsxs("button",{onClick:i,children:[h.jsx("p",{children:"🔎"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"New query"})]}),h.jsxs("button",{onClick:lv,children:[h.jsx("p",{children:"🪪"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Account"})]}),h.jsxs("button",{onClick:iv,children:[h.jsx("p",{children:"👥"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Users"})]})]})},ON=({children:n,isLogin:l})=>h.jsxs("div",{className:Ps.desktopLayout,children:[h.jsx(gu,{id:"default",className:"z-100"}),h.jsx(gu,{id:"default-xs",className:"z-100 text-xs!"}),!l&&h.jsx(jN,{}),h.jsx("main",{className:Ps.main,children:n})]}),DN=({children:n,isLogin:l})=>h.jsxs("div",{className:Ps.mobileLayout,children:[h.jsx("main",{className:Ps.main,children:n}),!l&&h.jsx(RN,{})]}),MN=({children:n})=>{const l=Cg(eh.laptop),{pathname:i}=qt(),r=i===Ye.login.path;return l?h.jsx(ON,{isLogin:r,children:n}):h.jsx(DN,{isLogin:r,children:n})};w2.createRoot(document.getElementById("root")).render(h.jsxs(rl.StrictMode,{children:[h.jsx(I3,{}),h.jsx(xS,{client:rt,children:h.jsx(Bx,{children:h.jsx(MN,{children:h.jsx(yN,{})})})})]}));
@@ -7,7 +7,7 @@
7
7
  <title>DataRamen | Lightweight GUI for MySQL & PostgreSQL</title>
8
8
  <meta name="description" content="Designed for speed, DataRamen makes navigating MySQL and PostgreSQL data effortless with a clean, high-performance interface." />
9
9
  <meta name="robots" content="noindex, nofollow">
10
- <script type="module" crossorigin src="/assets/index-CJFRNN83.js"></script>
10
+ <script type="module" crossorigin src="/assets/index-CLzSzn3S.js"></script>
11
11
  <link rel="stylesheet" crossorigin href="/assets/index-BBB4tfVq.css">
12
12
  </head>
13
13
  <body>
package/dist/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@dataramen/server","version":"0.0.84-beta.1","license":"MIT","main":"code/server.js","dependencies":{"@fastify/cors":"^11.0.1","@fastify/static":"^8.2.0","@fastify/cookie":"^11.0.2","dotenv":"^16.5.0","fast-glob":"^3.3.3","fastify":"^5.3.2","mysql2":"^3.14.1","pg":"^8.15.6","sqlite3":"^5.1.7","typeorm":"^0.3.27","bcryptjs":"^3.0.2","jose":"^6.0.12","reflect-metadata":"^0.2.2","qs":"^6.14.0"},"devDependencies":{"fs-extra":"^11.3.0","open":"^10.2.0","commander":"^14.0.2","yocto-spinner":"^1.0.0"}}
1
+ {"name":"@dataramen/server","version":"0.0.84","license":"MIT","main":"code/server.js","dependencies":{"@fastify/cors":"^11.0.1","@fastify/static":"^8.2.0","@fastify/cookie":"^11.0.2","dotenv":"^16.5.0","fast-glob":"^3.3.3","fastify":"^5.3.2","mysql2":"^3.14.1","pg":"^8.15.6","sqlite3":"^5.1.7","typeorm":"^0.3.27","bcryptjs":"^3.0.2","jose":"^6.0.12","reflect-metadata":"^0.2.2","qs":"^6.14.0"},"devDependencies":{"fs-extra":"^11.3.0","open":"^10.2.0","commander":"^14.0.2","yocto-spinner":"^1.0.0"}}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@dataramen/cli",
3
- "version": "0.0.61-beta.1",
3
+ "version": "0.0.61",
4
4
  "repository": "https://github.com/OleksandrDemian/dataramen.git",
5
5
  "author": "Oleksandr Demian <oleksandrovsky@gmail.com>",
6
6
  "license": "MIT",
7
7
  "bin": {
8
- "dataramen": "bin/run.js"
8
+ "dataramen": "bin/app.js"
9
9
  },
10
10
  "scripts": {
11
11
  "build": "node build.mjs"
package/bin/run.js DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
- var G=Object.create;var V=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var X=(e,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Q(t))!z.call(e,n)&&n!==r&&V(e,n,{get:()=>t[n],enumerable:!(a=U(t,n))||a.enumerable});return e};var u=(e,t,r)=>(r=e!=null?G(q(e)):{},X(t||!e||!e.__esModule?V(r,"default",{value:e,enumerable:!0}):r,e));var B=require("commander");var C=require("node:os"),N=require("node:path"),Z=(0,C.homedir)(),c="@dataramen/server",i=(0,N.join)(Z,".dataramen",".runtime","server");var Y=require("node:path"),D=u(require("fs-extra")),K=require("node:child_process");var k=u(require("fs-extra")),P=require("node:path");function A(e){let t;function r(){try{return t||(t=k.readJsonSync(e)),t}catch{return}}return r}var v=A((0,P.join)(__dirname,"..","package.json")),S=A((0,P.join)(i,"package.json"));var p=u(require("fs-extra")),f=require("node:path"),M=require("node:child_process"),$=require("node:util"),E=u(require("yocto-spinner")),g=(0,$.promisify)(M.exec);function I(){try{let e=S();if(!e)return!0;let t=p.readJsonSync((0,f.join)(__dirname,"..","dist","package.json"));return e.version!==t.version}catch{return!0}}async function W(){let e=(0,E.default)({text:"Checking if PM2 is installed"}).start();try{return await g("pm2 -v"),e.success("PM2 already installed"),!0}catch{return e.warning("PM2 not installed"),!1}}async function j(){let e=(0,E.default)({text:"Installing PM2"}).start();try{await g("npm i -g pm2"),e.success("Installed PM2")}catch{e.error("Failed to install PM2"),process.exit(1)}}async function b(){let e=(0,E.default)({text:"Stop running instances of "+c}).start();try{await g(`pm2 stop "${c}"`),e.warning("Stopped "+c)}catch{e.success("No running instances of "+c+" found")}}async function J(){let e=(0,E.default)({text:"Create local server"}).start();p.removeSync((0,f.join)(i,"code")),p.copySync((0,f.join)(__dirname,"..","dist","code"),(0,f.join)(i,"code")),p.copySync((0,f.join)(__dirname,"..","dist","package.json"),(0,f.join)(i,"package.json")),e.text="Install local server dependencies",await g("npm i",{cwd:i}),e.success("Local server installed")}var x=u(require("yocto-spinner")),T=u(require("open"));var H=require("node:net");async function O(e){return new Promise(t=>{let r=(0,H.createServer)().once("error",()=>{t(!1)}).once("listening",()=>{r.close()}).once("close",()=>t(!0)).listen(e,"127.0.0.1")})}var y=u(require("node:crypto"));var h=require("fs-extra"),_=require("node:path");function ee(e){try{return(0,h.readFileSync)((0,_.join)(i,e),"utf-8")}catch{return}}function te(e){let t={},r=ee(e);if(r){let a=r.split(`
3
- `);for(let n of a){let s=n.trim();if(!s||s.startsWith("#"))continue;let d=s.indexOf("=");if(d===-1)continue;let R=s.slice(0,d).trim(),m=s.slice(d+1).trim();(m.startsWith('"')&&m.endsWith('"')||m.startsWith("'")&&m.endsWith("'"))&&(m=m.slice(1,-1)),t[R]=m}}return t}function ne(){let e={customValues:{},fileName:".env"};function t(){e.customValues=te(e.fileName)}function r(){let s=Object.entries(e.customValues).map(([d,R])=>`${d}=${R}`).join(`
4
- `)+`
5
- `;(0,h.writeFileSync)((0,_.join)(i,e.fileName),s,{encoding:"utf8"})}function a(n){if(e.customValues[n])return e.customValues[n]}return t(),{getNumber:n=>re(a(n)),getString:n=>oe(a(n)),getBoolean:n=>se(a(n)),flush:r,set:(n,s)=>{e.customValues[n]=s},unset:n=>{delete e.customValues[n]}}}function re(e){if(!e)return;let t=Number(e);if(!isNaN(t)&&e.trim()!=="")return t;throw new Error("Wrong env value type")}function oe(e){if(e){if(typeof e=="string")return e;throw new Error("Wrong env value type")}}function se(e){if(!e)return;let t=e.toLowerCase();if(t==="true"||t==="1")return!0;if(t==="false"||t==="0")return!1;throw new Error("Wrong env value type")}var o=ne();function F(){let e=!1;if(!o.getString("SYMM_ENCRYPTION_KEY")){let t=y.randomBytes(32).toString("hex");o.set("SYMM_ENCRYPTION_KEY",t),console.log("Generated random SYMM_ENCRYPTION_KEY"),e=!0}if(!o.getString("JWT_SECRET")){let t=y.randomBytes(32).toString("hex");o.set("JWT_SECRET",t),console.log("Generated random JWT_SECRET"),e=!0}if(!o.getString("JWT_REFRESH_SECRET")){let t=y.randomBytes(32).toString("hex");o.set("JWT_REFRESH_SECRET",t),console.log("Generated random JWT_REFRESH_SECRET"),e=!0}e&&o.flush()}var ie=async e=>{try{return(await fetch(e,{method:"GET",signal:AbortSignal.timeout(5e3)})).status===200}catch{return!1}},L=async(e,t,r)=>{let a=Date.now();for(;Date.now()-a<t;){if(await ie(e))return!0;await new Promise(s=>setTimeout(s,r))}return!1};async function le(){await W()||await j(),await b();try{I()&&await J(),F();let t=o.getNumber("PORT")||4466;if(!t)throw new Error("PORT env variable not found");if(!await O(t))throw new Error(`Port ${t} is occupied by another process`);let a=(0,x.default)({text:"Starting new instance of "+c}).start(),n=D.readJsonSync((0,Y.join)(i,"package.json"));await g(`pm2 start "${n.main}" --name "${c}" --no-autorestart -- "${i}/.env"`,{cwd:i}),a.success("Local server will be available in a couple of seconds");let s=(0,x.default)({text:"Waiting for the server to become available"}).start();await L(`http://localhost:${t}/api/status`,3e4,1e3)?(await(0,T.default)(`http://localhost:${t}`),s.success(`App is running at http://localhost:${t}`)):s.error("Server failed to become available in time")}catch(t){console.error("Failed to start local server",t)}}async function me(){(0,K.execSync)(`pm2 logs ${c}`,{stdio:"inherit"})}async function ue(){await b()}function fe(){console.log(`DataRamen CLI version: ${v().version}`),console.log(`DataRamen local server version: ${S().version}`)}async function pe(){let e=o.getNumber("PORT");await(0,T.default)(`http://localhost:${e}`)}function de(e,t){o.set(e,t),o.flush(),console.log(`Environment property set: ${e}`)}function ge(e){o.unset(e),o.flush(),console.log(`Environment property unset: ${e}`)}var l={start:le,logs:me,stop:ue,version:fe,open:pe,setEnvVariable:de,unsetEnvVariable:ge};var w=new B.Command,Ee=[{command:"start",description:"Start local server, restarts if already running",handler:l.start},{command:"logs",description:"Listen for logs",handler:l.logs},{command:"stop",description:"Stop the server",handler:l.stop},{command:"open",description:"Stop the server",handler:l.open},{command:"set <prop> <value>",description:"Set env value",handler:l.setEnvVariable},{command:"unset <prop>",description:"Remove env value",handler:l.unsetEnvVariable}];w.name("dataramen").description("A cozy web GUI for MySQL and PostgreSQL - built for developers who like to move fast and stay focused.").version(v().version,"-v, --version","Show version");w.command("default",{hidden:!0,isDefault:!0}).action(l.start);Ee.forEach(e=>{w.command(e.command).description(e.description).action(e.handler)});w.parse();