@dataramen/cli 0.0.49-beta.1 → 0.0.49-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -229,9 +229,9 @@ to {
|
|
|
229
229
|
> * {
|
|
230
230
|
pointer-events: auto;
|
|
231
231
|
}
|
|
232
|
-
`,Bo=16,L3=({reverseOrder:n,position:l="top-center",toastOptions:r,gutter:i,children:o,containerStyle:u,containerClassName:d})=>{let{toasts:m,handlers:y}=u3(r);return b.createElement("div",{id:"_rht_toaster",style:{position:"fixed",zIndex:9999,top:Bo,left:Bo,right:Bo,bottom:Bo,pointerEvents:"none",...u},className:d,onMouseEnter:y.startPause,onMouseLeave:y.endPause},m.map(p=>{let g=p.position||l,S=y.calculateOffset(p,{reverseOrder:n,gutter:i,defaultPosition:l}),E=M3(g,S);return b.createElement(D3,{id:p.id,key:p.id,onHeightUpdate:y.updateHeight,className:p.visible?U3:"",style:E},p.type==="custom"?cu(p.message,p):o?o(p):b.createElement(O3,{toast:p,position:g}))}))},qt=Qt;const pt=new aS({defaultOptions:{queries:{staleTime:1e3*60*5,retry:(n,l)=>{var r;return uu(l)&&((r=l.response)==null?void 0:r.status)===404?!1:n<3}}},mutationCache:new Lv({onError:n=>{var l;uu(n)&&n.status&&n.status>=400&&n.status<500&&(l=n.response)!=null&&l.data.error&&qt.error(n.response.data.error)}})}),q3=async()=>{const{data:n}=await Zd.post("/auth/refresh");return n.data.accessToken},z3=async n=>{const{data:l}=await Zd.post("/auth/login",n);return l.data.accessToken},nd=()=>{pt.invalidateQueries({queryKey:["accessToken"]})},br=(()=>{let n=Promise.resolve(Gw()),l=!1;const r=async()=>{await Zd.post("/auth/logout"),zo(void 0),window.location.reload()};return{get:async()=>n.then(d=>(nd(),d)),refresh:()=>(l||(l=!0,n=q3().then(d=>(zo(d),d)).catch(()=>{zo(void 0),r()}).finally(()=>{l=!1,nd()})),n),login:d=>(l||(l=!0,n=z3(d).then(m=>(zo(m),m)).finally(()=>{l=!1,nd()})),n),logout:r}})(),p1=location.hostname.includes("app.dataramen.xyz")?"http://localhost:4466/api":"/api",Ve=lt.create({baseURL:p1,withCredentials:!0});Ve.interceptors.request.use(async n=>{const l=await br.get();return l&&(n.headers.Authorization=`Bearer ${l}`),n});Ve.interceptors.response.use(n=>n,n=>{var l;return uu(n)&&n.status===401&&((l=n==null?void 0:n.response)==null?void 0:l.data.error)!=="Missing auth token"&&br.refresh(),Promise.reject(n)});const Zd=lt.create({baseURL:p1,withCredentials:!0}),La="data-sources",Jd="auth-user",B3=n=>fn({queryKey:["project","datasources",n],queryFn:async()=>{const{data:l}=await Ve.get(`/project/team/${n}/datasources`);return l.data},enabled:!!n}),H3=n=>fn({queryKey:["project","saved-queries",n],queryFn:async()=>{const{data:l}=await Ve.get(`/project/team/${n}/queries`);return l.data},enabled:!!n}),Wi=n=>{const l=["project","team"],r=["project","saved-queries"];return Promise.all([pt.invalidateQueries(l),pt.invalidateQueries(r)])},k3=n=>{const l=["trash","team"];return pt.invalidateQueries(l)},Q3=(n,l)=>fn({queryKey:["project",l.teamId,"tables",n,l.selectedDataSources],queryFn:async()=>{const{data:r}=await Ve.get(`/project/team/${l.teamId}/query`,{params:{size:30,search:n,selectedDataSources:l.selectedDataSources}});return r.data},enabled:!!l.teamId,staleTime:0,keepPreviousData:!0}),Y3=(n,l)=>{},V3=()=>{},K3={event:Y3,pageView:V3},Nu=n=>fn([La,n],async()=>{const{data:l}=await Ve.get("/data-sources/"+n);return l.data},{enabled:!!n}),Pd=n=>fn({queryKey:[La,n.teamId],queryFn:async()=>{const{data:l}=await Ve.get("/data-sources",{params:n});return l.data},enabled:n.teamId!==void 0}),es=n=>fn({queryKey:[La,n,"inspections"],queryFn:async()=>{const{data:l}=await Ve.get(`/data-sources/${n}/inspections`);return l.data},enabled:!!n}),G3=()=>cn(async n=>{const{data:l}=await Ve.post("/data-sources",n);return l.data},{onSuccess:()=>{pt.invalidateQueries([La]),Wi()},onError:()=>{}}),F3=()=>cn({mutationFn:async({dataSource:n,id:l})=>{const{data:r}=await Ve.put(`/data-sources/${l}`,n);return r.data},onSuccess:()=>{pt.invalidateQueries([La]),Wi()}}),y1=()=>cn({mutationFn:async n=>{await Ve.post(`/data-sources/${n}/inspect`)},onSuccess:()=>{pt.invalidateQueries([La])}}),$3=()=>cn({mutationFn:async n=>{await Ve.delete(`/data-sources/${n}`)},onSuccess:()=>{pt.invalidateQueries([La]),Wi()}}),v1=()=>fn(["accessToken"],br.get),sa=()=>{const{data:n}=v1();return fn({queryKey:[Jd],queryFn:async()=>{const{data:l}=await Ve.get("/users");return l.data},enabled:!!n,retry:(l,r)=>uu(r)&&r.code==="ERR_NETWORK"?!1:l<3})},X3=()=>cn({mutationFn:async n=>{const{data:l}=await Ve.patch("/users",n);return l.data},onSuccess:async n=>{pt.setQueryData([Jd],n)}}),Z3=()=>cn({mutationFn:async n=>(await Ve.post("/users",n),!0),onSuccess:()=>{pt.invalidateQueries({queryKey:["team-users"]})}}),J3="_alert_6qdub_2",P3="_info_6qdub_2",I3="_danger_6qdub_2",W3="_success_6qdub_2",e4="_warning_6qdub_2",t4="_dark_6qdub_2",Li={alert:J3,info:P3,danger:I3,success:W3,warning:e4,dark:t4};function g1(n){var l,r,i="";if(typeof n=="string"||typeof n=="number")i+=n;else if(typeof n=="object")if(Array.isArray(n)){var o=n.length;for(l=0;l<o;l++)n[l]&&(r=g1(n[l]))&&(i&&(i+=" "),i+=r)}else for(r in n)n[r]&&(i&&(i+=" "),i+=r);return i}function se(){for(var n,l,r=0,i="",o=arguments.length;r<o;r++)(n=arguments[r])&&(l=g1(n))&&(i&&(i+=" "),i+=l);return i}const Lt=({variant:n,noRounded:l,className:r,children:i,...o})=>h.jsx("div",{className:se(Li.alert,!l&&"rounded-lg",(n==="info"||!n)&&Li.info,n==="danger"&&Li.danger,n==="dark"&&Li.dark,n==="warning"&&Li.warning,n==="success"&&Li.success,r),role:"alert",...o,children:i}),It=n=>{const l=new Set;let r=n;const i=m=>(l.add(m),()=>l.delete(m)),o=m=>(l.forEach(y=>y(m)),!0),u=m=>{r=typeof m=="function"?m(r):m,o(r)},d=m=>()=>m?m(r):r;return[m=>b.useSyncExternalStore(i,d(m),d(m)),u,{get:()=>r,subscribe:m=>(m(r),i(m))}]};function n4(n){const l=[];for(const r of n)for(const i of r.columns)i.ref&&(l.push({id:`${r.tableName}->${i.ref.table}.${i.ref.field}`,name:`${r.tableName} in ${i.ref.table}`,where:`${r.tableName}.${i.name} = ${i.ref.table}.${i.ref.field}`,on:{fromTable:i.ref.table,toTable:r.tableName,fromColumn:i.ref.field,toColumn:i.name}}),l.push({id:`${i.ref.table}->${r.tableName}.${i.name}`,name:`${i.ref.table} in ${r.tableName}`,where:`${i.ref.table}.${i.ref.field} = ${r.tableName}.${i.name}`,on:{fromTable:r.tableName,toTable:i.ref.table,fromColumn:i.name,toColumn:i.ref.field}}));return l}const a4=n=>fn({queryKey:["hooks",n],queryFn:async()=>{const l=await pt.fetchQuery({queryKey:[La,n,"inspections"],queryFn:async()=>{const{data:r}=await Ve.get(`/data-sources/${n}/inspections`);return r.data}});return n4(l)},enabled:!!n}),Id=[{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"}],Wd=Id.reduce((n,l)=>(n[l.value]=l.label,n),{}),eh=Id.reduce((n,l)=>(n[l.label]=l.value,n),{}),ts=n=>n.map(l=>({label:Wd[l],value:l})),l4=ts(["=","<>",">",">=","<","<=","IN","NOT IN","IS NULL","IS NOT NULL"]),i4=ts(["=","<>","LIKE","NOT LIKE","IN","NOT IN","IS NULL","IS NOT NULL"]);ts(["=","<>","IS NULL","IS NOT NULL"]);const s4=ts(["=","<>",">",">=","<","<=","IS NULL","IS NOT NULL"]);ts(["IS NULL","IS NOT NULL"]);ts(["IN","NOT IN"]);const b1=n=>n!=="IS NULL"&&n!=="IS NOT NULL",r4=(n,l)=>b1(n)?n==="IN"||n==="NOT IN"?l.split(",").map(r=>({value:r.trim(),isColumn:!1})):[{value:l,isColumn:!1}]:[],o4=["char","varchar","binary","varbinary","blob","text","enum","set","character","character varying","text","citext","uuid","xml","json","jsonb"],u4=["integer","smallint","decimal","numeric","float","real","double precision","int","smallint","integer","bigint","decimal","numeric","real","double precision","serial","bigserial","money"],c4=["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"],f4=["date","datetime","timestamp","timestamptz"].reduce((n,l)=>(n[l]=!0,n),{}),ta=n=>n.fn?n.distinct===!0?`${n.fn} distinct ${n.value}`:`${n.fn} ${n.value}`:n.value;var Xt=(n=>(n.OWNER="owner",n.ADMIN="admin",n.EDITOR="editor",n.READ_ONLY="read_only",n))(Xt||{});const Ly={[Xt.READ_ONLY]:10,[Xt.EDITOR]:20,[Xt.ADMIN]:30,[Xt.OWNER]:40};function d4(n,l){if(!n||!l)return{};const r=new Set;for(const o of l)o.table&&r.add(o.table);const i={};for(const o of r){const u=n.find(d=>d.tableName===o);if(u){i[o]=[];const d=u.columns.filter(m=>m.isPrimary);for(const m of d)if(l.find(p=>p.table===o&&p.column===m.name))i[o].push(m.name);else{delete i[o];break}}}return i}function h4(n,l,r,i){const{data:o}=a4(l),{data:u}=es(l);return b.useMemo(()=>{const d=d4(u,n==null?void 0:n.columns);return{name:r,tabId:i,hooks:(()=>{const m=[];if(!o||!n||!n.columns)return m;for(const y of o)(n.tables.includes(y.on.toTable)||n.tables.includes(y.on.fromTable))&&m.push(y);return m})(),availableJoins:(()=>{const m=[];if(!o||!n||!n.columns)return m;for(const y of o)!n.tables.includes(y.on.toTable)&&n.tables.includes(y.on.fromTable)&&m.push(y);return m})(),allColumns:(n==null?void 0:n.allColumns)||[],dataSourceId:l,entities:Object.keys(d),getValue:(m,y)=>{var S;const p=ta(y),g=(S=n==null?void 0:n.columns)==null?void 0:S.findIndex(E=>E.full===p);if(g!=null&&g>-1)return m[g]},getEntityKey:(m,y)=>d[m].reduce((p,g)=>{var E;const S=(E=n==null?void 0:n.columns)==null?void 0:E.findIndex(C=>C.column===g&&C.table===m);return S!=null&&S>-1&&p.push([g,y[S]]),p},[]),getColumnType:m=>{const y=n==null?void 0:n.allColumns.find(p=>p.full===m);if(y)return y.type}}},[n,l,o,u,r])}function m4(n,l){return b.useMemo(()=>({state:n,setState:l}),[n,l])}function fr(n){return{dataSourceId:n.dataSourceId||"",table:n.table||"",filters:(n==null?void 0:n.filters)||[],joins:(n==null?void 0:n.joins)??[],orderBy:(n==null?void 0:n.orderBy)??[],page:(n==null?void 0:n.page)||0,size:(n==null?void 0:n.size)||50,columns:(n==null?void 0:n.columns)??[],groupBy:(n==null?void 0:n.groupBy)??[],aggregations:(n==null?void 0:n.aggregations)??[]}}function p4(n,l,r){try{const i=r.getItem(n);if(i)return JSON.parse(i)}catch(i){console.warn("Failed to restore tabs",i)}return l}const th=({storage:n=localStorage,localStorageKey:l,initialData:r})=>{const i=It(p4(l,r,n));return i[2].subscribe(o=>{n.setItem(l,JSON.stringify(o))}),i},Ua=()=>Date.now().toString(36)+Math.random().toString(36).substring(2),[Au,Tu,Ru]=th({initialData:[],localStorageKey:"open-tabs__v1"}),[y4,Ad,v4]=th({initialData:"",localStorageKey:"active-tabs",storage:sessionStorage}),g4=n=>{setTimeout(l=>{const r=document.querySelector(`[data-tab-id="${l}"]`);r&&r.scrollIntoView({behavior:"smooth"})},50,n)},yl=(n,l,r=!1)=>{x4();const i=b4({label:n,type:"explorer",id:Ua(),options:fr(l)});r&&nh(i.id)},qy=n=>{const l=v4.get();if(Tu(r=>r.filter(i=>i.id!==n)),l===n){const r=Ru.get();r.length>0?Ad(r[0].id):Ad("")}},nh=n=>{Ad(n),g4(n)},Ou=(n,l)=>{Tu(r=>r.map(i=>i.id===n?{...i,label:l}:i))};function b4(n){return Tu(l=>l?[...l,n]:[n]),n}const zy=20;function x4(){if(Ru.get().length>=zy){const l=`Maximum ${zy} tabs are allowed to be open at the same time. Please close other tabs to open new ones.`;throw qt.error(l),new Error(l)}}const Ue={home:{path:"/"},workbench:{path:"/workbench"},share:{path:"/share"},login:{path:"/login"}},x1=async n=>pt.fetchQuery({queryKey:["query",n],queryFn:async()=>{const{data:l}=await Ve.get("/queries/"+n);return l.data}}),[S4,ad,w4]=It(void 0),E4=async()=>new Promise(n=>{ad({onCancel:()=>{ad(void 0),n(void 0)},onConfirm:(l,r,i)=>{ad(void 0),n({dsId:i,id:r,type:l})}})}),xr=n=>{const l=Pt();return b.useCallback(()=>{w4.get()||E4().then(i=>{(i==null?void 0:i.type)==="table"?(yl(i.id,fr({table:i.id,dataSourceId:i.dsId}),!0),location.pathname!==Ue.workbench.path&&l(Ue.workbench.path)):(i==null?void 0:i.type)==="query"&&x1(i.id).then(o=>{yl(o.name,fr(o.opts),!0),location.pathname!==Ue.workbench.path&&l(Ue.workbench.path)})})},[l,n])},Sr=n=>{const{data:l}=sa();return b.useMemo(()=>l?Ly[l.teamRole]>=Ly[n]:!1,[l,n])},C4="_input_ez0gl_2",_4="_small_ez0gl_2",j4="_content_ez0gl_2",N4="_form_ez0gl_2",A4="_mode-select_ez0gl_2",ze={input:C4,small:_4,content:j4,form:N4,switch:"_switch_ez0gl_2",modeSelect:A4},T4="_modal_zmowj_2",R4="_modal-visible_zmowj_2",O4="_modal-invisible_zmowj_2",D4="_backdrop_zmowj_2",M4="_modal-container_zmowj_2",U4="_close-button_zmowj_2",Hi={modal:T4,modalVisible:R4,modalInvisible:O4,backdrop:D4,modalContainer:M4,closeButton:U4},Qn=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"})),Yt=({children:n,backdropClose:l,isVisible:r,onClose:i,onClosed:o,noPadding:u=!1,portal:d=!1})=>{const[m,y]=b.useState(!1),p=()=>{l&&i()},g=E=>{r||getComputedStyle(E.currentTarget).opacity==="0"&&(y(!1),o&&o())};b.useEffect(()=>{r&&y(!0)},[r]);const S=h.jsxs("div",{onTransitionEnd:g,className:se(Hi.modal,r?Hi.modalVisible:Hi.modalInvisible),children:[h.jsx("div",{onClick:p,className:Hi.backdrop}),h.jsx("div",{className:se(Hi.modalContainer,u!==!0&&"p-4"),children:m&&n})]});return d?Nv.createPortal(S,document.body):S},On=({onClick:n})=>{const l=b.useRef(n);return l.current=n,b.useEffect(()=>{const r=i=>{var o;i.key==="Escape"&&((o=l.current)==null||o.call(l))};return window.addEventListener("keyup",r),()=>{window.removeEventListener("keyup",r)}},[]),h.jsx("button",{className:Hi.closeButton,onClick:n,children:h.jsx(Qn,{width:20,height:20})})},S1=({children:n})=>h.jsx("h2",{className:"text-xl font-semibold",children:n}),wr=n=>{const[l,r]=b.useState(n),[i,o]=b.useState([]),u=b.useRef(n),d=b.useCallback((p,g)=>{r(S=>({...S,[p]:g}))},[]),m=b.useCallback(p=>g=>{g.target.type==="checkbox"?d(p,g.target.checked):d(p,g.target.value),o(S=>S.includes(p)?S:[...S,p])},[d]),y=b.useCallback(()=>{r(u.current),o([])},[]);return[l,{set:d,change:m,reset:y,touched:i}]},L4=({form:n,change:l})=>h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:se(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:se(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:se(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:se(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:se(ze.input,ze.small),children:[h.jsx("label",{children:"Database"}),h.jsx("input",{value:n.dbDatabase,onChange:l("dbDatabase"),className:"input"})]})]}),q4=({form:n,change:l})=>h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:se(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:se(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:se(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:se(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:se(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:se(ze.input,ze.small),children:[h.jsx("label",{children:"Schema"}),h.jsx("input",{value:n.dbSchema,onChange:l("dbSchema"),className:"input"})]})]}),qi=[{label:"PostgreSQL",tag:"postgres"},{label:"MySQL",tag:"mysql"}],z4=({show:n,onClose:l,dbType:r="postgres"})=>{const i=G3(),o=y1(),{data:u}=sa(),[d,{change:m,set:y}]=wr({name:"",dbType:r,dbUrl:"",dbUser:"",dbPassword:"",dbDatabase:"",dbSchema:"",dbPort:5432,teamId:"",ownerId:"",description:"",allowInsert:!1,allowUpdate:!1}),p=async()=>{const w=await i.mutateAsync({...d,dbPort:Number(d.dbPort),teamId:u.teamId,ownerId:u.id});await o.mutateAsync(w.id),l(),K3.event("Create Datasource",{dbType:d.dbType})},g=w=>{y("allowInsert",!w),y("allowUpdate",!w)},S=()=>{l()},E=i.isLoading||o.isLoading,C=!d.allowInsert&&!d.allowUpdate;return h.jsxs(Yt,{isVisible:n,onClose:S,children:[h.jsx(On,{onClick:S}),h.jsxs(Lt,{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"}),"."]}),i.isError&&h.jsx(Lt,{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."})}),i.isLoading&&h.jsx(Lt,{className:"mb-2",variant:"info",children:"Creating connection"}),o.isLoading&&h.jsx(Lt,{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===qi[0].tag,onChange:()=>y("dbType",qi[0].tag)}),h.jsx("span",{children:qi[0].label})]}),h.jsxs("label",{className:"button tertiary",children:[h.jsx("input",{type:"radio",name:"bdType",className:"mr-2",checked:d.dbType===qi[1].tag,onChange:()=>y("dbType",qi[1].tag)}),h.jsx("span",{children:qi[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:se(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:se(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(L4,{form:d,change:m}),d.dbType==="postgres"&&h.jsx(q4,{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:()=>g(!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:()=>g(!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:S,className:"button tertiary",disabled:E,children:"Cancel"}),h.jsx("button",{onClick:p,className:"button primary",disabled:E,children:"Create"})]})]})},B4="_data-source-entry_2aje2_2",H4="_action-title_2aje2_2",k4="_action-subtext_2aje2_2",na={dataSourceEntry:B4,actionTitle:H4,actionSubtext:k4},Q4=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"})),Y4=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"}})),ah=({size:n,type:l})=>l==="mysql"?h.jsx(Q4,{width:n,height:n}):h.jsx(Y4,{width:n,height:n}),[V4,Yi]=It(void 0),K4=()=>{const n=xr("Home");return h.jsxs("div",{className:"card-white lg:col-span-2",onClick:n,children:[h.jsxs("h2",{className:na.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"})]})},G4=()=>{const[n,l]=b.useState(void 0),r=Sr(Xt.EDITOR),i=o=>{r?l(o):qt.error("You don't have permission to connect new data sources in this team")};return h.jsxs("div",{children:[n&&h.jsx(z4,{show:!0,dbType:n,onClose:()=>l(void 0)}),h.jsxs("div",{className:"card-white hover:bg-gray-50! cursor-pointer",onClick:()=>i("postgres"),children:[h.jsx("p",{className:na.actionTitle,children:"🧙♂️ Connection wizard"}),h.jsx("p",{className:na.actionSubtext,children:"Configure new database connection."})]})]})},F4=()=>{const n=Pt(),l=Au(),r=xr("Home"),i=()=>{l.length>0?n(Ue.workbench.path):r()};return h.jsxs("div",{className:"card-white hover:bg-gray-50! cursor-pointer",onClick:i,children:[h.jsxs("h2",{className:na.actionTitle,children:[h.jsx("span",{children:"🛠️ Workbench"}),h.jsx("span",{className:"hotkey",children:"W"})]}),h.jsx("p",{className:na.actionSubtext,children:"Continue your work from where you left."})]})},$4=()=>{const{data:n}=sa(),{data:l}=Pd({teamId:n==null?void 0:n.teamId}),r=i=>{Yi(i)};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-2 gap-2 mt-4",children:l==null?void 0:l.map(i=>h.jsxs("div",{className:na.dataSourceEntry,onClick:()=>r(i.id),tabIndex:0,children:[h.jsx(ah,{size:32,type:i.dbType}),h.jsx("p",{className:"font-semibold truncate text-gray-800 flex-1",children:i.name}),i.allowInsert?h.jsx("span",{className:"text-red-700",children:"Development"}):h.jsx("span",{className:"text-blue-700",children:"Production"})]},i.id))})]})},X4=()=>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-2 gap-2 mt-4",children:[h.jsxs("a",{className:"card-white hover:bg-gray-50!",href:"https://dataramen.xyz/",children:[h.jsx("p",{className:na.actionTitle,children:"Documentation"}),h.jsx("p",{className:na.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("p",{className:na.actionTitle,children:"Github"}),h.jsx("p",{className:na.actionSubtext,children:"Codebase is open sourced on Github"})]})]})]}),Z4=()=>{const{data:n}=sa(),{data:l}=Pd({teamId:n==null?void 0:n.teamId}),r=!!l&&l.length>0,i=!!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"}),i&&!r&&h.jsx(Lt,{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(K4,{}),h.jsx(G4,{}),i&&h.jsx(F4,{})]}),i&&h.jsx($4,{}),h.jsx(X4,{})]})})},[J4,lh]=It(void 0),P4=()=>lh(void 0);function Gl(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 I4=n=>{var r;const l=((r=n.value)==null?void 0:r.map(i=>i.value).join(", "))||"";return`${n.column} ${n.operator} ${l}`},hl=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,r=>r.toUpperCase()),l},W4="_container_1xayy_2",eE="_header_1xayy_2",tE="_fields-container_1xayy_2",nE="_field-label_1xayy_2",aE="_actions_1xayy_2",lr={container:W4,header:eE,fieldsContainer:tE,fieldLabel:nE,actions:aE},lE=(n,l)=>{const{datasourceId:r,opts:{searchAll:i,table:o,filters:u,joins:d,orderBy:m,groupBy:y,columns:p},page:g=0,size:S=20}=n;return fn({queryKey:["explorer",r,o,g,S,u,d,m,y,p,i],queryFn:async()=>{const{data:E}=await Ve.post("/runner/select",n);return E.data},retry:1,enabled:!!o&&!!r,keepPreviousData:!0,staleTime:0,cacheTime:0,onSuccess:l})},iE=(n,l,r)=>fn({queryKey:["entity",n,l,r],queryFn:async()=>{const i=r?r.map(([u,d])=>({id:Ua(),column:u,operator:"=",value:[{value:d}],connector:"AND"})):[],{data:o}=await Ve.post("/runner/select",{datasourceId:n,opts:{table:l,filters:i,joins:[],columns:[],orderBy:[],groupBy:[],aggregations:[]},size:1,page:0,name:`Select ${l}: [${r==null?void 0:r.join()}]`});return o.data},retry:1,enabled:!!l&&!!n&&!!r,staleTime:0,cacheTime:0}),sE=()=>cn({mutationFn:async n=>{const{data:l}=await Ve.post("/runner/update",n);return l.data}}),rE=()=>cn({mutationFn:async n=>{const{data:l}=await Ve.post("/runner/insert",n);return l.data}}),ih=n=>b.useMemo(()=>{var l,r,i;if(n)return n instanceof Kw?(l=n.response)!=null&&l.data.error?n.response.data.error:(i=(r=n.response)==null?void 0:r.data)!=null&&i.message?n.response.data.message:n.message:n instanceof Error?n.message:"Undefined error"},[n]),oE=({data:n})=>{const[l,{change:r,touched:i}]=wr({}),{mutateAsync:o,error:u}=rE(),d=ih(u),{data:m}=es(n.dataSourceId),[y,p]=b.useState(""),g=b.useMemo(()=>m==null?void 0:m.find(C=>C.tableName===n.table),[m,n.table]),S=b.useMemo(()=>{if(!g)return[];if(!y)return g.columns.map(w=>({...w,label:hl(w.name)}));const C=y.toLowerCase();return g.columns.filter(w=>w.name.toLowerCase().includes(C)).map(w=>({...w,label:hl(w.name)}))},[y,g]),E=()=>{const C=[];for(const w of i)C.push({value:l[w],column:w});o({datasourceId:n.dataSourceId,table:n.table,values:C}).then(P4)};return h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:lr.header,children:[h.jsxs("p",{className:"text-lg font-semibold",children:["Insert new row in ",h.jsx("span",{className:"underline",children:n.table})]}),d&&h.jsx(Lt,{variant:"danger",children:h.jsx("p",{children:d})})]}),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:lr.container,children:h.jsx("div",{className:lr.fieldsContainer,children:S.map(C=>h.jsxs("label",{className:lr.fieldLabel,children:[h.jsxs("div",{className:"flex justify-between",children:[h.jsxs("p",{children:[C.isPrimary?"🔐":"🏷️"," ",C.label]}),h.jsxs("p",{className:"text-blue-800 text-sm",children:["[",C.name,": ",C.type,"]"]})]}),h.jsx("input",{className:"input w-full",value:Gl(l[C.name]),onChange:r(C.name),placeholder:C.name})]},C.name))})}),h.jsxs("div",{className:lr.actions,children:[h.jsxs("label",{children:[h.jsx("span",{className:"mr-2",children:"🔎"}),h.jsx("input",{className:"input bg-white!",value:y,onChange:C=>p(C.target.value),placeholder:"Filter columns"})]}),h.jsx("span",{className:"flex-1"}),h.jsx("button",{disabled:!i.length,className:"button primary",onClick:E,children:"Run insert"})]})]})},uE=()=>{const n=J4(),[l,r]=b.useState(void 0);b.useEffect(()=>{n&&r(n)},[n]);const i=()=>lh(void 0);return h.jsxs(Yt,{isVisible:n!=null,onClose:i,onClosed:()=>r(void 0),noPadding:!0,children:[h.jsx(On,{onClick:i}),l&&h.jsx(oE,{data:l})]})},[cE,sh]=It(void 0),fE=()=>sh(void 0),dE="_container_16rc1_2",hE="_header_16rc1_2",mE="_key_16rc1_2",pE="_fields-container_16rc1_2",yE="_field-label_16rc1_2",vE="_actions_16rc1_2",zi={container:dE,header:hE,key:mE,fieldsContainer:pE,fieldLabel:yE,actions:vE},gE=({data:n})=>{const[l,{change:r,set:i,reset:o,touched:u}]=wr({}),[d,m]=b.useState(""),{data:y,isLoading:p}=iE(n.dataSourceId,n.tableName,n.entityId),{mutateAsync:g,error:S}=sE(),E=ih(S),C=Sr(Xt.EDITOR),{data:w}=es(n.dataSourceId),{data:A}=Nu(n.dataSourceId),j=b.useMemo(()=>w==null?void 0:w.find(H=>H.tableName===n.tableName),[n.tableName,w]),_=b.useMemo(()=>{if(!j)return[];if(!d)return j.columns.map($=>({...$,label:hl($.name)}));const H=d.toLowerCase();return j.columns.filter($=>$.name.toLowerCase().includes(H)).map($=>({...$,label:hl($.name)}))},[d,j]);b.useEffect(()=>{const H=y==null?void 0:y.rows[0];if(o(),H&&(y!=null&&y.columns))for(let $=0;$<y.columns.length;$++){const I=y.columns[$];i(I.column,Gl(H[$]))}},[y,i,o]);const O=()=>{const H=[];for(const $ of u)H.push({value:l[$],column:$});g({datasourceId:n.dataSourceId,table:n.tableName,filters:n.entityId.map($=>({id:Ua(),value:[{value:$[1]}],column:$[0],connector:"AND",operator:"="})),values:H}).then(fE)},D=n.entityId.map(([H,$])=>`${H} = ${$}`).join(", ")||"",Y=!(A!=null&&A.allowUpdate)||!C;return h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:zi.header,children:[h.jsxs("p",{className:"text-lg font-semibold",children:[Y?"View":"Edit"," row in ",h.jsx("span",{className:"underline",children:n==null?void 0:n.tableName})]}),h.jsx("span",{className:zi.key,children:D}),E&&h.jsx(Lt,{variant:"danger",children:h.jsx("p",{children:E})})]}),!Y&&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:zi.container,children:h.jsx("div",{className:zi.fieldsContainer,children:_.map(H=>h.jsxs("label",{className:zi.fieldLabel,children:[h.jsxs("div",{className:"flex justify-between",children:[h.jsxs("p",{children:[H.isPrimary?"🔐":"🏷️"," ",H.label]}),h.jsxs("p",{className:"text-blue-800 text-sm",children:["[",H.name,": ",H.type,"]"]})]}),h.jsx("input",{disabled:H.isPrimary||p||Y,className:"input w-full",value:Gl(l[H.name]),onChange:r(H.name),placeholder:H.name})]},H.name))})}),h.jsxs("div",{className:zi.actions,children:[h.jsxs("label",{children:[h.jsx("span",{className:"mr-2",children:"🔎"}),h.jsx("input",{className:"input bg-white!",value:d,onChange:H=>m(H.target.value),placeholder:"Filter columns"})]}),h.jsx("span",{className:"flex-1"}),!Y&&h.jsx("button",{disabled:!u.length,className:"button primary",onClick:O,children:"Run update"})]})]})},bE=()=>{const n=cE(),[l,r]=b.useState(void 0);b.useEffect(()=>{n&&r(n)},[n]);const i=()=>sh(void 0);return h.jsxs(Yt,{isVisible:n!=null,onClose:i,onClosed:()=>r(void 0),noPadding:!0,children:[h.jsx(On,{onClick:i}),l&&h.jsx(gE,{data:l})]})},[xE,ld]=It(void 0),w1=async n=>new Promise(l=>{ld({message:n,onCancel:()=>{l(!1),ld(void 0)},onConfirm:()=>{l(!0),ld(void 0)}})}),SE=({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"})]})]}),wE=()=>{const n=xE(),[l,r]=b.useState(void 0);return b.useEffect(()=>{n&&r(n)},[n]),h.jsx(Yt,{isVisible:!!n,onClose:()=>n==null?void 0:n.onCancel(),onClosed:()=>r(void 0),children:l&&h.jsx(SE,{confirm:l})})},[EE,Io]=It(void 0),Pl=async(n,l,r)=>new Promise(i=>{Io({message:n,defaultValue:l,alert:r,onCancel:()=>{Io(void 0),i(void 0)},onConfirm:o=>{Io(void 0),i(o)}})}),CE="_root_12mtw_1",_E={root:CE},jE=({data:n})=>{const[l,r]=b.useState("");b.useEffect(()=>{n.defaultValue&&r(n.defaultValue)},[n]);const i=u=>{r(u.target.value)},o=u=>{u.key==="Enter"&&(u.preventDefault(),n.onConfirm(l)),u.key==="Escape"&&(u.preventDefault(),n.onCancel())};return h.jsxs("div",{className:_E.root,children:[h.jsx("h2",{className:"text-xl font-semibold",children:n.message}),n.alert&&h.jsx(Lt,{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:i,onKeyDown:o}),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"})]})]})},NE=()=>{const n=EE(),[l,r]=b.useState(void 0);return b.useEffect(()=>{n&&r(n)},[n]),h.jsx(Yt,{isVisible:!!n,onClose:()=>Io(void 0),onClosed:()=>r(void 0),children:l&&h.jsx(jE,{data:l})})},[AE,TE]=It(void 0),E1=n=>{TE(n)},RE="_textarea_1tcsp_2",OE={textarea:RE},DE=()=>{const n=AE(),l=()=>{n&&(navigator.clipboard.writeText(n.toString()),qt.success("Copied!"))},r=()=>E1(void 0);return h.jsxs(Yt,{isVisible:!!n,onClose:r,backdropClose:!0,children:[h.jsx("textarea",{className:OE.textarea,readOnly:!0,defaultValue:n==null?void 0: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:r,children:"Close"})]})]})},ME="_tabs_13stu_2",UE="_mobile_13stu_2",LE="_tab_13stu_2",qE="_active_13stu_2",zE="_close-button_13stu_2",BE="_tooltip-label_13stu_2",HE="_tooltip-info-entry_13stu_2",ea={tabs:ME,mobile:UE,tab:LE,active:qE,closeButton:zE,tooltipLabel:BE,tooltipInfoEntry:HE},Vi=Math.min,Fl=Math.max,fu=Math.round,Ho=Math.floor,aa=n=>({x:n,y:n}),kE={left:"right",right:"left",bottom:"top",top:"bottom"},QE={start:"end",end:"start"};function Td(n,l,r){return Fl(n,Vi(l,r))}function Er(n,l){return typeof n=="function"?n(l):n}function Xl(n){return n.split("-")[0]}function Cr(n){return n.split("-")[1]}function C1(n){return n==="x"?"y":"x"}function rh(n){return n==="y"?"height":"width"}function ml(n){return["top","bottom"].includes(Xl(n))?"y":"x"}function oh(n){return C1(ml(n))}function YE(n,l,r){r===void 0&&(r=!1);const i=Cr(n),o=oh(n),u=rh(o);let d=o==="x"?i===(r?"end":"start")?"right":"left":i==="start"?"bottom":"top";return l.reference[u]>l.floating[u]&&(d=du(d)),[d,du(d)]}function VE(n){const l=du(n);return[Rd(n),l,Rd(l)]}function Rd(n){return n.replace(/start|end/g,l=>QE[l])}function KE(n,l,r){const i=["left","right"],o=["right","left"],u=["top","bottom"],d=["bottom","top"];switch(n){case"top":case"bottom":return r?l?o:i:l?i:o;case"left":case"right":return l?u:d;default:return[]}}function GE(n,l,r,i){const o=Cr(n);let u=KE(Xl(n),r==="start",i);return o&&(u=u.map(d=>d+"-"+o),l&&(u=u.concat(u.map(Rd)))),u}function du(n){return n.replace(/left|right|bottom|top/g,l=>kE[l])}function FE(n){return{top:0,right:0,bottom:0,left:0,...n}}function _1(n){return typeof n!="number"?FE(n):{top:n,right:n,bottom:n,left:n}}function hu(n){const{x:l,y:r,width:i,height:o}=n;return{width:i,height:o,top:r,left:l,right:l+i,bottom:r+o,x:l,y:r}}function By(n,l,r){let{reference:i,floating:o}=n;const u=ml(l),d=oh(l),m=rh(d),y=Xl(l),p=u==="y",g=i.x+i.width/2-o.width/2,S=i.y+i.height/2-o.height/2,E=i[m]/2-o[m]/2;let C;switch(y){case"top":C={x:g,y:i.y-o.height};break;case"bottom":C={x:g,y:i.y+i.height};break;case"right":C={x:i.x+i.width,y:S};break;case"left":C={x:i.x-o.width,y:S};break;default:C={x:i.x,y:i.y}}switch(Cr(l)){case"start":C[d]-=E*(r&&p?-1:1);break;case"end":C[d]+=E*(r&&p?-1:1);break}return C}const $E=async(n,l,r)=>{const{placement:i="bottom",strategy:o="absolute",middleware:u=[],platform:d}=r,m=u.filter(Boolean),y=await(d.isRTL==null?void 0:d.isRTL(l));let p=await d.getElementRects({reference:n,floating:l,strategy:o}),{x:g,y:S}=By(p,i,y),E=i,C={},w=0;for(let A=0;A<m.length;A++){const{name:j,fn:_}=m[A],{x:O,y:D,data:Y,reset:H}=await _({x:g,y:S,initialPlacement:i,placement:E,strategy:o,middlewareData:C,rects:p,platform:d,elements:{reference:n,floating:l}});g=O??g,S=D??S,C={...C,[j]:{...C[j],...Y}},H&&w<=50&&(w++,typeof H=="object"&&(H.placement&&(E=H.placement),H.rects&&(p=H.rects===!0?await d.getElementRects({reference:n,floating:l,strategy:o}):H.rects),{x:g,y:S}=By(p,E,y)),A=-1)}return{x:g,y:S,placement:E,strategy:o,middlewareData:C}};async function j1(n,l){var r;l===void 0&&(l={});const{x:i,y:o,platform:u,rects:d,elements:m,strategy:y}=n,{boundary:p="clippingAncestors",rootBoundary:g="viewport",elementContext:S="floating",altBoundary:E=!1,padding:C=0}=Er(l,n),w=_1(C),j=m[E?S==="floating"?"reference":"floating":S],_=hu(await u.getClippingRect({element:(r=await(u.isElement==null?void 0:u.isElement(j)))==null||r?j:j.contextElement||await(u.getDocumentElement==null?void 0:u.getDocumentElement(m.floating)),boundary:p,rootBoundary:g,strategy:y})),O=S==="floating"?{x:i,y:o,width:d.floating.width,height:d.floating.height}:d.reference,D=await(u.getOffsetParent==null?void 0:u.getOffsetParent(m.floating)),Y=await(u.isElement==null?void 0:u.isElement(D))?await(u.getScale==null?void 0:u.getScale(D))||{x:1,y:1}:{x:1,y:1},H=hu(u.convertOffsetParentRelativeRectToViewportRelativeRect?await u.convertOffsetParentRelativeRectToViewportRelativeRect({elements:m,rect:O,offsetParent:D,strategy:y}):O);return{top:(_.top-H.top+w.top)/Y.y,bottom:(H.bottom-_.bottom+w.bottom)/Y.y,left:(_.left-H.left+w.left)/Y.x,right:(H.right-_.right+w.right)/Y.x}}const XE=n=>({name:"arrow",options:n,async fn(l){const{x:r,y:i,placement:o,rects:u,platform:d,elements:m,middlewareData:y}=l,{element:p,padding:g=0}=Er(n,l)||{};if(p==null)return{};const S=_1(g),E={x:r,y:i},C=oh(o),w=rh(C),A=await d.getDimensions(p),j=C==="y",_=j?"top":"left",O=j?"bottom":"right",D=j?"clientHeight":"clientWidth",Y=u.reference[w]+u.reference[C]-E[C]-u.floating[w],H=E[C]-u.reference[C],$=await(d.getOffsetParent==null?void 0:d.getOffsetParent(p));let I=$?$[D]:0;(!I||!await(d.isElement==null?void 0:d.isElement($)))&&(I=m.floating[D]||u.floating[w]);const W=Y/2-H/2,re=I/2-A[w]/2-1,pe=Vi(S[_],re),Be=Vi(S[O],re),Ee=pe,Fe=I-A[w]-Be,ye=I/2-A[w]/2+W,xe=Td(Ee,ye,Fe),B=!y.arrow&&Cr(o)!=null&&ye!==xe&&u.reference[w]/2-(ye<Ee?pe:Be)-A[w]/2<0,F=B?ye<Ee?ye-Ee:ye-Fe:0;return{[C]:E[C]+F,data:{[C]:xe,centerOffset:ye-xe-F,...B&&{alignmentOffset:F}},reset:B}}}),ZE=function(n){return n===void 0&&(n={}),{name:"flip",options:n,async fn(l){var r,i;const{placement:o,middlewareData:u,rects:d,initialPlacement:m,platform:y,elements:p}=l,{mainAxis:g=!0,crossAxis:S=!0,fallbackPlacements:E,fallbackStrategy:C="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:A=!0,...j}=Er(n,l);if((r=u.arrow)!=null&&r.alignmentOffset)return{};const _=Xl(o),O=ml(m),D=Xl(m)===m,Y=await(y.isRTL==null?void 0:y.isRTL(p.floating)),H=E||(D||!A?[du(m)]:VE(m)),$=w!=="none";!E&&$&&H.push(...GE(m,A,w,Y));const I=[m,...H],W=await j1(l,j),re=[];let pe=((i=u.flip)==null?void 0:i.overflows)||[];if(g&&re.push(W[_]),S){const ye=YE(o,d,Y);re.push(W[ye[0]],W[ye[1]])}if(pe=[...pe,{placement:o,overflows:re}],!re.every(ye=>ye<=0)){var Be,Ee;const ye=(((Be=u.flip)==null?void 0:Be.index)||0)+1,xe=I[ye];if(xe&&(!(S==="alignment"?O!==ml(xe):!1)||pe.every(Z=>Z.overflows[0]>0&&ml(Z.placement)===O)))return{data:{index:ye,overflows:pe},reset:{placement:xe}};let B=(Ee=pe.filter(F=>F.overflows[0]<=0).sort((F,Z)=>F.overflows[1]-Z.overflows[1])[0])==null?void 0:Ee.placement;if(!B)switch(C){case"bestFit":{var Fe;const F=(Fe=pe.filter(Z=>{if($){const ue=ml(Z.placement);return ue===O||ue==="y"}return!0}).map(Z=>[Z.placement,Z.overflows.filter(ue=>ue>0).reduce((ue,T)=>ue+T,0)]).sort((Z,ue)=>Z[1]-ue[1])[0])==null?void 0:Fe[0];F&&(B=F);break}case"initialPlacement":B=m;break}if(o!==B)return{reset:{placement:B}}}return{}}}};async function JE(n,l){const{placement:r,platform:i,elements:o}=n,u=await(i.isRTL==null?void 0:i.isRTL(o.floating)),d=Xl(r),m=Cr(r),y=ml(r)==="y",p=["left","top"].includes(d)?-1:1,g=u&&y?-1:1,S=Er(l,n);let{mainAxis:E,crossAxis:C,alignmentAxis:w}=typeof S=="number"?{mainAxis:S,crossAxis:0,alignmentAxis:null}:{mainAxis:S.mainAxis||0,crossAxis:S.crossAxis||0,alignmentAxis:S.alignmentAxis};return m&&typeof w=="number"&&(C=m==="end"?w*-1:w),y?{x:C*g,y:E*p}:{x:E*p,y:C*g}}const PE=function(n){return n===void 0&&(n=0),{name:"offset",options:n,async fn(l){var r,i;const{x:o,y:u,placement:d,middlewareData:m}=l,y=await JE(l,n);return d===((r=m.offset)==null?void 0:r.placement)&&(i=m.arrow)!=null&&i.alignmentOffset?{}:{x:o+y.x,y:u+y.y,data:{...y,placement:d}}}}},IE=function(n){return n===void 0&&(n={}),{name:"shift",options:n,async fn(l){const{x:r,y:i,placement:o}=l,{mainAxis:u=!0,crossAxis:d=!1,limiter:m={fn:j=>{let{x:_,y:O}=j;return{x:_,y:O}}},...y}=Er(n,l),p={x:r,y:i},g=await j1(l,y),S=ml(Xl(o)),E=C1(S);let C=p[E],w=p[S];if(u){const j=E==="y"?"top":"left",_=E==="y"?"bottom":"right",O=C+g[j],D=C-g[_];C=Td(O,C,D)}if(d){const j=S==="y"?"top":"left",_=S==="y"?"bottom":"right",O=w+g[j],D=w-g[_];w=Td(O,w,D)}const A=m.fn({...l,[E]:C,[S]:w});return{...A,data:{x:A.x-r,y:A.y-i,enabled:{[E]:u,[S]:d}}}}}};function Du(){return typeof window<"u"}function ns(n){return N1(n)?(n.nodeName||"").toLowerCase():"#document"}function un(n){var l;return(n==null||(l=n.ownerDocument)==null?void 0:l.defaultView)||window}function ra(n){var l;return(l=(N1(n)?n.ownerDocument:n.document)||window.document)==null?void 0:l.documentElement}function N1(n){return Du()?n instanceof Node||n instanceof un(n).Node:!1}function zn(n){return Du()?n instanceof Element||n instanceof un(n).Element:!1}function la(n){return Du()?n instanceof HTMLElement||n instanceof un(n).HTMLElement:!1}function Hy(n){return!Du()||typeof ShadowRoot>"u"?!1:n instanceof ShadowRoot||n instanceof un(n).ShadowRoot}function _r(n){const{overflow:l,overflowX:r,overflowY:i,display:o}=Bn(n);return/auto|scroll|overlay|hidden|clip/.test(l+i+r)&&!["inline","contents"].includes(o)}function WE(n){return["table","td","th"].includes(ns(n))}function Mu(n){return[":popover-open",":modal"].some(l=>{try{return n.matches(l)}catch{return!1}})}function uh(n){const l=ch(),r=zn(n)?Bn(n):n;return["transform","translate","scale","rotate","perspective"].some(i=>r[i]?r[i]!=="none":!1)||(r.containerType?r.containerType!=="normal":!1)||!l&&(r.backdropFilter?r.backdropFilter!=="none":!1)||!l&&(r.filter?r.filter!=="none":!1)||["transform","translate","scale","rotate","perspective","filter"].some(i=>(r.willChange||"").includes(i))||["paint","layout","strict","content"].some(i=>(r.contain||"").includes(i))}function eC(n){let l=vl(n);for(;la(l)&&!Ki(l);){if(uh(l))return l;if(Mu(l))return null;l=vl(l)}return null}function ch(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function Ki(n){return["html","body","#document"].includes(ns(n))}function Bn(n){return un(n).getComputedStyle(n)}function Uu(n){return zn(n)?{scrollLeft:n.scrollLeft,scrollTop:n.scrollTop}:{scrollLeft:n.scrollX,scrollTop:n.scrollY}}function vl(n){if(ns(n)==="html")return n;const l=n.assignedSlot||n.parentNode||Hy(n)&&n.host||ra(n);return Hy(l)?l.host:l}function A1(n){const l=vl(n);return Ki(l)?n.ownerDocument?n.ownerDocument.body:n.body:la(l)&&_r(l)?l:A1(l)}function dr(n,l,r){var i;l===void 0&&(l=[]),r===void 0&&(r=!0);const o=A1(n),u=o===((i=n.ownerDocument)==null?void 0:i.body),d=un(o);if(u){const m=Od(d);return l.concat(d,d.visualViewport||[],_r(o)?o:[],m&&r?dr(m):[])}return l.concat(o,dr(o,[],r))}function Od(n){return n.parent&&Object.getPrototypeOf(n.parent)?n.frameElement:null}function T1(n){const l=Bn(n);let r=parseFloat(l.width)||0,i=parseFloat(l.height)||0;const o=la(n),u=o?n.offsetWidth:r,d=o?n.offsetHeight:i,m=fu(r)!==u||fu(i)!==d;return m&&(r=u,i=d),{width:r,height:i,$:m}}function fh(n){return zn(n)?n:n.contextElement}function Qi(n){const l=fh(n);if(!la(l))return aa(1);const r=l.getBoundingClientRect(),{width:i,height:o,$:u}=T1(l);let d=(u?fu(r.width):r.width)/i,m=(u?fu(r.height):r.height)/o;return(!d||!Number.isFinite(d))&&(d=1),(!m||!Number.isFinite(m))&&(m=1),{x:d,y:m}}const tC=aa(0);function R1(n){const l=un(n);return!ch()||!l.visualViewport?tC:{x:l.visualViewport.offsetLeft,y:l.visualViewport.offsetTop}}function nC(n,l,r){return l===void 0&&(l=!1),!r||l&&r!==un(n)?!1:l}function Zl(n,l,r,i){l===void 0&&(l=!1),r===void 0&&(r=!1);const o=n.getBoundingClientRect(),u=fh(n);let d=aa(1);l&&(i?zn(i)&&(d=Qi(i)):d=Qi(n));const m=nC(u,r,i)?R1(u):aa(0);let y=(o.left+m.x)/d.x,p=(o.top+m.y)/d.y,g=o.width/d.x,S=o.height/d.y;if(u){const E=un(u),C=i&&zn(i)?un(i):i;let w=E,A=Od(w);for(;A&&i&&C!==w;){const j=Qi(A),_=A.getBoundingClientRect(),O=Bn(A),D=_.left+(A.clientLeft+parseFloat(O.paddingLeft))*j.x,Y=_.top+(A.clientTop+parseFloat(O.paddingTop))*j.y;y*=j.x,p*=j.y,g*=j.x,S*=j.y,y+=D,p+=Y,w=un(A),A=Od(w)}}return hu({width:g,height:S,x:y,y:p})}function dh(n,l){const r=Uu(n).scrollLeft;return l?l.left+r:Zl(ra(n)).left+r}function O1(n,l,r){r===void 0&&(r=!1);const i=n.getBoundingClientRect(),o=i.left+l.scrollLeft-(r?0:dh(n,i)),u=i.top+l.scrollTop;return{x:o,y:u}}function aC(n){let{elements:l,rect:r,offsetParent:i,strategy:o}=n;const u=o==="fixed",d=ra(i),m=l?Mu(l.floating):!1;if(i===d||m&&u)return r;let y={scrollLeft:0,scrollTop:0},p=aa(1);const g=aa(0),S=la(i);if((S||!S&&!u)&&((ns(i)!=="body"||_r(d))&&(y=Uu(i)),la(i))){const C=Zl(i);p=Qi(i),g.x=C.x+i.clientLeft,g.y=C.y+i.clientTop}const E=d&&!S&&!u?O1(d,y,!0):aa(0);return{width:r.width*p.x,height:r.height*p.y,x:r.x*p.x-y.scrollLeft*p.x+g.x+E.x,y:r.y*p.y-y.scrollTop*p.y+g.y+E.y}}function lC(n){return Array.from(n.getClientRects())}function iC(n){const l=ra(n),r=Uu(n),i=n.ownerDocument.body,o=Fl(l.scrollWidth,l.clientWidth,i.scrollWidth,i.clientWidth),u=Fl(l.scrollHeight,l.clientHeight,i.scrollHeight,i.clientHeight);let d=-r.scrollLeft+dh(n);const m=-r.scrollTop;return Bn(i).direction==="rtl"&&(d+=Fl(l.clientWidth,i.clientWidth)-o),{width:o,height:u,x:d,y:m}}function sC(n,l){const r=un(n),i=ra(n),o=r.visualViewport;let u=i.clientWidth,d=i.clientHeight,m=0,y=0;if(o){u=o.width,d=o.height;const p=ch();(!p||p&&l==="fixed")&&(m=o.offsetLeft,y=o.offsetTop)}return{width:u,height:d,x:m,y}}function rC(n,l){const r=Zl(n,!0,l==="fixed"),i=r.top+n.clientTop,o=r.left+n.clientLeft,u=la(n)?Qi(n):aa(1),d=n.clientWidth*u.x,m=n.clientHeight*u.y,y=o*u.x,p=i*u.y;return{width:d,height:m,x:y,y:p}}function ky(n,l,r){let i;if(l==="viewport")i=sC(n,r);else if(l==="document")i=iC(ra(n));else if(zn(l))i=rC(l,r);else{const o=R1(n);i={x:l.x-o.x,y:l.y-o.y,width:l.width,height:l.height}}return hu(i)}function D1(n,l){const r=vl(n);return r===l||!zn(r)||Ki(r)?!1:Bn(r).position==="fixed"||D1(r,l)}function oC(n,l){const r=l.get(n);if(r)return r;let i=dr(n,[],!1).filter(m=>zn(m)&&ns(m)!=="body"),o=null;const u=Bn(n).position==="fixed";let d=u?vl(n):n;for(;zn(d)&&!Ki(d);){const m=Bn(d),y=uh(d);!y&&m.position==="fixed"&&(o=null),(u?!y&&!o:!y&&m.position==="static"&&!!o&&["absolute","fixed"].includes(o.position)||_r(d)&&!y&&D1(n,d))?i=i.filter(g=>g!==d):o=m,d=vl(d)}return l.set(n,i),i}function uC(n){let{element:l,boundary:r,rootBoundary:i,strategy:o}=n;const d=[...r==="clippingAncestors"?Mu(l)?[]:oC(l,this._c):[].concat(r),i],m=d[0],y=d.reduce((p,g)=>{const S=ky(l,g,o);return p.top=Fl(S.top,p.top),p.right=Vi(S.right,p.right),p.bottom=Vi(S.bottom,p.bottom),p.left=Fl(S.left,p.left),p},ky(l,m,o));return{width:y.right-y.left,height:y.bottom-y.top,x:y.left,y:y.top}}function cC(n){const{width:l,height:r}=T1(n);return{width:l,height:r}}function fC(n,l,r){const i=la(l),o=ra(l),u=r==="fixed",d=Zl(n,!0,u,l);let m={scrollLeft:0,scrollTop:0};const y=aa(0);function p(){y.x=dh(o)}if(i||!i&&!u)if((ns(l)!=="body"||_r(o))&&(m=Uu(l)),i){const C=Zl(l,!0,u,l);y.x=C.x+l.clientLeft,y.y=C.y+l.clientTop}else o&&p();u&&!i&&o&&p();const g=o&&!i&&!u?O1(o,m):aa(0),S=d.left+m.scrollLeft-y.x-g.x,E=d.top+m.scrollTop-y.y-g.y;return{x:S,y:E,width:d.width,height:d.height}}function id(n){return Bn(n).position==="static"}function Qy(n,l){if(!la(n)||Bn(n).position==="fixed")return null;if(l)return l(n);let r=n.offsetParent;return ra(n)===r&&(r=r.ownerDocument.body),r}function M1(n,l){const r=un(n);if(Mu(n))return r;if(!la(n)){let o=vl(n);for(;o&&!Ki(o);){if(zn(o)&&!id(o))return o;o=vl(o)}return r}let i=Qy(n,l);for(;i&&WE(i)&&id(i);)i=Qy(i,l);return i&&Ki(i)&&id(i)&&!uh(i)?r:i||eC(n)||r}const dC=async function(n){const l=this.getOffsetParent||M1,r=this.getDimensions,i=await r(n.floating);return{reference:fC(n.reference,await l(n.floating),n.strategy),floating:{x:0,y:0,width:i.width,height:i.height}}};function hC(n){return Bn(n).direction==="rtl"}const mC={convertOffsetParentRelativeRectToViewportRelativeRect:aC,getDocumentElement:ra,getClippingRect:uC,getOffsetParent:M1,getElementRects:dC,getClientRects:lC,getDimensions:cC,getScale:Qi,isElement:zn,isRTL:hC};function U1(n,l){return n.x===l.x&&n.y===l.y&&n.width===l.width&&n.height===l.height}function pC(n,l){let r=null,i;const o=ra(n);function u(){var m;clearTimeout(i),(m=r)==null||m.disconnect(),r=null}function d(m,y){m===void 0&&(m=!1),y===void 0&&(y=1),u();const p=n.getBoundingClientRect(),{left:g,top:S,width:E,height:C}=p;if(m||l(),!E||!C)return;const w=Ho(S),A=Ho(o.clientWidth-(g+E)),j=Ho(o.clientHeight-(S+C)),_=Ho(g),D={rootMargin:-w+"px "+-A+"px "+-j+"px "+-_+"px",threshold:Fl(0,Vi(1,y))||1};let Y=!0;function H($){const I=$[0].intersectionRatio;if(I!==y){if(!Y)return d();I?d(!1,I):i=setTimeout(()=>{d(!1,1e-7)},1e3)}I===1&&!U1(p,n.getBoundingClientRect())&&d(),Y=!1}try{r=new IntersectionObserver(H,{...D,root:o.ownerDocument})}catch{r=new IntersectionObserver(H,D)}r.observe(n)}return d(!0),u}function yC(n,l,r,i){i===void 0&&(i={});const{ancestorScroll:o=!0,ancestorResize:u=!0,elementResize:d=typeof ResizeObserver=="function",layoutShift:m=typeof IntersectionObserver=="function",animationFrame:y=!1}=i,p=fh(n),g=o||u?[...p?dr(p):[],...dr(l)]:[];g.forEach(_=>{o&&_.addEventListener("scroll",r,{passive:!0}),u&&_.addEventListener("resize",r)});const S=p&&m?pC(p,r):null;let E=-1,C=null;d&&(C=new ResizeObserver(_=>{let[O]=_;O&&O.target===p&&C&&(C.unobserve(l),cancelAnimationFrame(E),E=requestAnimationFrame(()=>{var D;(D=C)==null||D.observe(l)})),r()}),p&&!y&&C.observe(p),C.observe(l));let w,A=y?Zl(n):null;y&&j();function j(){const _=Zl(n);A&&!U1(A,_)&&r(),A=_,w=requestAnimationFrame(j)}return r(),()=>{var _;g.forEach(O=>{o&&O.removeEventListener("scroll",r),u&&O.removeEventListener("resize",r)}),S==null||S(),(_=C)==null||_.disconnect(),C=null,y&&cancelAnimationFrame(w)}}const vC=PE,gC=IE,bC=ZE,xC=XE,Yy=(n,l,r)=>{const i=new Map,o={platform:mC,...r},u={...o.platform,_c:i};return $E(n,l,{...o,platform:u})};var sd={exports:{}};/*!
|
|
232
|
+
`,Bo=16,L3=({reverseOrder:n,position:l="top-center",toastOptions:r,gutter:i,children:o,containerStyle:u,containerClassName:d})=>{let{toasts:m,handlers:y}=u3(r);return b.createElement("div",{id:"_rht_toaster",style:{position:"fixed",zIndex:9999,top:Bo,left:Bo,right:Bo,bottom:Bo,pointerEvents:"none",...u},className:d,onMouseEnter:y.startPause,onMouseLeave:y.endPause},m.map(p=>{let g=p.position||l,S=y.calculateOffset(p,{reverseOrder:n,gutter:i,defaultPosition:l}),E=M3(g,S);return b.createElement(D3,{id:p.id,key:p.id,onHeightUpdate:y.updateHeight,className:p.visible?U3:"",style:E},p.type==="custom"?cu(p.message,p):o?o(p):b.createElement(O3,{toast:p,position:g}))}))},qt=Qt;const pt=new aS({defaultOptions:{queries:{staleTime:1e3*60*5,retry:(n,l)=>{var r;return uu(l)&&((r=l.response)==null?void 0:r.status)===404?!1:n<3}}},mutationCache:new Lv({onError:n=>{var l;uu(n)&&n.status&&n.status>=400&&n.status<500&&(l=n.response)!=null&&l.data.error&&qt.error(n.response.data.error)}})}),q3=async()=>{const{data:n}=await Zd.post("/auth/refresh");return n.data.accessToken},z3=async n=>{const{data:l}=await Zd.post("/auth/login",n);return l.data.accessToken},nd=()=>{pt.invalidateQueries({queryKey:["accessToken"]})},br=(()=>{let n=Promise.resolve(Gw()),l=!1;const r=async()=>{await Zd.post("/auth/logout"),zo(void 0),window.location.reload()};return{get:async()=>n.then(d=>(nd(),d)),refresh:()=>(l||(l=!0,n=q3().then(d=>(zo(d),d)).catch(()=>{zo(void 0),r()}).finally(()=>{l=!1,nd()})),n),login:d=>(l||(l=!0,n=z3(d).then(m=>(zo(m),m)).finally(()=>{l=!1,nd()})),n),logout:r}})(),p1=location.hostname.includes("app.dataramen.xyz")?"http://localhost:4466/api":"/api",Ve=lt.create({baseURL:p1,withCredentials:!0});Ve.interceptors.request.use(async n=>{const l=await br.get();return l&&(n.headers.Authorization=`Bearer ${l}`),n});Ve.interceptors.response.use(n=>n,n=>{var l;return uu(n)&&n.status===401&&((l=n==null?void 0:n.response)==null?void 0:l.data.error)!=="Missing auth token"&&br.refresh(),Promise.reject(n)});const Zd=lt.create({baseURL:p1,withCredentials:!0}),La="data-sources",Jd="auth-user",B3=n=>fn({queryKey:["project","datasources",n],queryFn:async()=>{const{data:l}=await Ve.get(`/project/team/${n}/datasources`);return l.data},enabled:!!n}),H3=n=>fn({queryKey:["project","saved-queries",n],queryFn:async()=>{const{data:l}=await Ve.get(`/project/team/${n}/queries`);return l.data},enabled:!!n}),Wi=n=>{const l=["project","datasources"],r=["project","saved-queries"];return Promise.all([pt.invalidateQueries(l),pt.invalidateQueries(r)])},k3=n=>{const l=["trash","team"];return pt.invalidateQueries(l)},Q3=(n,l)=>fn({queryKey:["project",l.teamId,"tables",n,l.selectedDataSources],queryFn:async()=>{const{data:r}=await Ve.get(`/project/team/${l.teamId}/query`,{params:{size:30,search:n,selectedDataSources:l.selectedDataSources}});return r.data},enabled:!!l.teamId,staleTime:0,keepPreviousData:!0}),Y3=(n,l)=>{},V3=()=>{},K3={event:Y3,pageView:V3},Nu=n=>fn([La,n],async()=>{const{data:l}=await Ve.get("/data-sources/"+n);return l.data},{enabled:!!n}),Pd=n=>fn({queryKey:[La,n.teamId],queryFn:async()=>{const{data:l}=await Ve.get("/data-sources",{params:n});return l.data},enabled:n.teamId!==void 0}),es=n=>fn({queryKey:[La,n,"inspections"],queryFn:async()=>{const{data:l}=await Ve.get(`/data-sources/${n}/inspections`);return l.data},enabled:!!n}),G3=()=>cn(async n=>{const{data:l}=await Ve.post("/data-sources",n);return l.data},{onSuccess:()=>{pt.invalidateQueries([La]),Wi()},onError:()=>{}}),F3=()=>cn({mutationFn:async({dataSource:n,id:l})=>{const{data:r}=await Ve.put(`/data-sources/${l}`,n);return r.data},onSuccess:()=>{pt.invalidateQueries([La]),Wi()}}),y1=()=>cn({mutationFn:async n=>{await Ve.post(`/data-sources/${n}/inspect`)},onSuccess:()=>{pt.invalidateQueries([La])}}),$3=()=>cn({mutationFn:async n=>{await Ve.delete(`/data-sources/${n}`)},onSuccess:()=>{pt.invalidateQueries([La]),Wi()}}),v1=()=>fn(["accessToken"],br.get),sa=()=>{const{data:n}=v1();return fn({queryKey:[Jd],queryFn:async()=>{const{data:l}=await Ve.get("/users");return l.data},enabled:!!n,retry:(l,r)=>uu(r)&&r.code==="ERR_NETWORK"?!1:l<3})},X3=()=>cn({mutationFn:async n=>{const{data:l}=await Ve.patch("/users",n);return l.data},onSuccess:async n=>{pt.setQueryData([Jd],n)}}),Z3=()=>cn({mutationFn:async n=>(await Ve.post("/users",n),!0),onSuccess:()=>{pt.invalidateQueries({queryKey:["team-users"]})}}),J3="_alert_6qdub_2",P3="_info_6qdub_2",I3="_danger_6qdub_2",W3="_success_6qdub_2",e4="_warning_6qdub_2",t4="_dark_6qdub_2",Li={alert:J3,info:P3,danger:I3,success:W3,warning:e4,dark:t4};function g1(n){var l,r,i="";if(typeof n=="string"||typeof n=="number")i+=n;else if(typeof n=="object")if(Array.isArray(n)){var o=n.length;for(l=0;l<o;l++)n[l]&&(r=g1(n[l]))&&(i&&(i+=" "),i+=r)}else for(r in n)n[r]&&(i&&(i+=" "),i+=r);return i}function se(){for(var n,l,r=0,i="",o=arguments.length;r<o;r++)(n=arguments[r])&&(l=g1(n))&&(i&&(i+=" "),i+=l);return i}const Lt=({variant:n,noRounded:l,className:r,children:i,...o})=>h.jsx("div",{className:se(Li.alert,!l&&"rounded-lg",(n==="info"||!n)&&Li.info,n==="danger"&&Li.danger,n==="dark"&&Li.dark,n==="warning"&&Li.warning,n==="success"&&Li.success,r),role:"alert",...o,children:i}),It=n=>{const l=new Set;let r=n;const i=m=>(l.add(m),()=>l.delete(m)),o=m=>(l.forEach(y=>y(m)),!0),u=m=>{r=typeof m=="function"?m(r):m,o(r)},d=m=>()=>m?m(r):r;return[m=>b.useSyncExternalStore(i,d(m),d(m)),u,{get:()=>r,subscribe:m=>(m(r),i(m))}]};function n4(n){const l=[];for(const r of n)for(const i of r.columns)i.ref&&(l.push({id:`${r.tableName}->${i.ref.table}.${i.ref.field}`,name:`${r.tableName} in ${i.ref.table}`,where:`${r.tableName}.${i.name} = ${i.ref.table}.${i.ref.field}`,on:{fromTable:i.ref.table,toTable:r.tableName,fromColumn:i.ref.field,toColumn:i.name}}),l.push({id:`${i.ref.table}->${r.tableName}.${i.name}`,name:`${i.ref.table} in ${r.tableName}`,where:`${i.ref.table}.${i.ref.field} = ${r.tableName}.${i.name}`,on:{fromTable:r.tableName,toTable:i.ref.table,fromColumn:i.name,toColumn:i.ref.field}}));return l}const a4=n=>fn({queryKey:["hooks",n],queryFn:async()=>{const l=await pt.fetchQuery({queryKey:[La,n,"inspections"],queryFn:async()=>{const{data:r}=await Ve.get(`/data-sources/${n}/inspections`);return r.data}});return n4(l)},enabled:!!n}),Id=[{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"}],Wd=Id.reduce((n,l)=>(n[l.value]=l.label,n),{}),eh=Id.reduce((n,l)=>(n[l.label]=l.value,n),{}),ts=n=>n.map(l=>({label:Wd[l],value:l})),l4=ts(["=","<>",">",">=","<","<=","IN","NOT IN","IS NULL","IS NOT NULL"]),i4=ts(["=","<>","LIKE","NOT LIKE","IN","NOT IN","IS NULL","IS NOT NULL"]);ts(["=","<>","IS NULL","IS NOT NULL"]);const s4=ts(["=","<>",">",">=","<","<=","IS NULL","IS NOT NULL"]);ts(["IS NULL","IS NOT NULL"]);ts(["IN","NOT IN"]);const b1=n=>n!=="IS NULL"&&n!=="IS NOT NULL",r4=(n,l)=>b1(n)?n==="IN"||n==="NOT IN"?l.split(",").map(r=>({value:r.trim(),isColumn:!1})):[{value:l,isColumn:!1}]:[],o4=["char","varchar","binary","varbinary","blob","text","enum","set","character","character varying","text","citext","uuid","xml","json","jsonb"],u4=["integer","smallint","decimal","numeric","float","real","double precision","int","smallint","integer","bigint","decimal","numeric","real","double precision","serial","bigserial","money"],c4=["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"],f4=["date","datetime","timestamp","timestamptz"].reduce((n,l)=>(n[l]=!0,n),{}),ta=n=>n.fn?n.distinct===!0?`${n.fn} distinct ${n.value}`:`${n.fn} ${n.value}`:n.value;var Xt=(n=>(n.OWNER="owner",n.ADMIN="admin",n.EDITOR="editor",n.READ_ONLY="read_only",n))(Xt||{});const Ly={[Xt.READ_ONLY]:10,[Xt.EDITOR]:20,[Xt.ADMIN]:30,[Xt.OWNER]:40};function d4(n,l){if(!n||!l)return{};const r=new Set;for(const o of l)o.table&&r.add(o.table);const i={};for(const o of r){const u=n.find(d=>d.tableName===o);if(u){i[o]=[];const d=u.columns.filter(m=>m.isPrimary);for(const m of d)if(l.find(p=>p.table===o&&p.column===m.name))i[o].push(m.name);else{delete i[o];break}}}return i}function h4(n,l,r,i){const{data:o}=a4(l),{data:u}=es(l);return b.useMemo(()=>{const d=d4(u,n==null?void 0:n.columns);return{name:r,tabId:i,hooks:(()=>{const m=[];if(!o||!n||!n.columns)return m;for(const y of o)(n.tables.includes(y.on.toTable)||n.tables.includes(y.on.fromTable))&&m.push(y);return m})(),availableJoins:(()=>{const m=[];if(!o||!n||!n.columns)return m;for(const y of o)!n.tables.includes(y.on.toTable)&&n.tables.includes(y.on.fromTable)&&m.push(y);return m})(),allColumns:(n==null?void 0:n.allColumns)||[],dataSourceId:l,entities:Object.keys(d),getValue:(m,y)=>{var S;const p=ta(y),g=(S=n==null?void 0:n.columns)==null?void 0:S.findIndex(E=>E.full===p);if(g!=null&&g>-1)return m[g]},getEntityKey:(m,y)=>d[m].reduce((p,g)=>{var E;const S=(E=n==null?void 0:n.columns)==null?void 0:E.findIndex(C=>C.column===g&&C.table===m);return S!=null&&S>-1&&p.push([g,y[S]]),p},[]),getColumnType:m=>{const y=n==null?void 0:n.allColumns.find(p=>p.full===m);if(y)return y.type}}},[n,l,o,u,r])}function m4(n,l){return b.useMemo(()=>({state:n,setState:l}),[n,l])}function fr(n){return{dataSourceId:n.dataSourceId||"",table:n.table||"",filters:(n==null?void 0:n.filters)||[],joins:(n==null?void 0:n.joins)??[],orderBy:(n==null?void 0:n.orderBy)??[],page:(n==null?void 0:n.page)||0,size:(n==null?void 0:n.size)||50,columns:(n==null?void 0:n.columns)??[],groupBy:(n==null?void 0:n.groupBy)??[],aggregations:(n==null?void 0:n.aggregations)??[]}}function p4(n,l,r){try{const i=r.getItem(n);if(i)return JSON.parse(i)}catch(i){console.warn("Failed to restore tabs",i)}return l}const th=({storage:n=localStorage,localStorageKey:l,initialData:r})=>{const i=It(p4(l,r,n));return i[2].subscribe(o=>{n.setItem(l,JSON.stringify(o))}),i},Ua=()=>Date.now().toString(36)+Math.random().toString(36).substring(2),[Au,Tu,Ru]=th({initialData:[],localStorageKey:"open-tabs__v1"}),[y4,Ad,v4]=th({initialData:"",localStorageKey:"active-tabs",storage:sessionStorage}),g4=n=>{setTimeout(l=>{const r=document.querySelector(`[data-tab-id="${l}"]`);r&&r.scrollIntoView({behavior:"smooth"})},50,n)},yl=(n,l,r=!1)=>{x4();const i=b4({label:n,type:"explorer",id:Ua(),options:fr(l)});r&&nh(i.id)},qy=n=>{const l=v4.get();if(Tu(r=>r.filter(i=>i.id!==n)),l===n){const r=Ru.get();r.length>0?Ad(r[0].id):Ad("")}},nh=n=>{Ad(n),g4(n)},Ou=(n,l)=>{Tu(r=>r.map(i=>i.id===n?{...i,label:l}:i))};function b4(n){return Tu(l=>l?[...l,n]:[n]),n}const zy=20;function x4(){if(Ru.get().length>=zy){const l=`Maximum ${zy} tabs are allowed to be open at the same time. Please close other tabs to open new ones.`;throw qt.error(l),new Error(l)}}const Ue={home:{path:"/"},workbench:{path:"/workbench"},share:{path:"/share"},login:{path:"/login"}},x1=async n=>pt.fetchQuery({queryKey:["query",n],queryFn:async()=>{const{data:l}=await Ve.get("/queries/"+n);return l.data}}),[S4,ad,w4]=It(void 0),E4=async()=>new Promise(n=>{ad({onCancel:()=>{ad(void 0),n(void 0)},onConfirm:(l,r,i)=>{ad(void 0),n({dsId:i,id:r,type:l})}})}),xr=n=>{const l=Pt();return b.useCallback(()=>{w4.get()||E4().then(i=>{(i==null?void 0:i.type)==="table"?(yl(i.id,fr({table:i.id,dataSourceId:i.dsId}),!0),location.pathname!==Ue.workbench.path&&l(Ue.workbench.path)):(i==null?void 0:i.type)==="query"&&x1(i.id).then(o=>{yl(o.name,fr(o.opts),!0),location.pathname!==Ue.workbench.path&&l(Ue.workbench.path)})})},[l,n])},Sr=n=>{const{data:l}=sa();return b.useMemo(()=>l?Ly[l.teamRole]>=Ly[n]:!1,[l,n])},C4="_input_ez0gl_2",_4="_small_ez0gl_2",j4="_content_ez0gl_2",N4="_form_ez0gl_2",A4="_mode-select_ez0gl_2",ze={input:C4,small:_4,content:j4,form:N4,switch:"_switch_ez0gl_2",modeSelect:A4},T4="_modal_zmowj_2",R4="_modal-visible_zmowj_2",O4="_modal-invisible_zmowj_2",D4="_backdrop_zmowj_2",M4="_modal-container_zmowj_2",U4="_close-button_zmowj_2",Hi={modal:T4,modalVisible:R4,modalInvisible:O4,backdrop:D4,modalContainer:M4,closeButton:U4},Qn=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"})),Yt=({children:n,backdropClose:l,isVisible:r,onClose:i,onClosed:o,noPadding:u=!1,portal:d=!1})=>{const[m,y]=b.useState(!1),p=()=>{l&&i()},g=E=>{r||getComputedStyle(E.currentTarget).opacity==="0"&&(y(!1),o&&o())};b.useEffect(()=>{r&&y(!0)},[r]);const S=h.jsxs("div",{onTransitionEnd:g,className:se(Hi.modal,r?Hi.modalVisible:Hi.modalInvisible),children:[h.jsx("div",{onClick:p,className:Hi.backdrop}),h.jsx("div",{className:se(Hi.modalContainer,u!==!0&&"p-4"),children:m&&n})]});return d?Nv.createPortal(S,document.body):S},On=({onClick:n})=>{const l=b.useRef(n);return l.current=n,b.useEffect(()=>{const r=i=>{var o;i.key==="Escape"&&((o=l.current)==null||o.call(l))};return window.addEventListener("keyup",r),()=>{window.removeEventListener("keyup",r)}},[]),h.jsx("button",{className:Hi.closeButton,onClick:n,children:h.jsx(Qn,{width:20,height:20})})},S1=({children:n})=>h.jsx("h2",{className:"text-xl font-semibold",children:n}),wr=n=>{const[l,r]=b.useState(n),[i,o]=b.useState([]),u=b.useRef(n),d=b.useCallback((p,g)=>{r(S=>({...S,[p]:g}))},[]),m=b.useCallback(p=>g=>{g.target.type==="checkbox"?d(p,g.target.checked):d(p,g.target.value),o(S=>S.includes(p)?S:[...S,p])},[d]),y=b.useCallback(()=>{r(u.current),o([])},[]);return[l,{set:d,change:m,reset:y,touched:i}]},L4=({form:n,change:l})=>h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:se(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:se(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:se(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:se(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:se(ze.input,ze.small),children:[h.jsx("label",{children:"Database"}),h.jsx("input",{value:n.dbDatabase,onChange:l("dbDatabase"),className:"input"})]})]}),q4=({form:n,change:l})=>h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:se(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:se(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:se(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:se(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:se(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:se(ze.input,ze.small),children:[h.jsx("label",{children:"Schema"}),h.jsx("input",{value:n.dbSchema,onChange:l("dbSchema"),className:"input"})]})]}),qi=[{label:"PostgreSQL",tag:"postgres"},{label:"MySQL",tag:"mysql"}],z4=({show:n,onClose:l,dbType:r="postgres"})=>{const i=G3(),o=y1(),{data:u}=sa(),[d,{change:m,set:y}]=wr({name:"",dbType:r,dbUrl:"",dbUser:"",dbPassword:"",dbDatabase:"",dbSchema:"",dbPort:5432,teamId:"",ownerId:"",description:"",allowInsert:!1,allowUpdate:!1}),p=async()=>{const w=await i.mutateAsync({...d,dbPort:Number(d.dbPort),teamId:u.teamId,ownerId:u.id});await o.mutateAsync(w.id),l(),K3.event("Create Datasource",{dbType:d.dbType})},g=w=>{y("allowInsert",!w),y("allowUpdate",!w)},S=()=>{l()},E=i.isLoading||o.isLoading,C=!d.allowInsert&&!d.allowUpdate;return h.jsxs(Yt,{isVisible:n,onClose:S,children:[h.jsx(On,{onClick:S}),h.jsxs(Lt,{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"}),"."]}),i.isError&&h.jsx(Lt,{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."})}),i.isLoading&&h.jsx(Lt,{className:"mb-2",variant:"info",children:"Creating connection"}),o.isLoading&&h.jsx(Lt,{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===qi[0].tag,onChange:()=>y("dbType",qi[0].tag)}),h.jsx("span",{children:qi[0].label})]}),h.jsxs("label",{className:"button tertiary",children:[h.jsx("input",{type:"radio",name:"bdType",className:"mr-2",checked:d.dbType===qi[1].tag,onChange:()=>y("dbType",qi[1].tag)}),h.jsx("span",{children:qi[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:se(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:se(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(L4,{form:d,change:m}),d.dbType==="postgres"&&h.jsx(q4,{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:()=>g(!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:()=>g(!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:S,className:"button tertiary",disabled:E,children:"Cancel"}),h.jsx("button",{onClick:p,className:"button primary",disabled:E,children:"Create"})]})]})},B4="_data-source-entry_2aje2_2",H4="_action-title_2aje2_2",k4="_action-subtext_2aje2_2",na={dataSourceEntry:B4,actionTitle:H4,actionSubtext:k4},Q4=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"})),Y4=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"}})),ah=({size:n,type:l})=>l==="mysql"?h.jsx(Q4,{width:n,height:n}):h.jsx(Y4,{width:n,height:n}),[V4,Yi]=It(void 0),K4=()=>{const n=xr("Home");return h.jsxs("div",{className:"card-white lg:col-span-2",onClick:n,children:[h.jsxs("h2",{className:na.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"})]})},G4=()=>{const[n,l]=b.useState(void 0),r=Sr(Xt.EDITOR),i=o=>{r?l(o):qt.error("You don't have permission to connect new data sources in this team")};return h.jsxs("div",{children:[n&&h.jsx(z4,{show:!0,dbType:n,onClose:()=>l(void 0)}),h.jsxs("div",{className:"card-white hover:bg-gray-50! cursor-pointer",onClick:()=>i("postgres"),children:[h.jsx("p",{className:na.actionTitle,children:"🧙♂️ Connection wizard"}),h.jsx("p",{className:na.actionSubtext,children:"Configure new database connection."})]})]})},F4=()=>{const n=Pt(),l=Au(),r=xr("Home"),i=()=>{l.length>0?n(Ue.workbench.path):r()};return h.jsxs("div",{className:"card-white hover:bg-gray-50! cursor-pointer",onClick:i,children:[h.jsxs("h2",{className:na.actionTitle,children:[h.jsx("span",{children:"🛠️ Workbench"}),h.jsx("span",{className:"hotkey",children:"W"})]}),h.jsx("p",{className:na.actionSubtext,children:"Continue your work from where you left."})]})},$4=()=>{const{data:n}=sa(),{data:l}=Pd({teamId:n==null?void 0:n.teamId}),r=i=>{Yi(i)};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-2 gap-2 mt-4",children:l==null?void 0:l.map(i=>h.jsxs("div",{className:na.dataSourceEntry,onClick:()=>r(i.id),tabIndex:0,children:[h.jsx(ah,{size:32,type:i.dbType}),h.jsx("p",{className:"font-semibold truncate text-gray-800 flex-1",children:i.name}),i.allowInsert?h.jsx("span",{className:"text-red-700",children:"Development"}):h.jsx("span",{className:"text-blue-700",children:"Production"})]},i.id))})]})},X4=()=>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-2 gap-2 mt-4",children:[h.jsxs("a",{className:"card-white hover:bg-gray-50!",href:"https://dataramen.xyz/",children:[h.jsx("p",{className:na.actionTitle,children:"Documentation"}),h.jsx("p",{className:na.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("p",{className:na.actionTitle,children:"Github"}),h.jsx("p",{className:na.actionSubtext,children:"Codebase is open sourced on Github"})]})]})]}),Z4=()=>{const{data:n}=sa(),{data:l}=Pd({teamId:n==null?void 0:n.teamId}),r=!!l&&l.length>0,i=!!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"}),i&&!r&&h.jsx(Lt,{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(K4,{}),h.jsx(G4,{}),i&&h.jsx(F4,{})]}),i&&h.jsx($4,{}),h.jsx(X4,{})]})})},[J4,lh]=It(void 0),P4=()=>lh(void 0);function Gl(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 I4=n=>{var r;const l=((r=n.value)==null?void 0:r.map(i=>i.value).join(", "))||"";return`${n.column} ${n.operator} ${l}`},hl=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,r=>r.toUpperCase()),l},W4="_container_1xayy_2",eE="_header_1xayy_2",tE="_fields-container_1xayy_2",nE="_field-label_1xayy_2",aE="_actions_1xayy_2",lr={container:W4,header:eE,fieldsContainer:tE,fieldLabel:nE,actions:aE},lE=(n,l)=>{const{datasourceId:r,opts:{searchAll:i,table:o,filters:u,joins:d,orderBy:m,groupBy:y,columns:p},page:g=0,size:S=20}=n;return fn({queryKey:["explorer",r,o,g,S,u,d,m,y,p,i],queryFn:async()=>{const{data:E}=await Ve.post("/runner/select",n);return E.data},retry:1,enabled:!!o&&!!r,keepPreviousData:!0,staleTime:0,cacheTime:0,onSuccess:l})},iE=(n,l,r)=>fn({queryKey:["entity",n,l,r],queryFn:async()=>{const i=r?r.map(([u,d])=>({id:Ua(),column:u,operator:"=",value:[{value:d}],connector:"AND"})):[],{data:o}=await Ve.post("/runner/select",{datasourceId:n,opts:{table:l,filters:i,joins:[],columns:[],orderBy:[],groupBy:[],aggregations:[]},size:1,page:0,name:`Select ${l}: [${r==null?void 0:r.join()}]`});return o.data},retry:1,enabled:!!l&&!!n&&!!r,staleTime:0,cacheTime:0}),sE=()=>cn({mutationFn:async n=>{const{data:l}=await Ve.post("/runner/update",n);return l.data}}),rE=()=>cn({mutationFn:async n=>{const{data:l}=await Ve.post("/runner/insert",n);return l.data}}),ih=n=>b.useMemo(()=>{var l,r,i;if(n)return n instanceof Kw?(l=n.response)!=null&&l.data.error?n.response.data.error:(i=(r=n.response)==null?void 0:r.data)!=null&&i.message?n.response.data.message:n.message:n instanceof Error?n.message:"Undefined error"},[n]),oE=({data:n})=>{const[l,{change:r,touched:i}]=wr({}),{mutateAsync:o,error:u}=rE(),d=ih(u),{data:m}=es(n.dataSourceId),[y,p]=b.useState(""),g=b.useMemo(()=>m==null?void 0:m.find(C=>C.tableName===n.table),[m,n.table]),S=b.useMemo(()=>{if(!g)return[];if(!y)return g.columns.map(w=>({...w,label:hl(w.name)}));const C=y.toLowerCase();return g.columns.filter(w=>w.name.toLowerCase().includes(C)).map(w=>({...w,label:hl(w.name)}))},[y,g]),E=()=>{const C=[];for(const w of i)C.push({value:l[w],column:w});o({datasourceId:n.dataSourceId,table:n.table,values:C}).then(P4)};return h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:lr.header,children:[h.jsxs("p",{className:"text-lg font-semibold",children:["Insert new row in ",h.jsx("span",{className:"underline",children:n.table})]}),d&&h.jsx(Lt,{variant:"danger",children:h.jsx("p",{children:d})})]}),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:lr.container,children:h.jsx("div",{className:lr.fieldsContainer,children:S.map(C=>h.jsxs("label",{className:lr.fieldLabel,children:[h.jsxs("div",{className:"flex justify-between",children:[h.jsxs("p",{children:[C.isPrimary?"🔐":"🏷️"," ",C.label]}),h.jsxs("p",{className:"text-blue-800 text-sm",children:["[",C.name,": ",C.type,"]"]})]}),h.jsx("input",{className:"input w-full",value:Gl(l[C.name]),onChange:r(C.name),placeholder:C.name})]},C.name))})}),h.jsxs("div",{className:lr.actions,children:[h.jsxs("label",{children:[h.jsx("span",{className:"mr-2",children:"🔎"}),h.jsx("input",{className:"input bg-white!",value:y,onChange:C=>p(C.target.value),placeholder:"Filter columns"})]}),h.jsx("span",{className:"flex-1"}),h.jsx("button",{disabled:!i.length,className:"button primary",onClick:E,children:"Run insert"})]})]})},uE=()=>{const n=J4(),[l,r]=b.useState(void 0);b.useEffect(()=>{n&&r(n)},[n]);const i=()=>lh(void 0);return h.jsxs(Yt,{isVisible:n!=null,onClose:i,onClosed:()=>r(void 0),noPadding:!0,children:[h.jsx(On,{onClick:i}),l&&h.jsx(oE,{data:l})]})},[cE,sh]=It(void 0),fE=()=>sh(void 0),dE="_container_16rc1_2",hE="_header_16rc1_2",mE="_key_16rc1_2",pE="_fields-container_16rc1_2",yE="_field-label_16rc1_2",vE="_actions_16rc1_2",zi={container:dE,header:hE,key:mE,fieldsContainer:pE,fieldLabel:yE,actions:vE},gE=({data:n})=>{const[l,{change:r,set:i,reset:o,touched:u}]=wr({}),[d,m]=b.useState(""),{data:y,isLoading:p}=iE(n.dataSourceId,n.tableName,n.entityId),{mutateAsync:g,error:S}=sE(),E=ih(S),C=Sr(Xt.EDITOR),{data:w}=es(n.dataSourceId),{data:A}=Nu(n.dataSourceId),j=b.useMemo(()=>w==null?void 0:w.find(H=>H.tableName===n.tableName),[n.tableName,w]),_=b.useMemo(()=>{if(!j)return[];if(!d)return j.columns.map($=>({...$,label:hl($.name)}));const H=d.toLowerCase();return j.columns.filter($=>$.name.toLowerCase().includes(H)).map($=>({...$,label:hl($.name)}))},[d,j]);b.useEffect(()=>{const H=y==null?void 0:y.rows[0];if(o(),H&&(y!=null&&y.columns))for(let $=0;$<y.columns.length;$++){const I=y.columns[$];i(I.column,Gl(H[$]))}},[y,i,o]);const O=()=>{const H=[];for(const $ of u)H.push({value:l[$],column:$});g({datasourceId:n.dataSourceId,table:n.tableName,filters:n.entityId.map($=>({id:Ua(),value:[{value:$[1]}],column:$[0],connector:"AND",operator:"="})),values:H}).then(fE)},D=n.entityId.map(([H,$])=>`${H} = ${$}`).join(", ")||"",Y=!(A!=null&&A.allowUpdate)||!C;return h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:zi.header,children:[h.jsxs("p",{className:"text-lg font-semibold",children:[Y?"View":"Edit"," row in ",h.jsx("span",{className:"underline",children:n==null?void 0:n.tableName})]}),h.jsx("span",{className:zi.key,children:D}),E&&h.jsx(Lt,{variant:"danger",children:h.jsx("p",{children:E})})]}),!Y&&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:zi.container,children:h.jsx("div",{className:zi.fieldsContainer,children:_.map(H=>h.jsxs("label",{className:zi.fieldLabel,children:[h.jsxs("div",{className:"flex justify-between",children:[h.jsxs("p",{children:[H.isPrimary?"🔐":"🏷️"," ",H.label]}),h.jsxs("p",{className:"text-blue-800 text-sm",children:["[",H.name,": ",H.type,"]"]})]}),h.jsx("input",{disabled:H.isPrimary||p||Y,className:"input w-full",value:Gl(l[H.name]),onChange:r(H.name),placeholder:H.name})]},H.name))})}),h.jsxs("div",{className:zi.actions,children:[h.jsxs("label",{children:[h.jsx("span",{className:"mr-2",children:"🔎"}),h.jsx("input",{className:"input bg-white!",value:d,onChange:H=>m(H.target.value),placeholder:"Filter columns"})]}),h.jsx("span",{className:"flex-1"}),!Y&&h.jsx("button",{disabled:!u.length,className:"button primary",onClick:O,children:"Run update"})]})]})},bE=()=>{const n=cE(),[l,r]=b.useState(void 0);b.useEffect(()=>{n&&r(n)},[n]);const i=()=>sh(void 0);return h.jsxs(Yt,{isVisible:n!=null,onClose:i,onClosed:()=>r(void 0),noPadding:!0,children:[h.jsx(On,{onClick:i}),l&&h.jsx(gE,{data:l})]})},[xE,ld]=It(void 0),w1=async n=>new Promise(l=>{ld({message:n,onCancel:()=>{l(!1),ld(void 0)},onConfirm:()=>{l(!0),ld(void 0)}})}),SE=({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"})]})]}),wE=()=>{const n=xE(),[l,r]=b.useState(void 0);return b.useEffect(()=>{n&&r(n)},[n]),h.jsx(Yt,{isVisible:!!n,onClose:()=>n==null?void 0:n.onCancel(),onClosed:()=>r(void 0),children:l&&h.jsx(SE,{confirm:l})})},[EE,Io]=It(void 0),Pl=async(n,l,r)=>new Promise(i=>{Io({message:n,defaultValue:l,alert:r,onCancel:()=>{Io(void 0),i(void 0)},onConfirm:o=>{Io(void 0),i(o)}})}),CE="_root_12mtw_1",_E={root:CE},jE=({data:n})=>{const[l,r]=b.useState("");b.useEffect(()=>{n.defaultValue&&r(n.defaultValue)},[n]);const i=u=>{r(u.target.value)},o=u=>{u.key==="Enter"&&(u.preventDefault(),n.onConfirm(l)),u.key==="Escape"&&(u.preventDefault(),n.onCancel())};return h.jsxs("div",{className:_E.root,children:[h.jsx("h2",{className:"text-xl font-semibold",children:n.message}),n.alert&&h.jsx(Lt,{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:i,onKeyDown:o}),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"})]})]})},NE=()=>{const n=EE(),[l,r]=b.useState(void 0);return b.useEffect(()=>{n&&r(n)},[n]),h.jsx(Yt,{isVisible:!!n,onClose:()=>Io(void 0),onClosed:()=>r(void 0),children:l&&h.jsx(jE,{data:l})})},[AE,TE]=It(void 0),E1=n=>{TE(n)},RE="_textarea_1tcsp_2",OE={textarea:RE},DE=()=>{const n=AE(),l=()=>{n&&(navigator.clipboard.writeText(n.toString()),qt.success("Copied!"))},r=()=>E1(void 0);return h.jsxs(Yt,{isVisible:!!n,onClose:r,backdropClose:!0,children:[h.jsx("textarea",{className:OE.textarea,readOnly:!0,defaultValue:n==null?void 0: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:r,children:"Close"})]})]})},ME="_tabs_13stu_2",UE="_mobile_13stu_2",LE="_tab_13stu_2",qE="_active_13stu_2",zE="_close-button_13stu_2",BE="_tooltip-label_13stu_2",HE="_tooltip-info-entry_13stu_2",ea={tabs:ME,mobile:UE,tab:LE,active:qE,closeButton:zE,tooltipLabel:BE,tooltipInfoEntry:HE},Vi=Math.min,Fl=Math.max,fu=Math.round,Ho=Math.floor,aa=n=>({x:n,y:n}),kE={left:"right",right:"left",bottom:"top",top:"bottom"},QE={start:"end",end:"start"};function Td(n,l,r){return Fl(n,Vi(l,r))}function Er(n,l){return typeof n=="function"?n(l):n}function Xl(n){return n.split("-")[0]}function Cr(n){return n.split("-")[1]}function C1(n){return n==="x"?"y":"x"}function rh(n){return n==="y"?"height":"width"}function ml(n){return["top","bottom"].includes(Xl(n))?"y":"x"}function oh(n){return C1(ml(n))}function YE(n,l,r){r===void 0&&(r=!1);const i=Cr(n),o=oh(n),u=rh(o);let d=o==="x"?i===(r?"end":"start")?"right":"left":i==="start"?"bottom":"top";return l.reference[u]>l.floating[u]&&(d=du(d)),[d,du(d)]}function VE(n){const l=du(n);return[Rd(n),l,Rd(l)]}function Rd(n){return n.replace(/start|end/g,l=>QE[l])}function KE(n,l,r){const i=["left","right"],o=["right","left"],u=["top","bottom"],d=["bottom","top"];switch(n){case"top":case"bottom":return r?l?o:i:l?i:o;case"left":case"right":return l?u:d;default:return[]}}function GE(n,l,r,i){const o=Cr(n);let u=KE(Xl(n),r==="start",i);return o&&(u=u.map(d=>d+"-"+o),l&&(u=u.concat(u.map(Rd)))),u}function du(n){return n.replace(/left|right|bottom|top/g,l=>kE[l])}function FE(n){return{top:0,right:0,bottom:0,left:0,...n}}function _1(n){return typeof n!="number"?FE(n):{top:n,right:n,bottom:n,left:n}}function hu(n){const{x:l,y:r,width:i,height:o}=n;return{width:i,height:o,top:r,left:l,right:l+i,bottom:r+o,x:l,y:r}}function By(n,l,r){let{reference:i,floating:o}=n;const u=ml(l),d=oh(l),m=rh(d),y=Xl(l),p=u==="y",g=i.x+i.width/2-o.width/2,S=i.y+i.height/2-o.height/2,E=i[m]/2-o[m]/2;let C;switch(y){case"top":C={x:g,y:i.y-o.height};break;case"bottom":C={x:g,y:i.y+i.height};break;case"right":C={x:i.x+i.width,y:S};break;case"left":C={x:i.x-o.width,y:S};break;default:C={x:i.x,y:i.y}}switch(Cr(l)){case"start":C[d]-=E*(r&&p?-1:1);break;case"end":C[d]+=E*(r&&p?-1:1);break}return C}const $E=async(n,l,r)=>{const{placement:i="bottom",strategy:o="absolute",middleware:u=[],platform:d}=r,m=u.filter(Boolean),y=await(d.isRTL==null?void 0:d.isRTL(l));let p=await d.getElementRects({reference:n,floating:l,strategy:o}),{x:g,y:S}=By(p,i,y),E=i,C={},w=0;for(let A=0;A<m.length;A++){const{name:j,fn:_}=m[A],{x:O,y:D,data:Y,reset:H}=await _({x:g,y:S,initialPlacement:i,placement:E,strategy:o,middlewareData:C,rects:p,platform:d,elements:{reference:n,floating:l}});g=O??g,S=D??S,C={...C,[j]:{...C[j],...Y}},H&&w<=50&&(w++,typeof H=="object"&&(H.placement&&(E=H.placement),H.rects&&(p=H.rects===!0?await d.getElementRects({reference:n,floating:l,strategy:o}):H.rects),{x:g,y:S}=By(p,E,y)),A=-1)}return{x:g,y:S,placement:E,strategy:o,middlewareData:C}};async function j1(n,l){var r;l===void 0&&(l={});const{x:i,y:o,platform:u,rects:d,elements:m,strategy:y}=n,{boundary:p="clippingAncestors",rootBoundary:g="viewport",elementContext:S="floating",altBoundary:E=!1,padding:C=0}=Er(l,n),w=_1(C),j=m[E?S==="floating"?"reference":"floating":S],_=hu(await u.getClippingRect({element:(r=await(u.isElement==null?void 0:u.isElement(j)))==null||r?j:j.contextElement||await(u.getDocumentElement==null?void 0:u.getDocumentElement(m.floating)),boundary:p,rootBoundary:g,strategy:y})),O=S==="floating"?{x:i,y:o,width:d.floating.width,height:d.floating.height}:d.reference,D=await(u.getOffsetParent==null?void 0:u.getOffsetParent(m.floating)),Y=await(u.isElement==null?void 0:u.isElement(D))?await(u.getScale==null?void 0:u.getScale(D))||{x:1,y:1}:{x:1,y:1},H=hu(u.convertOffsetParentRelativeRectToViewportRelativeRect?await u.convertOffsetParentRelativeRectToViewportRelativeRect({elements:m,rect:O,offsetParent:D,strategy:y}):O);return{top:(_.top-H.top+w.top)/Y.y,bottom:(H.bottom-_.bottom+w.bottom)/Y.y,left:(_.left-H.left+w.left)/Y.x,right:(H.right-_.right+w.right)/Y.x}}const XE=n=>({name:"arrow",options:n,async fn(l){const{x:r,y:i,placement:o,rects:u,platform:d,elements:m,middlewareData:y}=l,{element:p,padding:g=0}=Er(n,l)||{};if(p==null)return{};const S=_1(g),E={x:r,y:i},C=oh(o),w=rh(C),A=await d.getDimensions(p),j=C==="y",_=j?"top":"left",O=j?"bottom":"right",D=j?"clientHeight":"clientWidth",Y=u.reference[w]+u.reference[C]-E[C]-u.floating[w],H=E[C]-u.reference[C],$=await(d.getOffsetParent==null?void 0:d.getOffsetParent(p));let I=$?$[D]:0;(!I||!await(d.isElement==null?void 0:d.isElement($)))&&(I=m.floating[D]||u.floating[w]);const W=Y/2-H/2,re=I/2-A[w]/2-1,pe=Vi(S[_],re),Be=Vi(S[O],re),Ee=pe,Fe=I-A[w]-Be,ye=I/2-A[w]/2+W,xe=Td(Ee,ye,Fe),B=!y.arrow&&Cr(o)!=null&&ye!==xe&&u.reference[w]/2-(ye<Ee?pe:Be)-A[w]/2<0,F=B?ye<Ee?ye-Ee:ye-Fe:0;return{[C]:E[C]+F,data:{[C]:xe,centerOffset:ye-xe-F,...B&&{alignmentOffset:F}},reset:B}}}),ZE=function(n){return n===void 0&&(n={}),{name:"flip",options:n,async fn(l){var r,i;const{placement:o,middlewareData:u,rects:d,initialPlacement:m,platform:y,elements:p}=l,{mainAxis:g=!0,crossAxis:S=!0,fallbackPlacements:E,fallbackStrategy:C="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:A=!0,...j}=Er(n,l);if((r=u.arrow)!=null&&r.alignmentOffset)return{};const _=Xl(o),O=ml(m),D=Xl(m)===m,Y=await(y.isRTL==null?void 0:y.isRTL(p.floating)),H=E||(D||!A?[du(m)]:VE(m)),$=w!=="none";!E&&$&&H.push(...GE(m,A,w,Y));const I=[m,...H],W=await j1(l,j),re=[];let pe=((i=u.flip)==null?void 0:i.overflows)||[];if(g&&re.push(W[_]),S){const ye=YE(o,d,Y);re.push(W[ye[0]],W[ye[1]])}if(pe=[...pe,{placement:o,overflows:re}],!re.every(ye=>ye<=0)){var Be,Ee;const ye=(((Be=u.flip)==null?void 0:Be.index)||0)+1,xe=I[ye];if(xe&&(!(S==="alignment"?O!==ml(xe):!1)||pe.every(Z=>Z.overflows[0]>0&&ml(Z.placement)===O)))return{data:{index:ye,overflows:pe},reset:{placement:xe}};let B=(Ee=pe.filter(F=>F.overflows[0]<=0).sort((F,Z)=>F.overflows[1]-Z.overflows[1])[0])==null?void 0:Ee.placement;if(!B)switch(C){case"bestFit":{var Fe;const F=(Fe=pe.filter(Z=>{if($){const ue=ml(Z.placement);return ue===O||ue==="y"}return!0}).map(Z=>[Z.placement,Z.overflows.filter(ue=>ue>0).reduce((ue,T)=>ue+T,0)]).sort((Z,ue)=>Z[1]-ue[1])[0])==null?void 0:Fe[0];F&&(B=F);break}case"initialPlacement":B=m;break}if(o!==B)return{reset:{placement:B}}}return{}}}};async function JE(n,l){const{placement:r,platform:i,elements:o}=n,u=await(i.isRTL==null?void 0:i.isRTL(o.floating)),d=Xl(r),m=Cr(r),y=ml(r)==="y",p=["left","top"].includes(d)?-1:1,g=u&&y?-1:1,S=Er(l,n);let{mainAxis:E,crossAxis:C,alignmentAxis:w}=typeof S=="number"?{mainAxis:S,crossAxis:0,alignmentAxis:null}:{mainAxis:S.mainAxis||0,crossAxis:S.crossAxis||0,alignmentAxis:S.alignmentAxis};return m&&typeof w=="number"&&(C=m==="end"?w*-1:w),y?{x:C*g,y:E*p}:{x:E*p,y:C*g}}const PE=function(n){return n===void 0&&(n=0),{name:"offset",options:n,async fn(l){var r,i;const{x:o,y:u,placement:d,middlewareData:m}=l,y=await JE(l,n);return d===((r=m.offset)==null?void 0:r.placement)&&(i=m.arrow)!=null&&i.alignmentOffset?{}:{x:o+y.x,y:u+y.y,data:{...y,placement:d}}}}},IE=function(n){return n===void 0&&(n={}),{name:"shift",options:n,async fn(l){const{x:r,y:i,placement:o}=l,{mainAxis:u=!0,crossAxis:d=!1,limiter:m={fn:j=>{let{x:_,y:O}=j;return{x:_,y:O}}},...y}=Er(n,l),p={x:r,y:i},g=await j1(l,y),S=ml(Xl(o)),E=C1(S);let C=p[E],w=p[S];if(u){const j=E==="y"?"top":"left",_=E==="y"?"bottom":"right",O=C+g[j],D=C-g[_];C=Td(O,C,D)}if(d){const j=S==="y"?"top":"left",_=S==="y"?"bottom":"right",O=w+g[j],D=w-g[_];w=Td(O,w,D)}const A=m.fn({...l,[E]:C,[S]:w});return{...A,data:{x:A.x-r,y:A.y-i,enabled:{[E]:u,[S]:d}}}}}};function Du(){return typeof window<"u"}function ns(n){return N1(n)?(n.nodeName||"").toLowerCase():"#document"}function un(n){var l;return(n==null||(l=n.ownerDocument)==null?void 0:l.defaultView)||window}function ra(n){var l;return(l=(N1(n)?n.ownerDocument:n.document)||window.document)==null?void 0:l.documentElement}function N1(n){return Du()?n instanceof Node||n instanceof un(n).Node:!1}function zn(n){return Du()?n instanceof Element||n instanceof un(n).Element:!1}function la(n){return Du()?n instanceof HTMLElement||n instanceof un(n).HTMLElement:!1}function Hy(n){return!Du()||typeof ShadowRoot>"u"?!1:n instanceof ShadowRoot||n instanceof un(n).ShadowRoot}function _r(n){const{overflow:l,overflowX:r,overflowY:i,display:o}=Bn(n);return/auto|scroll|overlay|hidden|clip/.test(l+i+r)&&!["inline","contents"].includes(o)}function WE(n){return["table","td","th"].includes(ns(n))}function Mu(n){return[":popover-open",":modal"].some(l=>{try{return n.matches(l)}catch{return!1}})}function uh(n){const l=ch(),r=zn(n)?Bn(n):n;return["transform","translate","scale","rotate","perspective"].some(i=>r[i]?r[i]!=="none":!1)||(r.containerType?r.containerType!=="normal":!1)||!l&&(r.backdropFilter?r.backdropFilter!=="none":!1)||!l&&(r.filter?r.filter!=="none":!1)||["transform","translate","scale","rotate","perspective","filter"].some(i=>(r.willChange||"").includes(i))||["paint","layout","strict","content"].some(i=>(r.contain||"").includes(i))}function eC(n){let l=vl(n);for(;la(l)&&!Ki(l);){if(uh(l))return l;if(Mu(l))return null;l=vl(l)}return null}function ch(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function Ki(n){return["html","body","#document"].includes(ns(n))}function Bn(n){return un(n).getComputedStyle(n)}function Uu(n){return zn(n)?{scrollLeft:n.scrollLeft,scrollTop:n.scrollTop}:{scrollLeft:n.scrollX,scrollTop:n.scrollY}}function vl(n){if(ns(n)==="html")return n;const l=n.assignedSlot||n.parentNode||Hy(n)&&n.host||ra(n);return Hy(l)?l.host:l}function A1(n){const l=vl(n);return Ki(l)?n.ownerDocument?n.ownerDocument.body:n.body:la(l)&&_r(l)?l:A1(l)}function dr(n,l,r){var i;l===void 0&&(l=[]),r===void 0&&(r=!0);const o=A1(n),u=o===((i=n.ownerDocument)==null?void 0:i.body),d=un(o);if(u){const m=Od(d);return l.concat(d,d.visualViewport||[],_r(o)?o:[],m&&r?dr(m):[])}return l.concat(o,dr(o,[],r))}function Od(n){return n.parent&&Object.getPrototypeOf(n.parent)?n.frameElement:null}function T1(n){const l=Bn(n);let r=parseFloat(l.width)||0,i=parseFloat(l.height)||0;const o=la(n),u=o?n.offsetWidth:r,d=o?n.offsetHeight:i,m=fu(r)!==u||fu(i)!==d;return m&&(r=u,i=d),{width:r,height:i,$:m}}function fh(n){return zn(n)?n:n.contextElement}function Qi(n){const l=fh(n);if(!la(l))return aa(1);const r=l.getBoundingClientRect(),{width:i,height:o,$:u}=T1(l);let d=(u?fu(r.width):r.width)/i,m=(u?fu(r.height):r.height)/o;return(!d||!Number.isFinite(d))&&(d=1),(!m||!Number.isFinite(m))&&(m=1),{x:d,y:m}}const tC=aa(0);function R1(n){const l=un(n);return!ch()||!l.visualViewport?tC:{x:l.visualViewport.offsetLeft,y:l.visualViewport.offsetTop}}function nC(n,l,r){return l===void 0&&(l=!1),!r||l&&r!==un(n)?!1:l}function Zl(n,l,r,i){l===void 0&&(l=!1),r===void 0&&(r=!1);const o=n.getBoundingClientRect(),u=fh(n);let d=aa(1);l&&(i?zn(i)&&(d=Qi(i)):d=Qi(n));const m=nC(u,r,i)?R1(u):aa(0);let y=(o.left+m.x)/d.x,p=(o.top+m.y)/d.y,g=o.width/d.x,S=o.height/d.y;if(u){const E=un(u),C=i&&zn(i)?un(i):i;let w=E,A=Od(w);for(;A&&i&&C!==w;){const j=Qi(A),_=A.getBoundingClientRect(),O=Bn(A),D=_.left+(A.clientLeft+parseFloat(O.paddingLeft))*j.x,Y=_.top+(A.clientTop+parseFloat(O.paddingTop))*j.y;y*=j.x,p*=j.y,g*=j.x,S*=j.y,y+=D,p+=Y,w=un(A),A=Od(w)}}return hu({width:g,height:S,x:y,y:p})}function dh(n,l){const r=Uu(n).scrollLeft;return l?l.left+r:Zl(ra(n)).left+r}function O1(n,l,r){r===void 0&&(r=!1);const i=n.getBoundingClientRect(),o=i.left+l.scrollLeft-(r?0:dh(n,i)),u=i.top+l.scrollTop;return{x:o,y:u}}function aC(n){let{elements:l,rect:r,offsetParent:i,strategy:o}=n;const u=o==="fixed",d=ra(i),m=l?Mu(l.floating):!1;if(i===d||m&&u)return r;let y={scrollLeft:0,scrollTop:0},p=aa(1);const g=aa(0),S=la(i);if((S||!S&&!u)&&((ns(i)!=="body"||_r(d))&&(y=Uu(i)),la(i))){const C=Zl(i);p=Qi(i),g.x=C.x+i.clientLeft,g.y=C.y+i.clientTop}const E=d&&!S&&!u?O1(d,y,!0):aa(0);return{width:r.width*p.x,height:r.height*p.y,x:r.x*p.x-y.scrollLeft*p.x+g.x+E.x,y:r.y*p.y-y.scrollTop*p.y+g.y+E.y}}function lC(n){return Array.from(n.getClientRects())}function iC(n){const l=ra(n),r=Uu(n),i=n.ownerDocument.body,o=Fl(l.scrollWidth,l.clientWidth,i.scrollWidth,i.clientWidth),u=Fl(l.scrollHeight,l.clientHeight,i.scrollHeight,i.clientHeight);let d=-r.scrollLeft+dh(n);const m=-r.scrollTop;return Bn(i).direction==="rtl"&&(d+=Fl(l.clientWidth,i.clientWidth)-o),{width:o,height:u,x:d,y:m}}function sC(n,l){const r=un(n),i=ra(n),o=r.visualViewport;let u=i.clientWidth,d=i.clientHeight,m=0,y=0;if(o){u=o.width,d=o.height;const p=ch();(!p||p&&l==="fixed")&&(m=o.offsetLeft,y=o.offsetTop)}return{width:u,height:d,x:m,y}}function rC(n,l){const r=Zl(n,!0,l==="fixed"),i=r.top+n.clientTop,o=r.left+n.clientLeft,u=la(n)?Qi(n):aa(1),d=n.clientWidth*u.x,m=n.clientHeight*u.y,y=o*u.x,p=i*u.y;return{width:d,height:m,x:y,y:p}}function ky(n,l,r){let i;if(l==="viewport")i=sC(n,r);else if(l==="document")i=iC(ra(n));else if(zn(l))i=rC(l,r);else{const o=R1(n);i={x:l.x-o.x,y:l.y-o.y,width:l.width,height:l.height}}return hu(i)}function D1(n,l){const r=vl(n);return r===l||!zn(r)||Ki(r)?!1:Bn(r).position==="fixed"||D1(r,l)}function oC(n,l){const r=l.get(n);if(r)return r;let i=dr(n,[],!1).filter(m=>zn(m)&&ns(m)!=="body"),o=null;const u=Bn(n).position==="fixed";let d=u?vl(n):n;for(;zn(d)&&!Ki(d);){const m=Bn(d),y=uh(d);!y&&m.position==="fixed"&&(o=null),(u?!y&&!o:!y&&m.position==="static"&&!!o&&["absolute","fixed"].includes(o.position)||_r(d)&&!y&&D1(n,d))?i=i.filter(g=>g!==d):o=m,d=vl(d)}return l.set(n,i),i}function uC(n){let{element:l,boundary:r,rootBoundary:i,strategy:o}=n;const d=[...r==="clippingAncestors"?Mu(l)?[]:oC(l,this._c):[].concat(r),i],m=d[0],y=d.reduce((p,g)=>{const S=ky(l,g,o);return p.top=Fl(S.top,p.top),p.right=Vi(S.right,p.right),p.bottom=Vi(S.bottom,p.bottom),p.left=Fl(S.left,p.left),p},ky(l,m,o));return{width:y.right-y.left,height:y.bottom-y.top,x:y.left,y:y.top}}function cC(n){const{width:l,height:r}=T1(n);return{width:l,height:r}}function fC(n,l,r){const i=la(l),o=ra(l),u=r==="fixed",d=Zl(n,!0,u,l);let m={scrollLeft:0,scrollTop:0};const y=aa(0);function p(){y.x=dh(o)}if(i||!i&&!u)if((ns(l)!=="body"||_r(o))&&(m=Uu(l)),i){const C=Zl(l,!0,u,l);y.x=C.x+l.clientLeft,y.y=C.y+l.clientTop}else o&&p();u&&!i&&o&&p();const g=o&&!i&&!u?O1(o,m):aa(0),S=d.left+m.scrollLeft-y.x-g.x,E=d.top+m.scrollTop-y.y-g.y;return{x:S,y:E,width:d.width,height:d.height}}function id(n){return Bn(n).position==="static"}function Qy(n,l){if(!la(n)||Bn(n).position==="fixed")return null;if(l)return l(n);let r=n.offsetParent;return ra(n)===r&&(r=r.ownerDocument.body),r}function M1(n,l){const r=un(n);if(Mu(n))return r;if(!la(n)){let o=vl(n);for(;o&&!Ki(o);){if(zn(o)&&!id(o))return o;o=vl(o)}return r}let i=Qy(n,l);for(;i&&WE(i)&&id(i);)i=Qy(i,l);return i&&Ki(i)&&id(i)&&!uh(i)?r:i||eC(n)||r}const dC=async function(n){const l=this.getOffsetParent||M1,r=this.getDimensions,i=await r(n.floating);return{reference:fC(n.reference,await l(n.floating),n.strategy),floating:{x:0,y:0,width:i.width,height:i.height}}};function hC(n){return Bn(n).direction==="rtl"}const mC={convertOffsetParentRelativeRectToViewportRelativeRect:aC,getDocumentElement:ra,getClippingRect:uC,getOffsetParent:M1,getElementRects:dC,getClientRects:lC,getDimensions:cC,getScale:Qi,isElement:zn,isRTL:hC};function U1(n,l){return n.x===l.x&&n.y===l.y&&n.width===l.width&&n.height===l.height}function pC(n,l){let r=null,i;const o=ra(n);function u(){var m;clearTimeout(i),(m=r)==null||m.disconnect(),r=null}function d(m,y){m===void 0&&(m=!1),y===void 0&&(y=1),u();const p=n.getBoundingClientRect(),{left:g,top:S,width:E,height:C}=p;if(m||l(),!E||!C)return;const w=Ho(S),A=Ho(o.clientWidth-(g+E)),j=Ho(o.clientHeight-(S+C)),_=Ho(g),D={rootMargin:-w+"px "+-A+"px "+-j+"px "+-_+"px",threshold:Fl(0,Vi(1,y))||1};let Y=!0;function H($){const I=$[0].intersectionRatio;if(I!==y){if(!Y)return d();I?d(!1,I):i=setTimeout(()=>{d(!1,1e-7)},1e3)}I===1&&!U1(p,n.getBoundingClientRect())&&d(),Y=!1}try{r=new IntersectionObserver(H,{...D,root:o.ownerDocument})}catch{r=new IntersectionObserver(H,D)}r.observe(n)}return d(!0),u}function yC(n,l,r,i){i===void 0&&(i={});const{ancestorScroll:o=!0,ancestorResize:u=!0,elementResize:d=typeof ResizeObserver=="function",layoutShift:m=typeof IntersectionObserver=="function",animationFrame:y=!1}=i,p=fh(n),g=o||u?[...p?dr(p):[],...dr(l)]:[];g.forEach(_=>{o&&_.addEventListener("scroll",r,{passive:!0}),u&&_.addEventListener("resize",r)});const S=p&&m?pC(p,r):null;let E=-1,C=null;d&&(C=new ResizeObserver(_=>{let[O]=_;O&&O.target===p&&C&&(C.unobserve(l),cancelAnimationFrame(E),E=requestAnimationFrame(()=>{var D;(D=C)==null||D.observe(l)})),r()}),p&&!y&&C.observe(p),C.observe(l));let w,A=y?Zl(n):null;y&&j();function j(){const _=Zl(n);A&&!U1(A,_)&&r(),A=_,w=requestAnimationFrame(j)}return r(),()=>{var _;g.forEach(O=>{o&&O.removeEventListener("scroll",r),u&&O.removeEventListener("resize",r)}),S==null||S(),(_=C)==null||_.disconnect(),C=null,y&&cancelAnimationFrame(w)}}const vC=PE,gC=IE,bC=ZE,xC=XE,Yy=(n,l,r)=>{const i=new Map,o={platform:mC,...r},u={...o.platform,_c:i};return $E(n,l,{...o,platform:u})};var sd={exports:{}};/*!
|
|
233
233
|
Copyright (c) 2018 Jed Watson.
|
|
234
234
|
Licensed under the MIT License (MIT), see
|
|
235
235
|
http://jedwatson.github.io/classnames
|
|
236
236
|
*/var Vy;function SC(){return Vy||(Vy=1,function(n){(function(){var l={}.hasOwnProperty;function r(){for(var u="",d=0;d<arguments.length;d++){var m=arguments[d];m&&(u=o(u,i(m)))}return u}function i(u){if(typeof u=="string"||typeof u=="number")return u;if(typeof u!="object")return"";if(Array.isArray(u))return r.apply(null,u);if(u.toString!==Object.prototype.toString&&!u.toString.toString().includes("[native code]"))return u.toString();var d="";for(var m in u)l.call(u,m)&&u[m]&&(d=o(d,m));return d}function o(u,d){return d?u?u+" "+d:u+d:u}n.exports?(r.default=r,n.exports=r):window.classNames=r})()}(sd)),sd.exports}var wC=SC();const Dd=yu(wC);var Ky={};const EC="react-tooltip-core-styles",CC="react-tooltip-base-styles",Gy={core:!1,base:!1};function Fy({css:n,id:l=CC,type:r="base",ref:i}){var o,u;if(!n||typeof document>"u"||Gy[r]||r==="core"&&typeof process<"u"&&(!((o=process==null?void 0:Ky)===null||o===void 0)&&o.REACT_TOOLTIP_DISABLE_CORE_STYLES)||r!=="base"&&typeof process<"u"&&(!((u=process==null?void 0:Ky)===null||u===void 0)&&u.REACT_TOOLTIP_DISABLE_BASE_STYLES))return;r==="core"&&(l=EC),i||(i={});const{insertAt:d}=i;if(document.getElementById(l))return;const m=document.head||document.getElementsByTagName("head")[0],y=document.createElement("style");y.id=l,y.type="text/css",d==="top"&&m.firstChild?m.insertBefore(y,m.firstChild):m.appendChild(y),y.styleSheet?y.styleSheet.cssText=n:y.appendChild(document.createTextNode(n)),Gy[r]=!0}const $y=async({elementReference:n=null,tooltipReference:l=null,tooltipArrowReference:r=null,place:i="top",offset:o=10,strategy:u="absolute",middlewares:d=[vC(Number(o)),bC({fallbackAxisSideDirection:"start"}),gC({padding:5})],border:m,arrowSize:y=8})=>{if(!n)return{tooltipStyles:{},tooltipArrowStyles:{},place:i};if(l===null)return{tooltipStyles:{},tooltipArrowStyles:{},place:i};const p=d;return r?(p.push(xC({element:r,padding:5})),Yy(n,l,{placement:i,strategy:u,middleware:p}).then(({x:g,y:S,placement:E,middlewareData:C})=>{var w,A;const j={left:`${g}px`,top:`${S}px`,border:m},{x:_,y:O}=(w=C.arrow)!==null&&w!==void 0?w:{x:0,y:0},D=(A={top:"bottom",right:"left",bottom:"top",left:"right"}[E.split("-")[0]])!==null&&A!==void 0?A:"bottom",Y=m&&{borderBottom:m,borderRight:m};let H=0;if(m){const $=`${m}`.match(/(\d+)px/);H=$!=null&&$[1]?Number($[1]):1}return{tooltipStyles:j,tooltipArrowStyles:{left:_!=null?`${_}px`:"",top:O!=null?`${O}px`:"",right:"",bottom:"",...Y,[D]:`-${y/2+H}px`},place:E}})):Yy(n,l,{placement:"bottom",strategy:u,middleware:p}).then(({x:g,y:S,placement:E})=>({tooltipStyles:{left:`${g}px`,top:`${S}px`},tooltipArrowStyles:{},place:E}))},Xy=(n,l)=>!("CSS"in window&&"supports"in window.CSS)||window.CSS.supports(n,l),Zy=(n,l,r)=>{let i=null;const o=function(...u){const d=()=>{i=null};!i&&(n.apply(this,u),i=setTimeout(d,l))};return o.cancel=()=>{i&&(clearTimeout(i),i=null)},o},Jy=n=>n!==null&&!Array.isArray(n)&&typeof n=="object",Md=(n,l)=>{if(n===l)return!0;if(Array.isArray(n)&&Array.isArray(l))return n.length===l.length&&n.every((o,u)=>Md(o,l[u]));if(Array.isArray(n)!==Array.isArray(l))return!1;if(!Jy(n)||!Jy(l))return n===l;const r=Object.keys(n),i=Object.keys(l);return r.length===i.length&&r.every(o=>Md(n[o],l[o]))},_C=n=>{if(!(n instanceof HTMLElement||n instanceof SVGElement))return!1;const l=getComputedStyle(n);return["overflow","overflow-x","overflow-y"].some(r=>{const i=l.getPropertyValue(r);return i==="auto"||i==="scroll"})},Py=n=>{if(!n)return null;let l=n.parentElement;for(;l;){if(_C(l))return l;l=l.parentElement}return document.scrollingElement||document.documentElement},jC=typeof window<"u"?b.useLayoutEffect:b.useEffect,An=n=>{n.current&&(clearTimeout(n.current),n.current=null)},NC="DEFAULT_TOOLTIP_ID",AC={anchorRefs:new Set,activeAnchor:{current:null},attach:()=>{},detach:()=>{},setActiveAnchor:()=>{}},TC=b.createContext({getTooltipData:()=>AC});function L1(n=NC){return b.useContext(TC).getTooltipData(n)}var Bi={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"},rd={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 RC=({forwardRef:n,id:l,className:r,classNameArrow:i,variant:o="dark",anchorId:u,anchorSelect:d,place:m="top",offset:y=10,events:p=["hover"],openOnClick:g=!1,positionStrategy:S="absolute",middlewares:E,wrapper:C,delayShow:w=0,delayHide:A=0,float:j=!1,hidden:_=!1,noArrow:O=!1,clickable:D=!1,closeOnEsc:Y=!1,closeOnScroll:H=!1,closeOnResize:$=!1,openEvents:I,closeEvents:W,globalCloseEvents:re,imperativeModeOnly:pe,style:Be,position:Ee,afterShow:Fe,afterHide:ye,disableTooltip:xe,content:B,contentWrapperRef:F,isOpen:Z,defaultIsOpen:ue=!1,setIsOpen:T,activeAnchor:Q,setActiveAnchor:P,border:J,opacity:le,arrowColor:Ce,arrowSize:ce=8,role:St="tooltip"})=>{var Me;const Ze=b.useRef(null),Vn=b.useRef(null),Nt=b.useRef(null),dn=b.useRef(null),ua=b.useRef(null),[hn,as]=b.useState({tooltipStyles:{},tooltipArrowStyles:{},place:m}),[zt,Bt]=b.useState(!1),[ca,Kn]=b.useState(!1),[$e,Gn]=b.useState(null),bl=b.useRef(!1),qa=b.useRef(null),{anchorRefs:xl,setActiveAnchor:Il}=L1(l),mn=b.useRef(!1),[tt,Vt]=b.useState([]),it=b.useRef(!1),za=g||p.includes("click"),ls=za||(I==null?void 0:I.click)||(I==null?void 0:I.dblclick)||(I==null?void 0:I.mousedown),Ba=I?{...I}:{mouseover:!0,focus:!0,mouseenter:!1,click:!1,dblclick:!1,mousedown:!1};!I&&za&&Object.assign(Ba,{mouseenter:!1,focus:!1,mouseover:!1,click:!0});const pn=W?{...W}:{mouseout:!0,blur:!0,mouseleave:!1,click:!1,dblclick:!1,mouseup:!1};!W&&za&&Object.assign(pn,{mouseleave:!1,blur:!1,mouseout:!1});const At=re?{...re}:{escape:Y||!1,scroll:H||!1,resize:$||!1,clickOutsideAnchor:ls||!1};pe&&(Object.assign(Ba,{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(At,{escape:!1,scroll:!1,resize:!1,clickOutsideAnchor:!1})),jC(()=>(it.current=!0,()=>{it.current=!1}),[]);const He=X=>{it.current&&(X&&Kn(!0),setTimeout(()=>{it.current&&(T==null||T(X),Z===void 0&&Bt(X))},10))};b.useEffect(()=>{if(Z===void 0)return()=>null;Z&&Kn(!0);const X=setTimeout(()=>{Bt(Z)},10);return()=>{clearTimeout(X)}},[Z]),b.useEffect(()=>{if(zt!==bl.current)if(An(ua),bl.current=zt,zt)Fe==null||Fe();else{const X=(te=>{const de=te.match(/^([\d.]+)(ms|s)$/);if(!de)return 0;const[,We,vt]=de;return Number(We)*(vt==="ms"?1:1e3)})(getComputedStyle(document.body).getPropertyValue("--rt-transition-show-delay"));ua.current=setTimeout(()=>{Kn(!1),Gn(null),ye==null||ye()},X+25)}},[zt]);const fa=X=>{as(te=>Md(te,X)?te:X)},Dn=(X=w)=>{An(Nt),ca?He(!0):Nt.current=setTimeout(()=>{He(!0)},X)},Ha=(X=A)=>{An(dn),dn.current=setTimeout(()=>{mn.current||He(!1)},X)},ka=X=>{var te;if(!X)return;const de=(te=X.currentTarget)!==null&&te!==void 0?te:X.target;if(!(de!=null&&de.isConnected))return P(null),void Il({current:null});w?Dn():He(!0),P(de),Il({current:de}),An(dn)},da=()=>{D?Ha(A||100):A?Ha():He(!1),An(Nt)},Fn=({x:X,y:te})=>{var de;const We={getBoundingClientRect:()=>({x:X,y:te,width:0,height:0,top:te,left:X,right:X,bottom:te})};$y({place:(de=$e==null?void 0:$e.place)!==null&&de!==void 0?de:m,offset:y,elementReference:We,tooltipReference:Ze.current,tooltipArrowReference:Vn.current,strategy:S,middlewares:E,border:J,arrowSize:ce}).then(vt=>{fa(vt)})},yn=X=>{if(!X)return;const te=X,de={x:te.clientX,y:te.clientY};Fn(de),qa.current=de},Sl=X=>{var te;if(!zt)return;const de=X.target;de.isConnected&&(!((te=Ze.current)===null||te===void 0)&&te.contains(de)||[document.querySelector(`[id='${u}']`),...tt].some(We=>We==null?void 0:We.contains(de))||(He(!1),An(Nt)))},wl=Zy(ka,50),st=Zy(da,50),Tt=X=>{st.cancel(),wl(X)},oe=()=>{wl.cancel(),st()},_e=b.useCallback(()=>{var X,te;const de=(X=$e==null?void 0:$e.position)!==null&&X!==void 0?X:Ee;de?Fn(de):j?qa.current&&Fn(qa.current):Q!=null&&Q.isConnected&&$y({place:(te=$e==null?void 0:$e.place)!==null&&te!==void 0?te:m,offset:y,elementReference:Q,tooltipReference:Ze.current,tooltipArrowReference:Vn.current,strategy:S,middlewares:E,border:J,arrowSize:ce}).then(We=>{it.current&&fa(We)})},[zt,Q,B,Be,m,$e==null?void 0:$e.place,y,S,Ee,$e==null?void 0:$e.position,j,ce]);b.useEffect(()=>{var X,te;const de=new Set(xl);tt.forEach(Oe=>{xe!=null&&xe(Oe)||de.add({current:Oe})});const We=document.querySelector(`[id='${u}']`);We&&!(xe!=null&&xe(We))&&de.add({current:We});const vt=()=>{He(!1)},vn=Py(Q),Wt=Py(Ze.current);At.scroll&&(window.addEventListener("scroll",vt),vn==null||vn.addEventListener("scroll",vt),Wt==null||Wt.addEventListener("scroll",vt));let rt=null;At.resize?window.addEventListener("resize",vt):Q&&Ze.current&&(rt=yC(Q,Ze.current,_e,{ancestorResize:!0,elementResize:!0,layoutShift:!0}));const Ot=Oe=>{Oe.key==="Escape"&&He(!1)};At.escape&&window.addEventListener("keydown",Ot),At.clickOutsideAnchor&&window.addEventListener("click",Sl);const Re=[],en=Oe=>!!(Oe!=null&&Oe.target&&(Q!=null&&Q.contains(Oe.target))),El=Oe=>{zt&&en(Oe)||ka(Oe)},Qa=Oe=>{zt&&en(Oe)&&da()},ot=["mouseover","mouseout","mouseenter","mouseleave","focus","blur"],is=["click","dblclick","mousedown","mouseup"];Object.entries(Ba).forEach(([Oe,gn])=>{gn&&(ot.includes(Oe)?Re.push({event:Oe,listener:Tt}):is.includes(Oe)&&Re.push({event:Oe,listener:El}))}),Object.entries(pn).forEach(([Oe,gn])=>{gn&&(ot.includes(Oe)?Re.push({event:Oe,listener:oe}):is.includes(Oe)&&Re.push({event:Oe,listener:Qa}))}),j&&Re.push({event:"pointermove",listener:yn});const ss=()=>{mn.current=!0},$n=()=>{mn.current=!1,da()},ha=D&&(pn.mouseout||pn.mouseleave);return ha&&((X=Ze.current)===null||X===void 0||X.addEventListener("mouseover",ss),(te=Ze.current)===null||te===void 0||te.addEventListener("mouseout",$n)),Re.forEach(({event:Oe,listener:gn})=>{de.forEach(Wl=>{var Cl;(Cl=Wl.current)===null||Cl===void 0||Cl.addEventListener(Oe,gn)})}),()=>{var Oe,gn;At.scroll&&(window.removeEventListener("scroll",vt),vn==null||vn.removeEventListener("scroll",vt),Wt==null||Wt.removeEventListener("scroll",vt)),At.resize?window.removeEventListener("resize",vt):rt==null||rt(),At.clickOutsideAnchor&&window.removeEventListener("click",Sl),At.escape&&window.removeEventListener("keydown",Ot),ha&&((Oe=Ze.current)===null||Oe===void 0||Oe.removeEventListener("mouseover",ss),(gn=Ze.current)===null||gn===void 0||gn.removeEventListener("mouseout",$n)),Re.forEach(({event:Wl,listener:Cl})=>{de.forEach(ei=>{var Ya;(Ya=ei.current)===null||Ya===void 0||Ya.removeEventListener(Wl,Cl)})})}},[Q,_e,ca,xl,tt,I,W,re,za,w,A]),b.useEffect(()=>{var X,te;let de=(te=(X=$e==null?void 0:$e.anchorSelect)!==null&&X!==void 0?X:d)!==null&&te!==void 0?te:"";!de&&l&&(de=`[data-tooltip-id='${l.replace(/'/g,"\\'")}']`);const We=new MutationObserver(vt=>{const vn=[],Wt=[];vt.forEach(rt=>{if(rt.type==="attributes"&&rt.attributeName==="data-tooltip-id"&&(rt.target.getAttribute("data-tooltip-id")===l?vn.push(rt.target):rt.oldValue===l&&Wt.push(rt.target)),rt.type==="childList"){if(Q){const Ot=[...rt.removedNodes].filter(Re=>Re.nodeType===1);if(de)try{Wt.push(...Ot.filter(Re=>Re.matches(de))),Wt.push(...Ot.flatMap(Re=>[...Re.querySelectorAll(de)]))}catch{}Ot.some(Re=>{var en;return!!(!((en=Re==null?void 0:Re.contains)===null||en===void 0)&&en.call(Re,Q))&&(Kn(!1),He(!1),P(null),An(Nt),An(dn),!0)})}if(de)try{const Ot=[...rt.addedNodes].filter(Re=>Re.nodeType===1);vn.push(...Ot.filter(Re=>Re.matches(de))),vn.push(...Ot.flatMap(Re=>[...Re.querySelectorAll(de)]))}catch{}}}),(vn.length||Wt.length)&&Vt(rt=>[...rt.filter(Ot=>!Wt.includes(Ot)),...vn])});return We.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-tooltip-id"],attributeOldValue:!0}),()=>{We.disconnect()}},[l,d,$e==null?void 0:$e.anchorSelect,Q]),b.useEffect(()=>{_e()},[_e]),b.useEffect(()=>{if(!(F!=null&&F.current))return()=>null;const X=new ResizeObserver(()=>{setTimeout(()=>_e())});return X.observe(F.current),()=>{X.disconnect()}},[B,F==null?void 0:F.current]),b.useEffect(()=>{var X;const te=document.querySelector(`[id='${u}']`),de=[...tt,te];Q&&de.includes(Q)||P((X=tt[0])!==null&&X!==void 0?X:te)},[u,tt,Q]),b.useEffect(()=>(ue&&He(!0),()=>{An(Nt),An(dn)}),[]),b.useEffect(()=>{var X;let te=(X=$e==null?void 0:$e.anchorSelect)!==null&&X!==void 0?X:d;if(!te&&l&&(te=`[data-tooltip-id='${l.replace(/'/g,"\\'")}']`),te)try{const de=Array.from(document.querySelectorAll(te));Vt(de)}catch{Vt([])}},[l,d,$e==null?void 0:$e.anchorSelect]),b.useEffect(()=>{Nt.current&&(An(Nt),Dn(w))},[w]);const Ht=(Me=$e==null?void 0:$e.content)!==null&&Me!==void 0?Me:B,Rt=zt&&Object.keys(hn.tooltipStyles).length>0;return b.useImperativeHandle(n,()=>({open:X=>{if(X!=null&&X.anchorSelect)try{document.querySelector(X.anchorSelect)}catch{return void console.warn(`[react-tooltip] "${X.anchorSelect}" is not a valid CSS selector`)}Gn(X??null),X!=null&&X.delay?Dn(X.delay):He(!0)},close:X=>{X!=null&&X.delay?Ha(X.delay):He(!1)},activeAnchor:Q,place:hn.place,isOpen:!!(ca&&!_&&Ht&&Rt)})),ca&&!_&&Ht?Ge.createElement(C,{id:l,role:St,className:Dd("react-tooltip",Bi.tooltip,rd.tooltip,rd[o],r,`react-tooltip__place-${hn.place}`,Bi[Rt?"show":"closing"],Rt?"react-tooltip__show":"react-tooltip__closing",S==="fixed"&&Bi.fixed,D&&Bi.clickable),onTransitionEnd:X=>{An(ua),zt||X.propertyName!=="opacity"||(Kn(!1),Gn(null),ye==null||ye())},style:{...Be,...hn.tooltipStyles,opacity:le!==void 0&&Rt?le:void 0},ref:Ze},Ht,Ge.createElement(C,{className:Dd("react-tooltip-arrow",Bi.arrow,rd.arrow,i,O&&Bi.noArrow),style:{...hn.tooltipArrowStyles,background:Ce?`linear-gradient(to right bottom, transparent 50%, ${Ce} 50%)`:void 0,"--rt-arrow-size":`${ce}px`},ref:Vn})):null},OC=({content:n})=>Ge.createElement("span",{dangerouslySetInnerHTML:{__html:n}}),hh=Ge.forwardRef(({id:n,anchorId:l,anchorSelect:r,content:i,html:o,render:u,className:d,classNameArrow:m,variant:y="dark",place:p="top",offset:g=10,wrapper:S="div",children:E=null,events:C=["hover"],openOnClick:w=!1,positionStrategy:A="absolute",middlewares:j,delayShow:_=0,delayHide:O=0,float:D=!1,hidden:Y=!1,noArrow:H=!1,clickable:$=!1,closeOnEsc:I=!1,closeOnScroll:W=!1,closeOnResize:re=!1,openEvents:pe,closeEvents:Be,globalCloseEvents:Ee,imperativeModeOnly:Fe=!1,style:ye,position:xe,isOpen:B,defaultIsOpen:F=!1,disableStyleInjection:Z=!1,border:ue,opacity:T,arrowColor:Q,arrowSize:P,setIsOpen:J,afterShow:le,afterHide:Ce,disableTooltip:ce,role:St="tooltip"},Me)=>{const[Ze,Vn]=b.useState(i),[Nt,dn]=b.useState(o),[ua,hn]=b.useState(p),[as,zt]=b.useState(y),[Bt,ca]=b.useState(g),[Kn,$e]=b.useState(_),[Gn,bl]=b.useState(O),[qa,xl]=b.useState(D),[Il,mn]=b.useState(Y),[tt,Vt]=b.useState(S),[it,za]=b.useState(C),[ls,Ba]=b.useState(A),[pn,At]=b.useState(null),[He,fa]=b.useState(null),Dn=b.useRef(Z),{anchorRefs:Ha,activeAnchor:ka}=L1(n),da=st=>st==null?void 0:st.getAttributeNames().reduce((Tt,oe)=>{var _e;return oe.startsWith("data-tooltip-")&&(Tt[oe.replace(/^data-tooltip-/,"")]=(_e=st==null?void 0:st.getAttribute(oe))!==null&&_e!==void 0?_e:null),Tt},{}),Fn=st=>{const Tt={place:oe=>{var _e;hn((_e=oe)!==null&&_e!==void 0?_e:p)},content:oe=>{Vn(oe??i)},html:oe=>{dn(oe??o)},variant:oe=>{var _e;zt((_e=oe)!==null&&_e!==void 0?_e:y)},offset:oe=>{ca(oe===null?g:Number(oe))},wrapper:oe=>{var _e;Vt((_e=oe)!==null&&_e!==void 0?_e:S)},events:oe=>{const _e=oe==null?void 0:oe.split(" ");za(_e??C)},"position-strategy":oe=>{var _e;Ba((_e=oe)!==null&&_e!==void 0?_e:A)},"delay-show":oe=>{$e(oe===null?_:Number(oe))},"delay-hide":oe=>{bl(oe===null?O:Number(oe))},float:oe=>{xl(oe===null?D:oe==="true")},hidden:oe=>{mn(oe===null?Y:oe==="true")},"class-name":oe=>{At(oe)}};Object.values(Tt).forEach(oe=>oe(null)),Object.entries(st).forEach(([oe,_e])=>{var Ht;(Ht=Tt[oe])===null||Ht===void 0||Ht.call(Tt,_e)})};b.useEffect(()=>{Vn(i)},[i]),b.useEffect(()=>{dn(o)},[o]),b.useEffect(()=>{hn(p)},[p]),b.useEffect(()=>{zt(y)},[y]),b.useEffect(()=>{ca(g)},[g]),b.useEffect(()=>{$e(_)},[_]),b.useEffect(()=>{bl(O)},[O]),b.useEffect(()=>{xl(D)},[D]),b.useEffect(()=>{mn(Y)},[Y]),b.useEffect(()=>{Ba(A)},[A]),b.useEffect(()=>{Dn.current!==Z&&console.warn("[react-tooltip] Do not change `disableStyleInjection` dynamically.")},[Z]),b.useEffect(()=>{typeof window<"u"&&window.dispatchEvent(new CustomEvent("react-tooltip-inject-styles",{detail:{disableCore:Z==="core",disableBase:Z}}))},[]),b.useEffect(()=>{var st;const Tt=new Set(Ha);let oe=r;if(!oe&&n&&(oe=`[data-tooltip-id='${n.replace(/'/g,"\\'")}']`),oe)try{document.querySelectorAll(oe).forEach(te=>{Tt.add({current:te})})}catch{console.warn(`[react-tooltip] "${oe}" is not a valid CSS selector`)}const _e=document.querySelector(`[id='${l}']`);if(_e&&Tt.add({current:_e}),!Tt.size)return()=>null;const Ht=(st=He??_e)!==null&&st!==void 0?st:ka.current,Rt=new MutationObserver(te=>{te.forEach(de=>{var We;if(!Ht||de.type!=="attributes"||!(!((We=de.attributeName)===null||We===void 0)&&We.startsWith("data-tooltip-")))return;const vt=da(Ht);Fn(vt)})}),X={attributes:!0,childList:!1,subtree:!1};if(Ht){const te=da(Ht);Fn(te),Rt.observe(Ht,X)}return()=>{Rt.disconnect()}},[Ha,ka,He,l,r]),b.useEffect(()=>{ye!=null&&ye.border&&console.warn("[react-tooltip] Do not set `style.border`. Use `border` prop instead."),ue&&!Xy("border",`${ue}`)&&console.warn(`[react-tooltip] "${ue}" is not a valid \`border\`.`),ye!=null&&ye.opacity&&console.warn("[react-tooltip] Do not set `style.opacity`. Use `opacity` prop instead."),T&&!Xy("opacity",`${T}`)&&console.warn(`[react-tooltip] "${T}" is not a valid \`opacity\`.`)},[]);let yn=E;const Sl=b.useRef(null);if(u){const st=u({content:(He==null?void 0:He.getAttribute("data-tooltip-content"))||Ze||null,activeAnchor:He});yn=st?Ge.createElement("div",{ref:Sl,className:"react-tooltip-content-wrapper"},st):null}else Ze&&(yn=Ze);Nt&&(yn=Ge.createElement(OC,{content:Nt}));const wl={forwardRef:Me,id:n,anchorId:l,anchorSelect:r,className:Dd(d,pn),classNameArrow:m,content:yn,contentWrapperRef:Sl,place:ua,variant:as,offset:Bt,wrapper:tt,events:it,openOnClick:w,positionStrategy:ls,middlewares:j,delayShow:Kn,delayHide:Gn,float:qa,hidden:Il,noArrow:H,clickable:$,closeOnEsc:I,closeOnScroll:W,closeOnResize:re,openEvents:pe,closeEvents:Be,globalCloseEvents:Ee,imperativeModeOnly:Fe,style:ye,position:xe,isOpen:B,defaultIsOpen:F,border:ue,opacity:T,arrowColor:Q,arrowSize:P,setIsOpen:J,afterShow:le,afterHide:Ce,disableTooltip:ce,activeAnchor:He,setActiveAnchor:st=>fa(st),role:St};return Ge.createElement(RC,{...wl})});typeof window<"u"&&window.addEventListener("react-tooltip-inject-styles",n=>{n.detail.disableCore||Fy({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||Fy({css:`
|
|
237
|
-
.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 DC=n=>{if(!n)return;const l=pt.getQueryData([Jd]);if(!l)return;const r=pt.getQueryData([La,l.teamId]);return r==null?void 0:r.find(i=>i.id===n)},Iy=n=>window.matchMedia(n).matches;function mh(n,{defaultValue:l=!1,initializeWithValue:r=!0}={}){const[i,o]=b.useState(()=>r?Iy(n):l);return b.useLayoutEffect(()=>{const u=window.matchMedia(n);function d(){o(()=>Iy(n))}return d(),u.addListener?u.addListener(d):u.addEventListener("change",d),()=>{u.removeListener?u.removeListener(d):u.removeEventListener("change",d)}},[n]),i}const Lu={laptop:"(min-width: 1024px)"},MC=()=>window.matchMedia(Lu.laptop).matches,UC="_table_inecl_2",LC="_semi-transparent_inecl_2",qC="_table-loading_inecl_2",zC="_table-empty_inecl_2",BC="_table-row-cells_inecl_2",HC="_header-cell_inecl_2",kC="_header-actions_inecl_2",QC="_cell_inecl_2",YC="_cell-actions_inecl_2",VC="_table-config_inecl_2",KC="_table-action_inecl_2",GC="_blue_inecl_2",FC="_red_inecl_2",$C="_modal_inecl_2",XC="_options-container_inecl_2",ZC="_underlying-rows-btn_inecl_2",JC="_option-item_inecl_2",ne={table:UC,semiTransparent:LC,tableLoading:qC,tableEmpty:zC,tableRowCells:BC,headerCell:HC,headerActions:kC,cell:QC,cellActions:YC,tableConfig:VC,tableAction:KC,blue:GC,red:FC,modal:$C,optionsContainer:XC,underlyingRowsBtn:ZC,optionItem:JC},oa=b.createContext({name:"No name",hooks:[],availableJoins:[],allColumns:[],dataSourceId:"",entities:[],getValue:()=>{},getColumnType:()=>{},getEntityKey:()=>[]}),yt=b.createContext({state:fr({}),setState:()=>{}}),Yn=b.createContext({}),q1=()=>{const[n,l]=b.useState();return b.useMemo(()=>({show:!!n,position:n,open:i=>{i.preventDefault(),l({x:i.clientX-1,y:i.clientY-1})},close:()=>{l(void 0)}}),[n])},PC=n=>{if(n==="ASC")return"DESC";if(n!=="DESC")return"ASC"},IC=()=>{const{state:n,setState:l}=b.useContext(yt),r=b.useCallback(i=>{l(o=>{const u=o.orderBy[0];if(u&&u.column===i){const d=PC(u.direction);return d?{...o,orderBy:[{column:i,direction:d}]}:{...o,orderBy:[]}}return{...o,orderBy:[{column:i,direction:"ASC"}]}})},[l]);return{orderBy:n.orderBy,updateOrderBy:r}};function WC(n){var r;const l=(r=n.target)==null?void 0:r.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 od(n,l,r){var u,d,m;const i=(d=(u=n==null?void 0:n.rows)==null?void 0:u[l])==null?void 0:d[r],o=(m=n==null?void 0:n.columns)==null?void 0:m[r];return{value:i,column:o}}const e_=()=>{const{data:n}=b.useContext(Yn),{getColumnType:l}=b.useContext(oa),{setState:r}=b.useContext(yt),i=m=>{const{value:y,column:p}=od(n,m.row,m.col);if(p){const g=Gl(y,l(p.full));navigator.clipboard.writeText(g),qt.success("Copied!")}},o=m=>{const{value:y,column:p}=od(n,m.row,m.col);if(p){const g=Gl(y,l(p.full));E1(g)}},u=m=>{const{value:y,column:p}=od(n,m.row,m.col);let g=(p==null?void 0:p.full)||"",S;if((p==null?void 0:p.table)===""){qt.error("Filtering on aggregated column is not supported yet");return}if(g){let E;if(y==null)E={id:Ua(),isEnabled:!0,column:g,connector:"AND",operator:"IS NULL"};else{const C=Gl(y,l(g));E={id:Ua(),isEnabled:!0,column:g,connector:"AND",operator:"=",fn:S,value:[{value:C}]}}r(C=>({...C,filters:[...C.filters,E]})),qt.success(`Added new filter on column ${p==null?void 0:p.alias}`)}};return m=>{const y=WC(m);y&&(y.action==="copy"?i(y):y.action==="show"?o(y):y.action==="filter"&&u(y))}},t_="_container_hnjf3_2",n_="_content_hnjf3_2",a_="_backdrop_hnjf3_2",ud={container:t_,content:n_,backdrop:a_},z1=({children:n,handler:l})=>{const r=b.useRef(l.close);r.current=l.close;const i=b.useMemo(()=>{if(!l.position)return;const o={};if(typeof window<"u"){const u=l.position.y>window.innerHeight/2,d=l.position.x>window.innerWidth/2;u?o.bottom=window.innerHeight-l.position.y:o.top=l.position.y,MC()?d?o.right=window.innerWidth-l.position.x:o.left=l.position.x:(o.right=36,o.left=36)}return o},[l]);return b.useEffect(()=>{const o=u=>{u.code==="Escape"&&r.current()};return window.addEventListener("keyup",o),()=>{window.removeEventListener("keyup",o)}},[]),i?h.jsxs("div",{className:ud.container,children:[h.jsx("div",{className:ud.backdrop,onClick:o=>{o.stopPropagation(),o.preventDefault(),l.close()}}),h.jsx("div",{className:ud.content,style:i,children:n})]}):null},l_="_table_12hui_2",i_="_root_12hui_2",s_="_content_12hui_2",r_="_sub_12hui_2",ko={table:l_,root:i_,content:s_,sub:r_},B1=({hook:n,onClick:l})=>h.jsxs("button",{className:ko.root,onClick:l,title:n.where,children:[h.jsx("span",{children:"📄"}),h.jsxs("div",{className:ko.content,children:[h.jsxs("p",{className:ko.table,children:[" ",n.on.toTable]}),h.jsxs("span",{className:ko.sub,children:[n.on.toColumn," = ",n.on.fromTable,".",n.on.fromColumn]})]})]},n.where),pl=(n,l)=>n!=null&&n>l,o_=({handler:n,rowIndex:l})=>{const{hooks:r,entities:i,dataSourceId:o,getEntityKey:u,getValue:d}=b.useContext(oa),{state:m}=b.useContext(yt),{data:y}=b.useContext(Yn),[p,g]=b.useState(""),[S,E]=b.useState(""),C=b.useMemo(()=>y==null?void 0:y.rows[l],[y,l]),w=()=>{C&&(yl("⬇️ "+m.table,{joins:m.joins,table:m.table,dataSourceId:m.dataSourceId,filters:[...m.filters,...m.groupBy.map(Y=>({id:Ua(),connector:"AND",column:Y.value,operator:"=",value:[{value:d(C,Y)}]}))]},!0),n.close())},A=Y=>{if(!C)return;const H=d(C,{value:`${Y.on.fromTable}.${Y.on.fromColumn}`});yl(`↗️ ${Y.on.toColumn} equals ${H}`,{table:Y.on.toTable,dataSourceId:o,filters:[{id:Ua(),column:Y.on.toTable+"."+Y.on.toColumn,operator:H==null?"IS NULL":"=",connector:"AND",value:H!=null?[{value:H,isColumn:!1}]:void 0}]},!0),n.close()},j=Y=>{if(!C)return;const H=u(Y,C);n.close(),sh({tableName:Y,dataSourceId:o,entityId:H}),n.close()},_=b.useMemo(()=>p?i.filter(Y=>Y.includes(p)):i,[i,p]),O=b.useMemo(()=>{if(!y)return[];const Y=S.toLowerCase();return r.filter(H=>y.columns.some(I=>I.column===H.on.fromColumn&&I.table===H.on.fromTable)?H.on.toTable.toLowerCase().includes(Y):!1)},[S,r,y]),D=m.groupBy.length>0;return h.jsxs(z1,{handler:n,children:[i.length>0&&h.jsxs("div",{className:ne.optionsContainer,children:[h.jsxs("label",{className:"flex justify-between items-center gap-2 sticky left-0 top-0 input",children:[h.jsx("span",{className:"font-semibold",children:"📝"}),h.jsx("input",{className:"flex-1 outline-0",placeholder:"Edit/View row",value:p,onChange:Y=>g(Y.target.value)})]}),h.jsx("div",{className:"flex flex-col",children:pl(_.length,0)?_.map(Y=>h.jsx("button",{className:se(ne.optionItem,"font-semibold"),onClick:()=>j(Y),children:h.jsxs("span",{children:["📄 ",Y]})},Y)):h.jsx("p",{className:"text-center text-gray-800",children:"Empty"})})]}),r.length>0&&h.jsxs("div",{className:ne.optionsContainer,children:[h.jsxs("label",{className:"flex justify-between items-center gap-2 sticky left-0 top-0 p-1 input",children:[h.jsx("span",{className:"font-semibold",children:"↗️"}),h.jsx("input",{className:"flex-1 outline-0",placeholder:"Connected tables",value:S,onChange:Y=>E(Y.target.value)})]}),h.jsx("div",{className:"flex flex-col",children:O.length>0?O.map(Y=>h.jsx(B1,{hook:Y,onClick:()=>A(Y)},Y.where)):h.jsx("p",{className:"text-center text-gray-800",children:"Empty"})})]}),D&&h.jsx("button",{onClick:w,className:ne.underlyingRowsBtn,children:"🎯 Underlying rows"})]})},u_={ASC:"⬆️",DESC:"⬇️"},c_=()=>{const{data:n}=b.useContext(Yn),{orderBy:l,updateOrderBy:r}=IC(),i=(n==null?void 0:n.columns)||[],o=l[0];return h.jsx("thead",{children:h.jsx("tr",{children:i.map(u=>h.jsxs("td",{className:ne.headerCell,children:[h.jsxs("div",{className:"overflow-hidden",children:[h.jsx("p",{className:"text-xs truncate",children:u.table||"-"}),h.jsx("p",{className:"text-sm font-bold truncate",children:u.column})]}),h.jsx("div",{className:ne.headerActions,children:h.jsx("button",{onClick:()=>r(u.full),children:(o==null?void 0:o.column)===u.full?u_[o.direction]:"↕️"})})]},u.full))})})};function f_({value:n,row:l,col:r}){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 i=Gl(n);return h.jsxs(h.Fragment,{children:[h.jsx("span",{"data-row":l,className:"truncate block pointer-events-none",children:i}),h.jsxs("div",{className:ne.cellActions,children:[h.jsx("button",{"data-copy-col":r,"data-copy-row":l,children:"📋"}),h.jsx("button",{"data-show-col":r,"data-show-row":l,children:"👀"}),h.jsx("button",{"data-filter-col":r,"data-filter-row":l,children:"🔎"})]})]})}const d_=b.memo(({row:n,isLastRow:l,index:r})=>h.jsx("tr",{className:se(ne.tableRowCells,l&&"rounded-b-lg"),children:n.map((i,o)=>h.jsx("td",{className:ne.cell,"data-row":r,children:h.jsx(f_,{value:i,col:o,row:r})},o))})),h_=()=>{var g,S;const{data:n,error:l,isLoading:r,isFetching:i}=b.useContext(Yn),o=ih(l),u=e_(),d=q1(),[m,y]=b.useState(void 0),p=E=>{var A;const C=(A=E.target)==null?void 0:A.dataset,w=C==null?void 0:C.row;w!=null&&(y(parseInt(w)),d.open(E))};return h.jsxs(h.Fragment,{children:[m!=null&&d.show&&h.jsx(o_,{handler:d,rowIndex:m}),o&&h.jsx(Lt,{className:"my-4",variant:"danger",children:o}),r&&h.jsx("div",{className:ne.tableLoading,children:"Loading data"}),n&&h.jsxs("table",{className:se(ne.table,i&&ne.semiTransparent),onContextMenu:p,onClick:u,children:[h.jsx(c_,{}),h.jsxs("tbody",{children:[((g=n.rows)==null?void 0:g.length)<1&&h.jsx("tr",{className:ne.tableEmpty,children:h.jsx("td",{colSpan:n.columns.length,children:"No data"})}),(S=n.rows)==null?void 0:S.map((E,C)=>h.jsx(d_,{index:C,row:E,isLastRow:C===n.rows.length-1},C))]})]})]})},m_="_root_valvq_2",p_="_root-show_valvq_2",y_="_content-desktop_valvq_2",v_="_content-mobile_valvq_2",g_="_card_valvq_2",b_="_cards-list_valvq_2",x_="_sub-text_valvq_2",S_="_text_valvq_2",w_="_section-title_valvq_2",E_="_sidebar-action_valvq_2",C_="_sidebar-add-action_valvq_2",__="_section-container_valvq_2",j_="_close-button_valvq_2",N_="_section-open-btn_valvq_2",A_="_show_valvq_2",ie={root:m_,rootShow:p_,contentDesktop:y_,contentMobile:v_,card:g_,cardsList:b_,subText:x_,text:S_,sectionTitle:w_,sidebarAction:E_,sidebarAddAction:C_,sectionContainer:__,closeButton:j_,sectionOpenBtn:N_,show:A_};function T_(n,l){if(!n&&!l)return!0;if(!n||!l||n.length!==l.length)return!1;for(let r=0;r<n.length;r++)if(n[r]!==l[r])return!1;return!0}const H1=()=>{const{state:n,setState:l}=b.useContext(yt),r=b.useCallback(o=>{l(u=>({...u,filters:o}))},[l]),i=b.useCallback(o=>{l(u=>({...u,filters:u.filters.filter(d=>!(o.column===d.column&&o.operator===d.operator&&T_(o.value,d.value)))}))},[l]);return{filters:n.filters,removeFilter:i,setFilters:r}},R_=(n,l)=>n.type!==l.type||n.on!==l.on||n.table!==l.table,O_=(n,l)=>n.type===l.type&&n.on===l.on&&n.table===l.table,k1=()=>{const{state:n,setState:l}=b.useContext(yt),r=b.useCallback(i=>{l(o=>{const u=o.joins;if(u.some(m=>O_(m,i))){const m=i.table+".";return{...o,joins:u.filter(y=>R_(y,i)),columns:o.columns.filter(y=>!y.value.startsWith(m)),groupBy:o.groupBy.filter(y=>!y.value.startsWith(m)),orderBy:o.orderBy.filter(y=>!y.column.startsWith(m)),aggregations:o.aggregations.filter(y=>!y.value.startsWith(m)),filters:o.filters.filter(y=>!y.column.startsWith(m))}}return{...o,joins:[...u,i]}})},[l]);return{joins:n.joins,toggle:r}},ph=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"})),ki=new Map,D_=n=>{const l=[];return n.ctrlKey&&l.push("CTRL"),n.altKey&&l.push("ALT"),n.shiftKey&&l.push("SHIFT"),n.metaKey&&l.push("META"),l.push(n.key.toLowerCase()),l.join("+")},M_=n=>{var i,o,u;const l=(o=(i=n.target)==null?void 0:i.tagName)==null?void 0:o.toLowerCase();if(n.ctrlKey||n.altKey||n.metaKey||["input","textarea","select"].includes(l)||(u=n.target)!=null&&u.isContentEditable)return;const r=ki.get(D_(n));r&&r.length>0&&r[r.length-1].callback()},U_=(n,l,r="")=>{const i=n.toLowerCase(),o=ki.get(n);return o?ki.set(n,[...o,{callback:l,label:r}]):ki.set(i,[{callback:l,label:r}]),()=>{const u=n.toLowerCase(),d=ki.get(u);d&&ki.set(u,d.filter(m=>m.callback!==l))}};window.addEventListener("keyup",M_);function Tn(n,l,r){const i=b.useRef({callback:l,label:r});i.current.callback=l,b.useEffect(()=>U_(n,()=>{i.current.callback()},i.current.label),[n])}const L_=()=>{const n=xr("Hotkey"),l=Pt(),r=jt(),{data:i}=sa();Tn("n",()=>{i&&n()},"📖 New query"),Tn("w",()=>{if(!i)return;Ru.get().length<1?n():r.pathname!==Ue.workbench.path&&l(Ue.workbench.path)},"🛠️ Open Workbench"),Tn("h",()=>{r.pathname!==Ue.home.path&&l(Ue.home.path)},"🏠 Go home")},[q_,z_]=It(!1),yh=()=>z_(n=>!n),B_="_sidebar_1tu0c_2",H_="_sidebar-visible_1tu0c_2",k_="_sidebar-container_1tu0c_2",Q_="_sidebar-invisible_1tu0c_2",Y_="_backdrop_1tu0c_2",ir={sidebar:B_,sidebarVisible:H_,sidebarContainer:k_,sidebarInvisible:Q_,backdrop:Y_},V_=({children:n,backdropClose:l,isVisible:r,onClose:i,onClosed:o,contentClassName:u})=>{const[d,m]=b.useState(!1),y=()=>{l&&i()},p=g=>{r||getComputedStyle(g.currentTarget).opacity==="0"&&(m(!1),o&&o())};return b.useEffect(()=>{r&&m(!0)},[r]),h.jsxs("div",{onTransitionEnd:p,className:se(ir.sidebar,r?ir.sidebarVisible:ir.sidebarInvisible),children:[h.jsx("div",{onClick:y,className:ir.backdrop}),h.jsx("div",{className:se(ir.sidebarContainer,u),children:d&&n})]})},[qu,vh]=It({filters:!1,joins:!1,columns:!1,groupBy:!1,aggregate:!1}),qn=n=>vh(l=>({...l,[n]:!0})),zu=n=>vh(l=>({...l,[n]:!1})),mu=n=>vh(l=>({...l,[n]:!l[n]})),K_=()=>{const n=q_();return mh(Lu.laptop)?h.jsx("div",{className:se(ie.root,n&&ie.rootShow),children:h.jsxs("div",{className:se(ie.contentDesktop,"no-scrollbar"),children:[h.jsx(ev,{}),h.jsx(Wy,{}),h.jsx(sv,{}),h.jsx(iv,{}),h.jsx(lv,{}),h.jsx(nv,{}),h.jsx(av,{}),h.jsx(tv,{})]})}):h.jsx(V_,{isVisible:n,onClose:yh,backdropClose:!0,children:h.jsxs("div",{className:ie.contentMobile,children:[h.jsx(ev,{}),h.jsx(Wy,{}),h.jsx(sv,{}),h.jsx(iv,{}),h.jsx(lv,{}),h.jsx(nv,{}),h.jsx(av,{}),h.jsx(tv,{})]})})};function jr({onShow:n,show:l,title:r,items:i}){return h.jsxs("div",{className:"flex justify-between items-center",children:[h.jsx("p",{className:ie.sectionTitle,children:r}),i>0&&h.jsxs("button",{className:se(ie.sectionOpenBtn,l&&ie.show),onClick:n,children:[h.jsx("span",{children:i}),h.jsx(ph,{width:16,height:16})]})]})}function Wy(){const{name:n,tabId:l}=b.useContext(oa),{data:r}=b.useContext(Yn),i=()=>{l&&Pl("New tab name",n).then(u=>{u&&Ou(l,u)})},o=()=>{r!=null&&r.query&&(navigator.clipboard.writeText(r==null?void 0:r.query),qt.success("Query copied to clipboard"))};return Tn("r",i,"Rename tab"),h.jsxs("div",{className:"grid lg:grid-cols-2 gap-1 px-2 mb-4",children:[h.jsx("button",{className:ie.sidebarAction,onClick:i,children:h.jsx("span",{children:"✏️ Rename tab"})}),h.jsx("button",{className:ie.sidebarAction,onClick:o,children:h.jsx("span",{children:"🖋️ Copy SQL"})})]})}function ev(){const{state:n}=b.useContext(yt),{data:l}=Nu(n.dataSourceId);return h.jsxs("div",{className:ie.sectionContainer,children:[h.jsx("div",{className:ie.card,children:h.jsxs("div",{children:[h.jsx("p",{className:ie.subText,children:"📄 Table"}),h.jsx("p",{className:se(ie.text,"text-blue-600"),children:n.table})]})}),h.jsx("div",{className:se(ie.card,"mt-2"),children:h.jsxs("div",{children:[h.jsx("p",{className:ie.subText,children:"📦 Data source"}),h.jsx("p",{className:se(ie.text,"text-blue-600"),children:l==null?void 0:l.name})]})})]})}function tv(){const{state:n,setState:l}=b.useContext(yt),[r,i]=b.useState(!0),o=u=>{l(d=>({...d,groupBy:d.groupBy.filter(m=>ta(m)!==u)}))};return h.jsxs("div",{className:ie.sectionContainer,children:[h.jsx(jr,{title:"📚 Group by",show:r,onShow:()=>i(!r),items:n.groupBy.length}),r&&n.groupBy.length>0&&h.jsx("div",{className:ie.cardsList,children:n.groupBy.map(u=>h.jsxs("div",{className:ie.card,children:[h.jsx("span",{className:ie.text,children:ta(u)}),h.jsx("button",{className:ie.closeButton,onClick:()=>o(ta(u)),children:h.jsx(Qn,{width:20,height:20})})]},ta(u)))}),h.jsxs("button",{className:ie.sidebarAddAction,onClick:()=>qn("groupBy"),children:[h.jsx("span",{className:"hotkey",children:"G"}),h.jsx("span",{children:"Add group by"})]})]})}function nv(){const{state:n,setState:l}=b.useContext(yt),[r,i]=b.useState(!1),o=d=>{l(m=>({...m,columns:m.columns.filter(y=>ta(y)!==d)}))},u=n.aggregations.length>0||n.groupBy.length>0;return h.jsxs("div",{className:ie.sectionContainer,children:[h.jsx(jr,{title:"👀 Columns",show:r,onShow:()=>i(!r),items:u?0:n.columns.length}),u&&h.jsx(Lt,{variant:"warning",className:"border border-yellow-800 my-2",children:h.jsx("span",{className:ie.text,children:"Columns are ignored when there is at least one aggregation or group by"})}),!u&&r&&n.columns.length>0&&h.jsx("div",{className:ie.cardsList,children:n.columns.map(d=>h.jsxs("div",{className:ie.card,children:[h.jsx("span",{className:ie.text,children:ta(d)}),h.jsx("button",{className:ie.closeButton,onClick:()=>o(ta(d)),children:h.jsx(Qn,{width:20,height:20})})]}))}),!u&&h.jsxs("button",{className:ie.sidebarAddAction,onClick:()=>qn("columns"),children:[h.jsx("span",{className:"hotkey",children:"C"}),h.jsx("span",{children:"Show/Hide columns"})]})]})}function av(){const{state:n,setState:l}=b.useContext(yt),[r,i]=b.useState(!0),o=u=>{const d=ta(u);l(m=>({...m,aggregations:m.aggregations.filter(y=>y.fn!==u.fn||y.value!==u.value),orderBy:m.orderBy.filter(y=>y.column!==d)}))};return h.jsxs("div",{className:ie.sectionContainer,children:[h.jsx(jr,{title:"🔢 Aggregations",show:r,onShow:()=>i(!r),items:n.aggregations.length}),r&&n.aggregations.length>0&&h.jsx("div",{className:ie.cardsList,children:n.aggregations.map(u=>h.jsxs("div",{className:ie.card,children:[h.jsxs("span",{className:ie.text,children:[u.fn," ",u.value]}),h.jsx("button",{className:ie.closeButton,onClick:()=>o(u),children:h.jsx(Qn,{width:20,height:20})})]}))}),h.jsxs("button",{className:ie.sidebarAddAction,onClick:()=>qn("aggregate"),children:[h.jsx("span",{className:"hotkey",children:"A"}),h.jsx("span",{children:"Aggregate data"})]})]})}const G_=n=>(n==null?void 0:n.map(l=>l.value).join(", "))||"";function lv(){const{state:n}=b.useContext(yt),{removeFilter:l}=H1(),[r,i]=b.useState(!0),o=()=>{qn("filters")};return h.jsxs("div",{className:ie.sectionContainer,children:[h.jsx(jr,{title:"🎚️ Filters",show:r,onShow:()=>i(!r),items:n.filters.length}),r&&n.filters.length>0&&h.jsx("div",{className:ie.cardsList,children:n.filters.map((u,d)=>h.jsxs("div",{className:ie.card,children:[h.jsxs("div",{className:"overflow-hidden",children:[h.jsx("p",{className:se(ie.subText,"truncate"),children:u.column}),h.jsxs("p",{className:se(ie.text,"truncate"),children:[Wd[u.operator]," ",G_(u.value)]})]}),h.jsx("button",{className:ie.closeButton,onClick:()=>l(u),children:h.jsx(Qn,{width:20,height:20})})]},d))}),h.jsxs("button",{className:ie.sidebarAddAction,onClick:o,children:[h.jsx("span",{className:"hotkey",children:"F"}),h.jsx("span",{children:"Filter data"})]})]})}function iv(){const{toggle:n}=k1(),{availableJoins:l}=b.useContext(oa),{state:r}=b.useContext(yt),[i,o]=b.useState(!0);return h.jsxs("div",{className:ie.sectionContainer,children:[h.jsx(jr,{title:"📄 Joins",show:i,onShow:()=>o(!i),items:r.joins.length}),i&&r.joins.length>0&&h.jsx("div",{className:ie.cardsList,children:r.joins.map((u,d)=>h.jsxs("div",{className:ie.card,children:[h.jsxs("div",{className:"overflow-hidden",children:[h.jsxs("p",{className:se(ie.subText,"truncate"),children:["on ",u.on]}),h.jsx("p",{className:ie.text,children:u.table})]}),d===r.joins.length-1&&h.jsx("button",{className:ie.closeButton,onClick:()=>n(u),children:h.jsx(Qn,{width:20,height:20})})]},u.table+u.on))}),l.length>0&&h.jsxs("button",{onClick:()=>qn("joins"),className:ie.sidebarAddAction,children:[h.jsx("span",{className:"hotkey",children:"J"}),h.jsx("span",{children:"Join table"})]})]})}function sv(){const{state:n,setState:l}=b.useContext(yt);if(!n.orderBy.length)return null;const r=i=>{l(o=>({...o,orderBy:o.orderBy.filter(u=>u.column!==i.column&&u.direction!==i.direction)}))};return h.jsxs("div",{className:ie.sectionContainer,children:[h.jsx("p",{className:ie.sectionTitle,children:"Order by"}),h.jsx("div",{className:ie.cardsList,children:n.orderBy.map((i,o)=>h.jsxs("div",{className:ie.card,children:[h.jsxs("div",{className:"overflow-hidden",children:[h.jsx("p",{className:se(ie.subText,"truncate"),children:i.direction}),h.jsx("p",{className:ie.text,children:i.column})]}),h.jsx("button",{className:ie.closeButton,onClick:()=>r(i),children:h.jsx(Qn,{width:20,height:20})})]},o))})]})}const Q1=()=>{const{state:n,setState:l}=b.useContext(yt),r=b.useCallback(o=>{l(u=>({...u,page:o}))},[l]),i=b.useCallback(o=>{l(u=>({...u,size:o}))},[l]);return{page:n.page,size:n.size,setSize:i,setPage:r}},F_=n=>fn({queryKey:["query",n],queryFn:async()=>{const{data:l}=await Ve.get("/queries/"+n);return l.data},enabled:!!n}),$_=()=>cn({mutationFn:async n=>{const{data:l}=await Ve.post("/saved-queries",n);return l.data},onSuccess:()=>{pt.invalidateQueries(["queries"]),Wi()}}),X_=()=>cn({mutationFn:async n=>Ve.delete("/saved-queries/"+n),onSuccess:()=>{Wi()}}),Z_=()=>cn({mutationFn:async({id:n,payload:l})=>{const{data:r}=await Ve.patch("/queries/"+n,l);return r.data},onSuccess:n=>{pt.invalidateQueries(["query",n.id]),Wi(),k3(),n.isTrash}}),[J_,Y1]=It(void 0),Ud=()=>Y1(void 0);function P_(){return h.jsxs("div",{className:"flex items-center bg-white border-b border-gray-200 overflow-auto no-scrollbar",children:[h.jsx(I_,{}),h.jsx(W_,{}),h.jsx(ej,{}),h.jsx(tj,{})]})}function I_(){const{dataSourceId:n,name:l,tabId:r}=b.useContext(oa),{data:i}=Nu(n),{data:o}=b.useContext(Yn),u=Sr(Xt.EDITOR),d=$_(),m=()=>{var p,g;(p=o==null?void 0:o.columns)!=null&&p[0].table&&lh({table:(g=o==null?void 0:o.columns)==null?void 0:g[0].table,dataSourceId:n})},y=async()=>{const p=await Pl("Query name",l);!p||!(o!=null&&o.queryHistoryId)||(d.mutate({name:p,queryId:o.queryHistoryId}),r&&Ou(r,p))};return Tn("s",y,"Save query"),h.jsxs("div",{className:ne.tableConfig,children:[h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Manage filters",onClick:()=>qn("filters"),className:se(ne.tableAction,ne.blue),children:[h.jsx("span",{children:"Filter"}),h.jsx("span",{className:"hotkey",children:"F"})]}),h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Join tables",onClick:()=>qn("joins"),className:se(ne.tableAction,ne.blue),children:[h.jsx("span",{children:"Join"}),h.jsx("span",{className:"hotkey",children:"J"})]}),h.jsx(nj,{}),h.jsxs("button",{"data-tooltip-id":"explorer-more-actions",className:se(ne.tableAction,ne.blue),children:[h.jsx("span",{className:"whitespace-nowrap",children:"More actions"}),h.jsx(ph,{width:16,height:16,className:"rotate-90"})]}),h.jsxs(hh,{id:"explorer-more-actions",className:"z-10 shadow-md flex flex-col",clickable:!0,variant:"light",opacity:1,children:[h.jsxs("button",{onClick:()=>qn("columns"),className:se(ne.tableAction,ne.modal,ne.blue,"justify-between"),children:[h.jsx("span",{children:"Columns"}),h.jsx("span",{className:"hotkey",children:"C"})]}),h.jsxs("button",{onClick:()=>qn("groupBy"),className:se(ne.tableAction,ne.modal,ne.blue,"justify-between"),children:[h.jsx("span",{children:"Group by"}),h.jsx("span",{className:"hotkey",children:"G"})]}),h.jsxs("button",{onClick:()=>qn("aggregate"),className:se(ne.tableAction,ne.modal,ne.blue,"justify-between"),children:[h.jsx("span",{children:"Aggregate"}),h.jsx("span",{className:"hotkey",children:"A"})]}),h.jsxs("button",{onClick:yh,className:se(ne.tableAction,ne.modal,ne.blue,"justify-between"),children:[h.jsx("span",{children:"Query editor"}),h.jsx("span",{className:"hotkey",children:"E"})]}),u&&h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"h-0.5 my-2 bg-gray-100"}),h.jsxs("button",{onClick:y,className:se(ne.tableAction,ne.modal,ne.blue),children:[h.jsx("span",{children:"Save query"}),h.jsx("span",{className:"hotkey",children:"S"})]}),(i==null?void 0:i.allowInsert)===!0&&h.jsx("button",{onClick:m,className:se(ne.tableAction,ne.modal,ne.blue),children:"Insert new row"})]})]})]})}function W_(){const{name:n}=b.useContext(oa),{state:l}=b.useContext(yt),{refetch:r,data:i}=b.useContext(Yn),o=(window==null?void 0:window.location.hostname)!=="localhost",u=xr("Workbook"),d=()=>{yl(n,l,!0),Ud()},m=()=>{if(i!=null&&i.queryHistoryId){const y=new URL(window.location.href);y.pathname=Ue.share.path,y.searchParams.set("shareId",i.queryHistoryId),navigator.clipboard.writeText(y.toString()),qt.success("Share link copied to clipboard")}};return Tn("e",yh,"Show editor sidebar"),h.jsxs("div",{className:ne.tableConfig,children:[h.jsx("button",{"data-tooltip-id":"default","data-tooltip-content":"Refresh data",onClick:r,className:se(ne.tableAction,ne.blue),children:"Refresh"}),o&&h.jsx("button",{"data-tooltip-id":"default","data-tooltip-content":"Share query",onClick:m,className:se(ne.tableAction,ne.blue),children:"Share"}),h.jsx("button",{"data-tooltip-id":"default","data-tooltip-content":"Clone in a new tab",onClick:d,className:se(ne.tableAction,ne.blue),children:"Clone"}),h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Start new query tab",onClick:u,className:se(ne.tableAction,ne.blue),children:[h.jsx("span",{className:"whitespace-nowrap",children:"New query"}),h.jsx("span",{className:"hotkey",children:"N"})]})]})}function ej(){const{page:n,size:l,setPage:r}=Q1(),{data:i}=b.useContext(Yn),o=(i==null?void 0:i.rows.length)===l;return h.jsxs("div",{className:ne.tableConfig,children:[h.jsx("button",{"data-tooltip-content":"Previous page","data-tooltip-id":"default",disabled:n<=0,className:se(ne.tableAction,ne.blue),onClick:()=>r(n-1),children:"Prev"}),h.jsx("span",{className:"text-sm bg-gray-50 rounded-md px-2 border border-gray-200",children:n+1}),h.jsx("button",{"data-tooltip-content":"Next page","data-tooltip-id":"default",disabled:!o,className:se(ne.tableAction,ne.blue),onClick:()=>r(n+1),children:"Next"})]})}function tj(){const{size:n,setSize:l}=Q1();return h.jsx("div",{className:ne.tableConfig,children:h.jsx("label",{className:ne.tableAction,"data-tooltip-content":"Size","data-tooltip-id":"default",children:h.jsxs("select",{style:{height:"20px"},value:n,onChange:r=>l(parseInt(r.target.value,10)),children:[h.jsx("option",{value:5,children:"5 rows"}),h.jsx("option",{value:10,children:"10 rows"}),h.jsx("option",{value:20,children:"20 rows"}),h.jsx("option",{value:50,children:"50 rows"}),h.jsx("option",{value:100,children:"100 rows"}),h.jsx("option",{value:200,children:"200 rows"})]})})})}function nj(){const{state:n,setState:l}=b.useContext(yt),r=()=>{l(o=>({...o,searchAll:void 0}))},i=()=>{Pl("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(o=>{o!==void 0&&l(u=>({...u,searchAll:o.length>0?o:void 0}))})};return Tn("k",i,"Search text"),n.searchAll?h.jsx("button",{"data-tooltip-id":"default","data-tooltip-content":"Remove search all filter",onClick:r,className:se(ne.tableAction,ne.red),children:h.jsxs("span",{className:"truncate px-1",children:["❌ ",n.searchAll]})}):h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Search text in all columns",onClick:i,className:se(ne.tableAction,ne.blue),children:[h.jsx("span",{className:"whitespace-nowrap",children:"Search text"}),h.jsx("span",{className:"hotkey",children:"K"})]})}const aj="_drop-container_1labe_2",lj="_item_1labe_2",rv={dropContainer:aj,item:lj},Ld=({dataSourceId:n,focusId:l,placeholder:r="Column",onChange:i,value:o,autoFocus:u,allowTables:d})=>{const{data:m}=es(n),y=b.useRef(null),p=b.useMemo(()=>{if(!m)return[];let _=m;return d&&(_=m.filter(O=>d.includes(O.tableName))),_.flatMap(O=>O.columns.map(D=>({value:O.tableName+"."+D.name,label:D.name,table:O.tableName,searchValue:D.name.toLowerCase()})))},[m,d]),g=b.useMemo(()=>{const _=o.toLowerCase()||"",O=[];for(let D=0;D<p.length&&O.length<10;D++)p[D].searchValue.includes(_)&&O.push(p[D]);return O},[p,o]),[S,E]=b.useState(!1),[C,w]=b.useState(0),A=_=>{var O;if(_.key==="ArrowDown")_.preventDefault(),w(D=>(D+1)%g.length);else if(_.key==="ArrowUp")_.preventDefault(),w(D=>(D-1+g.length)%g.length);else if(_.key==="Enter"&&C>=0&&C<g.length){_.preventDefault();const D=g[C].value;E(!1);const Y=p.findIndex(H=>H.value===D)>-1;i(((O=g[C])==null?void 0:O.value)||D,Y,!0)}};b.useEffect(()=>{var O;const _=(O=y.current)==null?void 0:O.querySelector('[data-is-active="true"]');_&&_.scrollIntoView({behavior:"smooth",block:"nearest"})},[C]);const j=_=>{const O=_.currentTarget.value,D=p.findIndex(Y=>Y.value===O)>-1;i(O,D,!1)};return h.jsxs("div",{className:"relative",onFocus:()=>E(!0),onBlur:()=>E(!1),children:[h.jsx("input",{autoFocus:u,onKeyDown:A,value:o,onChange:j,className:"input w-full",placeholder:r,"data-focus":l}),S&&g.length>0&&h.jsx("div",{className:rv.dropContainer,ref:y,tabIndex:-1,children:g.map((_,O)=>h.jsxs("div",{className:rv.item,"data-is-active":C===O,onMouseDownCapture:D=>{D.preventDefault(),E(!1),i(_.value,!0,!0)},children:[h.jsx("span",{className:"text-xs font-semibold truncate",children:_.table}),h.jsx("p",{className:"truncate text-sm",children:_.label})]},O))})]})},ij="_drop-container_jg8ux_2",sj="_item_jg8ux_2",ov={dropContainer:ij,item:sj};function rj(n){return o4.includes(n)?i4:u4.includes(n)?l4:c4.includes(n)?s4:Id}const oj=({value:n,onChange:l,autoFocus:r,focusId:i,colType:o})=>{const u=b.useMemo(()=>{const E=n.toLowerCase()||"";return rj(o||"").filter(C=>C.label.includes(E))},[n,o]),d=b.useRef(null),[m,y]=b.useState(!1),[p,g]=b.useState(0),S=E=>{var C;E.key==="ArrowDown"?(E.preventDefault(),g(w=>(w+1)%u.length)):E.key==="ArrowUp"?(E.preventDefault(),g(w=>(w-1+u.length)%u.length)):E.key==="Enter"&&(p>=0&&p<u.length?(E.preventDefault(),y(!1),l(((C=u[p])==null?void 0:C.label)||"",!0)):l(n,!0))};return b.useEffect(()=>{var C;const E=(C=d.current)==null?void 0:C.querySelector('[data-is-active="true"]');E&&E.scrollIntoView({behavior:"smooth",block:"nearest"})},[p]),h.jsxs("div",{className:"relative",children:[h.jsx("input",{onKeyDown:S,value:n,onChange:E=>l(E.target.value,!1),className:"input w-full",placeholder:"Operator",autoFocus:r,onFocus:()=>y(!0),onBlur:()=>y(!1),"data-focus":i}),m&&u.length>0&&h.jsx("ul",{className:ov.dropContainer,ref:d,tabIndex:-1,children:u.map((E,C)=>h.jsx("li",{className:ov.item,"data-is-active":p===C,onMouseDownCapture:w=>{w.preventDefault(),y(!1),l(E.label,!0)},children:E.label},C))})]})},uj="_actions_r2knb_2",cj="_filter-actions_r2knb_2",V1={actions:uj,filterActions:cj},fj=["=","<",">",">=","<>","!=","<="];function dj(n){for(let l=0;l<n.length;l++){const r=n[l];if(!r.operator.length&&!r.value.length&&!r.column.length)continue;if(!r.column.includes("."))return qt.error(`Filter #${l+1} has invalid column value`),!1;const i=eh[r.operator];if(!i)return qt.error(`Filter #${l+1} has invalid operator`),!1;if(r.isColumnRef&&!fj.includes(i))return qt.error(`Filter #${l+1} cannot reference another column because it uses '${r.operator}' operator`),!1}return!0}function hj(n){const l=[];return n.forEach(r=>{if(!r.operator.length||!r.column.length||r.operator!=="is null"&&r.operator!=="is not null"&&!r.value.length)return;const i=eh[r.operator];l.push({id:r.id,value:r.isColumnRef?[{value:r.value,isColumn:!0}]:r4(i,r.value),operator:i,column:r.column,isEnabled:!0,connector:"AND"})}),l}function mj(n){let l="";if(n.value)for(let r=0;r<n.value.length;r++)l+=n.value[r].value,r<n.value.length-1&&(l+=", ");return l}const pj=({filter:n,dataSourceId:l,allowedTables:r,inspections:i,autoFocus:o,onChangeColumn:u,onChangeOperator:d,onChangeValue:m,onRemoveFilter:y,onIsColumnChange:p})=>{const g=b.useMemo(()=>{if(!i)return"";let S=null;for(const E of i)for(const C of E.columns)E.tableName+"."+C.name===n.column&&(S=C);return S!=null&&S.type?S.type:""},[n.column,i]);return h.jsxs("div",{className:"flex gap-2 items-center",children:[h.jsx("label",{className:"w-full",children:h.jsx(Ld,{dataSourceId:l,onChange:S=>u(n.id,S),value:n.column,allowTables:r,focusId:"column",autoFocus:o})}),h.jsx("label",{children:h.jsx(oj,{onChange:S=>d(n.id,S),focusId:"operator",colType:g,value:n.operator})}),b1(eh[n.operator])&&h.jsx("label",{className:"w-full",children:n.isColumnRef?h.jsx(Ld,{dataSourceId:l,onChange:S=>m(n.id,S),value:n.value,allowTables:r,focusId:"value",placeholder:"Search column"}):h.jsx("input",{className:"input w-full",placeholder:"Filter value",value:n.value,onChange:S=>m(n.id,S.currentTarget.value),"data-focus":"value"})}),h.jsxs("div",{className:V1.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:se("p-0.5 cursor-pointer rounded-lg border",n.isColumnRef?"bg-blue-50 border-blue-200":"bg-white border-white"),onClick:()=>p(n.id,!n.isColumnRef),children:"🏷️"}),h.jsx("button",{tabIndex:-1,"data-tooltip-id":"default","data-tooltip-content":"Remove aggregation",className:"p-0.5 text-sm cursor-pointer",onClick:()=>y(n.id),children:h.jsx(Qn,{width:20,height:20,className:"text-red-600"})})]})]})},yj=()=>{const{state:n}=b.useContext(yt),{setFilters:l}=H1(),r=qu(A=>A.filters),{data:i}=es(n.dataSourceId),o=b.useMemo(()=>[n.table,...n.joins.map(A=>A.table)],[n.table,n.joins]),[u,d]=b.useState([]),m=(A,j)=>{d(_=>[..._.map(O=>O.id===A?{...O,column:j}:O)])},y=(A,j)=>{d(_=>[..._.map(O=>O.id===A?{...O,operator:j}:O)])},p=(A,j)=>{d(_=>[..._.map(O=>O.id===A?{...O,value:j}:O)])},g=()=>{d(A=>[...A,{id:Ua(),value:"",column:"",operator:"",isColumnRef:!1}])},S=(A,j)=>{d(_=>[..._.map(O=>O.id===A?{...O,isColumnRef:j}:O)])},E=A=>{d(j=>j.filter(_=>_.id!==A))},C=()=>zu("filters"),w=()=>{dj(u)&&(l(hj(u)),C())};return b.useEffect(()=>{if(!r){d([]);return}d(()=>{const A=n.filters.map(j=>{var _,O;return{id:j.id,value:mj(j),column:j.column,operator:Wd[j.operator],isColumnRef:!!((O=(_=j.value)==null?void 0:_[0])!=null&&O.isColumn)}});return A.push({id:Ua(),value:"",column:"",operator:"",isColumnRef:!1}),A})},[r]),Tn("f",()=>{mu("filters")},"Add new filter"),h.jsxs(Yt,{isVisible:r,onClose:C,portal:!0,children:[h.jsx(On,{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:[u.length<1&&h.jsx("p",{className:"p-1 text-center rounded-lg bg-gray-50 border border-gray-200",children:"No filters"}),u.map((A,j)=>h.jsx(pj,{filter:A,dataSourceId:n.dataSourceId,allowedTables:o,inspections:i||[],onChangeColumn:m,onChangeOperator:y,onChangeValue:p,onRemoveFilter:E,onIsColumnChange:S,autoFocus:j===u.length-1},A.id))]}),h.jsxs("div",{className:V1.actions,children:[h.jsx("button",{className:"button tertiary",onClick:g,children:"Add filter"}),h.jsx("button",{className:"button primary",onClick:w,children:"Apply filters"})]})]})},vj="_card_phvek_2",gj="_cards-list_phvek_2",bj="_join-modal_phvek_2",xj="_close-button_phvek_2",Qo={card:vj,cardsList:gj,joinModal:bj,closeButton:xj},Sj=()=>{const{isFetching:n}=b.useContext(Yn),l=qu(p=>p.joins),{toggle:r,joins:i}=k1(),{availableJoins:o}=b.useContext(oa),[u,d]=b.useState(""),m=b.useMemo(()=>{const p=u.toLowerCase();return o.filter(g=>g.on.toTable.toLowerCase().includes(p))},[o,u]),y=()=>zu("joins");return Tn("j",()=>{o.length>0?qn("joins"):qt.error("No available tables to join")},"Add new join"),h.jsxs(Yt,{isVisible:l,onClose:y,portal:!0,children:[h.jsx(On,{onClick:y}),h.jsxs("div",{className:Qo.joinModal,children:[h.jsx("h2",{className:"text-lg font-semibold mb-4",children:"Join table"}),i.length>0&&h.jsx("div",{className:Qo.cardsList,children:i.map((p,g)=>h.jsxs("div",{className:Qo.card,children:[h.jsxs("p",{className:"text-sm truncate",children:[p.table," on ",p.on]}),g===i.length-1&&h.jsx("button",{className:Qo.closeButton,onClick:()=>r(p),disabled:n,children:h.jsx(Qn,{width:20,height:20})})]},p.table+p.on))}),m.length>0?h.jsx("input",{className:"input w-full",placeholder:"Filter",autoFocus:!0,onChange:p=>d(p.target.value),value:u,disabled:n}):h.jsx(Lt,{variant:"warning",children:h.jsx("p",{className:"text-sm truncate",children:"No more tables to join"})}),h.jsx("div",{className:`flex flex-col mt-2 overflow-y-auto ${n?"opacity-40":""}`,children:m.map(p=>h.jsx(B1,{hook:p,onClick:()=>{n||(r({table:p.on.toTable,type:"LEFT",on:p.where}),d(""))}},p.where))})]})]})};function wj(n){return n.reduce((l,r)=>(l[r]=!0,l),{})}function Ej(n){return n.reduce((l,r)=>(l[r]=!0,l),{})}const Cj="_container_141nc_2",_j="_column-label_141nc_2",jj="_not-active_141nc_2",Wo={container:Cj,columnLabel:_j,notActive:jj};function Nj(n){if(!n)return[];const l={};return n.forEach(r=>{l[r.table]?l[r.table].push({value:r.full,ogColumn:r.column,label:hl(r.column),type:r.type}):l[r.table]=[{value:r.full,ogColumn:r.column,label:hl(r.column),type:r.type}],f4[r.type]&&["YEAR","MONTH","DAY"].forEach(i=>{l[r.table].push({value:i+" "+r.full,ogColumn:r.column,label:i+" "+hl(r.column),type:"number",nested:!0})})}),Object.entries(l).reduce((r,[i,o])=>(r.push({name:hl(i),columns:o}),r),[])}function Aj(n,l){const r=l.toLowerCase();return n.map(i=>{const o=i.columns.filter(u=>u.label.toLowerCase().includes(r)||u.ogColumn.toLowerCase().includes(r));return{...i,columns:o}}).filter(i=>i.columns.length>0)}const Tj=({column:n,selected:l,onCheck:r})=>h.jsxs("label",{className:se(Wo.columnLabel,l?Wo.active:Wo.notActive,n.nested&&"pl-5!"),children:[h.jsx("input",{type:"checkbox",checked:l[n.value],name:n.value,onChange:r}),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),Rj={columns:"c",groupBy:"g"},uv=({mode:n})=>{const l=qu(_=>_[n]),{allColumns:r}=b.useContext(oa),{state:i,setState:o}=b.useContext(yt),[u,d]=b.useState({}),[m,y]=b.useState(""),p=b.useMemo(()=>Nj(r),[r]),g=i.aggregations.length>0||i.groupBy.length>0,S=b.useMemo(()=>m?Aj(p,m):p,[m,p]),E=_=>{d(O=>({...O,[_.target.name]:_.target.checked}))},C=_=>{const O=_.target.checked;d(D=>{for(const Y of r)D[Y.full]=O;return{...D}})},w=()=>{zu(n)},A=()=>{const _=[];for(const[O,D]of Object.entries(u))if(D){const[Y,H]=O.split(" ");_.push({value:H||Y,fn:H?Y:void 0})}o(O=>({...O,[n]:_})),w()},j=b.useMemo(()=>{for(const _ of r)if(!u[_.full])return!1;return!0},[u,r]);return Tn(Rj[n],()=>{n==="columns"?g?qt.error("Columns are ignored when there is at least one aggregation or group by"):mu("columns"):mu("groupBy")},"Manage "+n),b.useEffect(()=>{if(!l){d({});return}d(()=>wj(i[n].map(_=>_.fn?_.fn+" "+_.value:_.value)))},[l,d]),h.jsxs(Yt,{isVisible:l,onClose:w,portal:!0,children:[h.jsx(On,{onClick:w}),h.jsxs("div",{className:Wo.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:_=>y(_.target.value)}),h.jsx("div",{className:"overflow-y-auto",children:S.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(Tj,{column:O,selected:u,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:j,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:A,children:"Apply"})]})]})]})},Oj="_options-container_14i8j_2",Dj={optionsContainer:Oj},cd="COUNT all",Mj=n=>n.distinct?[n.fn,"DISTINCT",n.value].join(" "):[n.fn,n.value].join(" "),Uj=()=>{const n=qu(w=>w.aggregate),{dataSourceId:l}=b.useContext(oa),{setState:r,state:i}=b.useContext(yt),{data:o}=b.useContext(Yn),[u,d]=b.useState({fn:"",col:""}),m=w=>d({...u,fn:w.currentTarget.value}),y=w=>d({...u,col:w}),p=()=>zu("aggregate"),g=()=>{const w=u.fn===cd?{value:"*",fn:"COUNT"}:{fn:u.fn,value:u.col,distinct:u.fn==="COUNT"};r(A=>({...A,aggregations:[...A.aggregations,w]}))},S=u.fn===cd,E=S?!1:!u.col||!u.fn,C=w=>{const A=ta(w);r(j=>({...j,aggregations:j.aggregations.filter(_=>_.fn!==w.fn||_.value!==w.value),orderBy:j.orderBy.filter(_=>_.column!==A)}))};return Tn("a",()=>{mu("aggregate")},"Aggregate data"),h.jsxs(Yt,{isVisible:n,onClose:p,backdropClose:!0,portal:!0,children:[h.jsx(On,{onClick:p}),h.jsxs("div",{children:[h.jsx("h2",{className:"text-lg font-semibold",children:"Aggregate"}),pl(i.aggregations.length,0)&&h.jsx("div",{className:"flex flex-col gap-1 mt-4",children:i.aggregations.map((w,A)=>h.jsxs("p",{className:"p-2 rounded-md bg-gray-50 flex items-center justify-between",children:[h.jsx("span",{children:Mj(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(Qn,{width:20,height:20,className:"text-red-600"})})]},A))}),h.jsxs("div",{className:Dj.optionsContainer,children:[h.jsxs("label",{className:se(S&&"col-span-2"),children:[h.jsx("p",{className:"font-semibold text-xs",children:"Function"}),h.jsxs("select",{className:"input w-full",value:u.fn,onChange:m,autoFocus:!0,children:[h.jsx("option",{value:"",disabled:!0,children:"Select function"}),h.jsx("option",{value:cd,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"})]})]}),!S&&h.jsxs("label",{children:[h.jsx("p",{className:"font-semibold text-xs",children:"Column"}),h.jsx(Ld,{dataSourceId:l,allowTables:(o==null?void 0:o.tables)||[],onChange:y,value:u.col})]}),h.jsx("button",{className:"button primary",disabled:E,onClick:g,children:"Add"})]})]})]})},K1=({options:n,updater:l,name:r,tabId:i})=>{const o=m4(n,l),{state:u}=o,d=lE({datasourceId:n.dataSourceId,name:r,opts:{table:n.table,filters:u.filters,joins:u.joins,orderBy:u.orderBy,columns:u.columns,aggregations:u.aggregations,groupBy:u.groupBy,searchAll:u.searchAll},page:u.page,size:u.size}),m=h4(d.data,n.dataSourceId,r,i);return h.jsx(oa,{value:m,children:h.jsx(yt,{value:o,children:h.jsxs(Yn,{value:d,children:[h.jsx(P_,{}),h.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[h.jsxs("div",{className:"m-1 flex-1 overflow-auto pb-12 no-scrollbar",children:[h.jsx("div",{className:"pb-0.5 sticky bottom-0"}),h.jsx(h_,{})]}),h.jsx(yj,{}),h.jsx(Sj,{}),h.jsx(uv,{mode:"columns"}),h.jsx(uv,{mode:"groupBy"}),h.jsx(Uj,{}),h.jsx(K_,{})]})]})})})},Lj=({tab:n})=>{const l=b.useCallback(r=>{Tu(i=>i.map(o=>o.id!==n.id?o:{...o,options:r(o.options)}))},[n]);return h.jsx(K1,{updater:l,options:n.options,name:n.label,tabId:n.id})},qj=({content:n,activeAnchor:l})=>{if(!l)return null;const r=l.getAttribute("data-tab-id"),i=Ru.get().find(d=>d.id===r),o=DC(i==null?void 0:i.options.dataSourceId);if(!i)return n;const u=()=>{Pl("New tab name",i.label).then(d=>{d&&Ou(i.id,d)})};return h.jsxs("div",{children:[h.jsxs("button",{className:ea.tooltipLabel,onClick:u,children:[h.jsxs("div",{className:"overflow-hidden",children:[h.jsx("p",{className:"text-xs",children:"label"}),h.jsx("p",{className:"truncate font-semibold",children:i.label})]}),h.jsx("span",{children:"✏️"})]}),h.jsxs("div",{className:ea.tooltipInfoEntry,children:[h.jsx("p",{className:"text-sm",children:"table"}),h.jsx("p",{className:"truncate font-semibold",children:i.options.table})]}),o&&h.jsxs("div",{className:ea.tooltipInfoEntry,children:[h.jsxs("p",{className:"text-sm",children:["data source [",o.dbType,"]"]}),h.jsx("p",{className:"truncate font-semibold",children:o.name})]}),i.options.joins.length>0&&h.jsxs("div",{className:ea.tooltipInfoEntry,children:[h.jsx("p",{className:"text-sm",children:"joins"}),h.jsx("p",{className:"truncate font-semibold",children:i.options.joins.map(d=>d.table).join(", ")})]}),i.options.filters.length>0&&h.jsxs("div",{className:ea.tooltipInfoEntry,children:[h.jsx("p",{className:"text-sm",children:"filters"}),i.options.filters.map(d=>h.jsx("p",{className:"truncate font-semibold",children:I4(d)}))]})]})},zj=()=>{const n=y4(),l=Au(),r=mh(Lu.laptop),i=b.useMemo(()=>{if(!l)return;const m=l.find(y=>y.id===n);return m||l[0]},[n,l]),o=m=>{m.stopPropagation(),m.preventDefault();const y=m.currentTarget.getAttribute("data-tab-id");y&&qy(y)},u=m=>{m.button===1&&qy(m.currentTarget.dataset.tabId)},d=m=>{const y=l.find(p=>p.id===m);Pl("New tab name",y==null?void 0:y.label).then(p=>{p&&Ou(m,p)})};return l.length<1?h.jsx(t2,{to:"/"}):h.jsxs("div",{className:"h-screen max-h-screen bg-(--bg) flex flex-col",children:[r&&h.jsx(hh,{id:"tab",render:qj,className:"z-10 shadow-md p-0!",offset:-1,noArrow:!0,opacity:1,variant:"light",clickable:!0,delayShow:500}),i&&h.jsx(Lj,{tab:i}),h.jsx("div",{className:se(ea.tabs,"no-scrollbar",!r&&ea.mobile),children:l==null?void 0:l.map(m=>h.jsxs("div",{onClick:()=>nh(m.id),className:se(ea.tab,m.id===(i==null?void 0:i.id)&&ea.active),"data-tab-id":m.id,"data-tooltip-id":"tab","data-tooltip-content":m.label,onAuxClick:u,onContextMenu:y=>{y.preventDefault(),d(m.id)},children:[h.jsxs("span",{className:"truncate w-full",children:["📄 ",m.label]}),h.jsx("button",{"data-tab-id":m.id,className:ea.closeButton,onClick:o,children:h.jsx(Qn,{width:20,height:20})})]},m.id))})]})},Bj=()=>{const n=J_(),l=b.useCallback(r=>{Y1(i=>i?{...i,options:r(i.options)}:(qt.error("Something went wrong."),i))},[]);return n?h.jsxs(Yt,{isVisible:!0,onClose:Ud,children:[h.jsx(On,{onClick:Ud}),h.jsx("div",{className:"border border-gray-200 bg-(--bg) flex flex-col",children:h.jsx(K1,{name:n.label,options:n.options,updater:l})})]}):null},Hj="_root_cmyhu_2",kj="_down_cmyhu_2",Qj="_chevron_cmyhu_2",Yj="_table-name-container_cmyhu_2",Vj="_link_cmyhu_2",Kj="_table-name_cmyhu_2",Gj="_ul_cmyhu_2",Fj="_column-type_cmyhu_2",Ra={root:Hj,down:kj,chevron:Qj,tableNameContainer:Yj,link:Vj,tableName:Kj,ul:Gj,columnType:Fj},[i6,$j]=It(!1),G1=()=>$j(!1),Xj=new Intl.DateTimeFormat("en",{dateStyle:"full",timeStyle:"long"});function Zj(n,l){if(l&&n.toLowerCase().includes(l))return"bg-yellow-200"}const Jj=({insp:n,filter:l,expanded:r})=>{const i=b.useMemo(()=>r?n.columns:l.length<1?[]:n.columns.filter(o=>o.name.toLowerCase().includes(l)),[n,l,r]);return h.jsx("ul",{className:Ra.ul,children:i.map(o=>h.jsx(h.Fragment,{children:h.jsxs("li",{children:[o.isPrimary?"🔐":"🏷️"," ",h.jsx("span",{className:Zj(o.name,l),children:o.name})," ",h.jsxs("span",{className:Ra.columnType,children:["[",o.type,"]"]}),o.ref&&h.jsxs("span",{children:[" ➡️ ",h.jsx("span",{className:Ra.columnType,children:o.ref.table}),".",o.ref.field]})]},o.name+o.type)}))},n.id)};function Pj({id:n}){const{data:l}=Nu(n),{data:r}=es(n),i=Pt(),{pathname:o}=jt(),u=F3(),d=y1(),m=$3(),y=b.useMemo(()=>l!=null&&l.lastInspected?Xj.format(new Date(l.lastInspected)):"--",[l]),[p,g]=b.useState({}),[S,E]=b.useState(""),[C,w]=b.useState("table"),A=Sr(Xt.EDITOR),j=S.toLowerCase(),_=b.useMemo(()=>{if(!j||!r)return r||[];const W=[];for(const re of r){if(re.tableName.toLowerCase().includes(j)){W.push(re);continue}C!=="table"&&re.columns.findIndex(pe=>pe.name.toLowerCase().includes(j))>=0&&W.push(re)}return W},[j,r,C]),O=W=>{g(re=>({...re,[W]:!re[W]}))},D=W=>{yl(W,{table:W,dataSourceId:n},!0),Yi(void 0),G1(),o!==Ue.workbench.path&&i(Ue.workbench.path)},Y=()=>{d.mutate(n)},H=async()=>{const W=await Pl("Enter name",l==null?void 0:l.name);W&&u.mutate({id:n,dataSource:{name:W}})},$=async()=>{await w1("Are you sure you want to delete this data source?")&&(m.mutate(n),Yi(void 0))},I=C==="column";return h.jsxs("div",{className:Ra.root,children:[h.jsxs("h3",{className:"page-head flex gap-2",children:[l&&h.jsx(ah,{size:32,type:l.dbType}),h.jsx("span",{className:"truncate",children:l==null?void 0:l.name})]}),h.jsx("p",{className:"mt-1 text-sm font-semibold",children:y}),A&&h.jsxs("div",{className:"mt-2 flex gap-2",children:[h.jsx("button",{disabled:d.isLoading,onClick:Y,className:"button tertiary flex items-center gap-1",children:"Refresh schema"}),h.jsx("button",{disabled:d.isLoading,onClick:H,className:"button tertiary",children:"Rename"}),h.jsx("button",{disabled:d.isLoading,onClick:$,className:"button tertiary",children:"Delete"})]}),h.jsxs("div",{className:"flex gap-1 items-center mb-2 mt-4",children:[h.jsx("input",{className:"input flex-1 bg-gray-50",placeholder:I?"Search column":"Search table",value:S,onChange:W=>E(W.target.value),autoFocus:!0}),h.jsx("button",{className:"button primary w-20",onClick:()=>w(I?"table":"column"),children:I?"Column":"Table"})]}),h.jsx("div",{className:"overflow-y-auto",children:_==null?void 0:_.map(W=>h.jsxs("div",{children:[h.jsxs("div",{className:Ra.tableNameContainer,children:[h.jsx("button",{className:se(Ra.chevron,p[W.id]&&Ra.down),onClick:()=>O(W.id),children:h.jsx(ph,{width:16,height:16})}),h.jsx("button",{className:se(Ra.tableName,"flex-1"),onClick:()=>O(W.id),children:W.tableName}),h.jsx("button",{className:Ra.link,onClick:()=>D(W.tableName),children:"↗️"})]}),(p[W.id]||S.length>0)&&h.jsx(Jj,{insp:W,filter:I?j:"",expanded:p[W.id]})]},W.id))})]})}const Ij=()=>{const n=V4(),[l,r]=b.useState(void 0);b.useEffect(()=>{n&&r(n)},[n]);const i=()=>Yi(void 0);return h.jsxs(Yt,{isVisible:n!=null,onClose:i,onClosed:()=>r(void 0),backdropClose:!0,children:[h.jsx(On,{onClick:i}),l&&h.jsx(Pj,{id:l})]})};function Wj(n,l=500){const[r,i]=b.useState(n);return b.useEffect(()=>{const o=setTimeout(()=>i(n),l);return()=>clearTimeout(o)},[n,l]),r}const eN="_search_17rcq_2",tN="_entry_17rcq_2",nN="_ds_17rcq_2",aN="_ds-entry_17rcq_2",Yo={search:eN,entry:tN,ds:nN,dsEntry:aN},[lN,iN]=th({initialData:[],localStorageKey:"selected-data-sources-v1"}),sN=n=>iN(l=>{const r=l.indexOf(n);return r>-1?(l.splice(r,1),[...l]):[...l,n]}),rN={table:"📄",query:"📖"},oN=({onTable:n,onQuery:l,autoFocus:r})=>{const[i,o]=b.useState(""),[u,d]=b.useState(-1),m=Wj(i,200),y=lN(),{data:p}=sa(),{data:g}=Pd({teamId:p==null?void 0:p.teamId}),{data:S}=Q3(m,{teamId:p==null?void 0:p.teamId,selectedDataSources:y}),E=j=>{j.type==="table"?n(j.name,j.dataSourceId):j.type==="query"&&l(j.id,j.dataSourceId)},C=j=>{var _;S&&(j.key==="ArrowDown"?(j.preventDefault(),d(O=>(O+1)%S.length)):j.key==="ArrowUp"?(j.preventDefault(),d(O=>(O-1+S.length)%S.length)):j.key==="Enter"&&u>=0&&(_=S[u])!=null&&_.name&&(j.preventDefault(),E(S[u])))},w=j=>{const _=j.currentTarget.dataset.tableId,O=S==null?void 0:S.find(D=>D.id===_);O&&E(O)},A=b.useMemo(()=>Ej(y),[y]);return h.jsxs("div",{className:"overflow-hidden flex flex-col w-full lg:w-lg",children:[pl(g==null?void 0:g.length,0)&&h.jsx("div",{className:"flex overflow-x-auto mb-2 gap-2 no-scrollbar",children:g.map(j=>h.jsxs("label",{className:Yo.dsEntry,children:[h.jsx("input",{type:"checkbox",checked:A[j.id]===!0,onChange:()=>sN(j.id)}),h.jsx("span",{children:j.name})]},j.id))}),h.jsx("input",{className:Yo.search,placeholder:"Search table or saved query to start from",value:i,onChange:j=>o(j.target.value),onKeyDown:C,autoFocus:r}),pl(S==null?void 0:S.length,0)&&h.jsx("div",{className:"overflow-y-auto max-h-full mt-2",children:S.map((j,_)=>h.jsxs("button",{className:Yo.entry,"data-is-active":u===_,"data-table-id":j.id,onClick:w,children:[h.jsxs("p",{className:"font-semibold",children:[rN[j.type]," ",j.name]}),h.jsxs("p",{className:Yo.ds,children:["📦 ",j.dataSourceName]})]},j.id))})]})},uN=()=>{const n=S4(),l=(o,u)=>{n==null||n.onConfirm("table",o,u)},r=(o,u)=>{n==null||n.onConfirm("query",o,u)},i=()=>{n==null||n.onCancel()};return h.jsxs(Yt,{isVisible:!!n,onClose:i,children:[h.jsx(On,{onClick:i}),h.jsx(oN,{autoFocus:!0,onTable:l,onQuery:r})]})},cN=()=>{const n=jt();b.useEffect(()=>{},[n.pathname])},[fN,F1]=It(!1),fd=()=>F1(!1),$1=()=>F1(!0),dN=({repeatPassword:n,password:l})=>l.length<1?null:l.length<8?h.jsx(Lt,{variant:"warning",children:"New password should be at least 8 characters long"}):l!==n?h.jsx(Lt,{variant:"warning",children:"Repeat password should match new password"}):null,hN=()=>{const n=fN(),{data:l}=sa(),{mutateAsync:r,isLoading:i}=X3(),o=Pt(),[{password:u,repeatPassword:d},{change:m,touched:y,reset:p}]=wr({password:"",repeatPassword:""}),g=()=>{o("/"),br.logout().then(()=>{fd()})},S=()=>{r({password:u}).then(()=>{p(),qt.success("Password successfully updated!")})},E=u.length<8||u!==d||i,C=y.includes("password");return h.jsxs(Yt,{isVisible:n,onClose:fd,children:[h.jsx(On,{onClick:fd}),h.jsxs("div",{className:"w-full lg:w-lg flex flex-col gap-2",children:[h.jsx(S1,{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==null?void 0: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:u,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(dN,{password:u,repeatPassword:d}),h.jsxs("div",{className:"flex justify-end gap-2 mt-2",children:[h.jsx("button",{className:"button tertiary",disabled:E,onClick:S,children:"Update password"}),h.jsx("button",{className:"button danger",onClick:g,children:"Log out"})]})]})]})},[mN,X1]=It(!1),Z1=()=>X1(!0),cv=()=>X1(!1),pN=n=>fn({queryKey:["team-users"],queryFn:async()=>{const{data:l}=await Ve.get("/teams/"+n+"/users");return l.data},enabled:!!n}),yN=()=>cn({mutationFn:async({role:n,teamId:l,userId:r})=>(await Ve.patch("/teams/"+l+"/user-role",{role:n,userId:r}),!0),onSuccess:()=>{pt.invalidateQueries({queryKey:["team-users"]})}}),vN=()=>cn({mutationFn:async({teamId:n,userId:l})=>(await Ve.delete("/teams/"+n,{params:{userId:l}}),!0),onSuccess:()=>{pt.invalidateQueries({queryKey:["team-users"]})}}),gN="_user-entry_1v0j4_2",bN={userEntry:gN},xN=()=>{const n=mN(),{data:l}=sa(),{data:r}=pN(l==null?void 0:l.teamId),{mutate:i,isLoading:o}=Z3(),{mutate:u,isLoading:d}=yN(),{mutate:m,isLoading:y}=vN(),[p,{change:g,reset:S}]=wr({password:"",username:""}),E=()=>{i({username:p.username,password:p.password,teamId:(l==null?void 0:l.teamId)||""}),S()},C=(_,O)=>{u({teamId:l.teamId,role:O,userId:_})},w=_=>{w1("Are you sure you want to remove this user?").then(O=>{O&&m({userId:_,teamId:l.teamId})})},A=Sr(Xt.ADMIN),j=o||d||y;return h.jsxs(Yt,{isVisible:n,onClose:cv,backdropClose:!0,children:[h.jsx(On,{onClick:cv}),h.jsxs("div",{className:"w-full lg:w-lg flex flex-col overflow-hidden",children:[h.jsx(S1,{children:"Manage users"}),pl(r==null?void 0:r.length,0)&&h.jsx("div",{className:"mt-4 overflow-y-auto flex-1",children:r.map(_=>h.jsxs("div",{className:bN.userEntry,children:[h.jsxs("select",{className:"input",value:_.role,disabled:!A||j,onChange:O=>C(_.id,O.currentTarget.value),children:[h.jsx("option",{value:Xt.OWNER,children:"Owner"}),h.jsx("option",{value:Xt.ADMIN,children:"Admin"}),h.jsx("option",{value:Xt.EDITOR,children:"Editor"}),h.jsx("option",{value:Xt.READ_ONLY,children:"Reader"})]}),h.jsx("p",{className:"flex-1 mx-2",children:_.name}),A&&h.jsx("button",{className:"p-1 cursor-pointer text-red-500 text-sm",onClick:()=>w(_.id),children:"❌"})]},_.id))}),A&&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:g("username"),value:p.username,placeholder:"Username",disabled:j}),h.jsx("input",{className:"input",onChange:g("password"),value:p.password,type:"password",name:"newPassword",autoComplete:"new-password",placeholder:"Password",disabled:j}),h.jsx("button",{className:"button primary",onClick:E,disabled:j,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."})]})]})]})},SN=()=>{const[n,l]=b.useState(""),[r,i]=b.useState(""),[o,u]=b.useState(),[d,m]=b.useState(!1),y=Pt(),p=g=>{g.preventDefault(),u(void 0),br.login({password:r,username:n}).then(()=>{y("/",{replace:!0})}).catch(u)};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:p,children:[h.jsx("p",{className:"font-semibold text-xl min-w-md",children:"Login"}),o&&h.jsx(Lt,{variant:"danger",children:"Failed to login. Please verify your credentials"}),h.jsx("input",{value:n,onChange:g=>l(g.currentTarget.value),className:"input",placeholder:"User name"}),h.jsx("input",{value:r,onChange:g=>i(g.currentTarget.value),className:"input",type:"password",placeholder:"Password"}),h.jsx("button",{type:"submit",className:"button primary",children:"Login"}),d?h.jsxs(Lt,{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?"})]})})})},wN=()=>{const n=Pt(),{pathname:l}=jt(),{data:r,isLoading:i}=v1();b.useEffect(()=>{!r&&!i&&l!==Ue.login.path&&n(Ue.login.path)},[r,i,n,l])},EN=()=>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..."})]}),CN=()=>{const[n]=M2(),l=Pt(),{data:r,isLoading:i,isError:o}=F_(n.get("shareId"));return b.useEffect(()=>{var u;r&&(yl(r.name,{...r.opts,dataSourceId:(u=r.dataSource)==null?void 0:u.id},!0),l(Ue.workbench.path,{replace:!0}))},[r]),h.jsxs("div",{className:"page-container flex items-center justify-center h-screen",children:[i&&h.jsxs("div",{className:"flex items-center flex-col gap-2",children:[h.jsx(EN,{}),h.jsx("p",{children:"Fetching query information"})]}),o&&h.jsx(Lt,{variant:"danger",children:"Failed to load query information"})]})};function _N(){return L_(),cN(),wN(),h.jsxs(h.Fragment,{children:[h.jsxs(a2,{children:[h.jsx(sr,{path:Ue.home.path,element:h.jsx(Z4,{})}),h.jsx(sr,{path:Ue.workbench.path,element:h.jsx(zj,{})}),h.jsx(sr,{path:Ue.login.path,element:h.jsx(SN,{})}),h.jsx(sr,{path:Ue.share.path,element:h.jsx(CN,{})})]}),h.jsx(Bj,{}),h.jsx(uE,{}),h.jsx(bE,{}),h.jsx(DE,{}),h.jsx(Ij,{}),h.jsx(uN,{}),h.jsx(hN,{}),h.jsx(xN,{}),h.jsx(NE,{}),h.jsx(wE,{})]})}const jN="_desktop-layout_iepur_2",NN="_mobile-layout_iepur_2",AN="_nav_iepur_2",TN="_main_iepur_2",RN="_header_iepur_2",Gi={desktopLayout:jN,mobileLayout:NN,nav:AN,main:TN,header:RN},ON="_container_10op7_2",DN="_menu_10op7_2",pu={container:ON,menu:DN},MN=({name:n,id:l,onRename:r,onDelete:i,onOpen:o})=>{const u=q1();return h.jsxs("button",{className:pu.menu,onContextMenu:u.open,onClick:()=>o(l),children:[h.jsx(z1,{handler:u,children:h.jsxs("div",{className:"context-menu-container",children:[h.jsx("button",{onClick:d=>{d.preventDefault(),d.stopPropagation(),u.close(),r(l)},className:"context-menu-item",children:"✏️ Rename"}),h.jsx("button",{onClick:d=>{d.preventDefault(),d.stopPropagation(),u.close(),i(l)},className:"context-menu-item",children:"🗑️ Delete"})]})}),h.jsxs("span",{children:["📖 ",n]})]})},UN=({dataSource:n,index:l})=>{const r=()=>{Yi(n.id)};return Tn(l.toString(),()=>{Yi(i=>{if(i!==n.id)return n.id})},n.name),h.jsxs("button",{className:pu.menu,onClick:r,children:[h.jsx(ah,{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})]})},LN=()=>{const n=Pt(),l=jt(),{data:r}=sa(),{data:i}=B3(r==null?void 0:r.teamId),{data:o}=H3(r==null?void 0:r.teamId),u=Au(),d=Z_(),m=X_(),y=E=>{x1(E).then(C=>{var w;yl(C.name,fr({...C.opts,dataSourceId:(w=C.dataSource)==null?void 0:w.id}),!0),l.pathname!==Ue.workbench.path&&n(Ue.workbench.path)})},p=async E=>{const C=o==null?void 0:o.find(A=>A.id===E),w=await Pl("New name?",C==null?void 0:C.name);w&&d.mutate({id:E,payload:{name:w}})},g=E=>{var w;const C=(w=o==null?void 0:o.find(A=>A.id===E))==null?void 0:w.savedQueryId;C&&m.mutate(C)},S=E=>{nh(E),l.pathname!==Ue.workbench.path&&n(Ue.workbench.path)};return h.jsx("div",{className:pu.container,children:h.jsxs("div",{className:"flex-1 overflow-y-auto",children:[pl(i==null?void 0: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((E,C)=>h.jsx(UN,{dataSource:E,index:C+1},E.id))]}),pl(o==null?void 0:o.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"}),o.map(E=>h.jsx(MN,{onDelete:g,onRename:p,onOpen:y,name:E.name,id:E.id},E.savedQueryId))]}),pl(u==null?void 0:u.length,0)&&h.jsxs("div",{className:"mt-4",children:[h.jsx("p",{className:"font-semibold text-sm text-gray-600 mb-2",children:"WORKBENCH TABS"}),u==null?void 0:u.map(E=>h.jsxs("button",{className:pu.menu,onClick:()=>S(E.id),children:["📄 ",E.label]},E.id))]})]})})},qN=()=>{const n=Pt(),{pathname:l}=jt(),{data:r}=sa(),i=()=>{G1(),l!==Ue.home.path&&n(Ue.home.path)};return h.jsxs("nav",{className:Gi.nav,children:[r&&h.jsxs("div",{className:Gi.header,children:[h.jsx("button",{onClick:i,children:"🏠 Home"}),h.jsxs("button",{onClick:$1,children:["🪪 ",r.username]}),h.jsx("button",{onClick:Z1,children:"👥 Manage users"})]}),h.jsx(LN,{})]})},zN="_root_18apu_2",BN={root:zN},HN=()=>{const{pathname:n}=jt(),l=Pt(),r=xr("Mobile home workbench"),i=Au(),o=()=>{n!==Ue.home.path&&l(Ue.home.path)},u=()=>{i.length<1?r():n!==Ue.workbench.path&&l(Ue.workbench.path)};return h.jsxs("div",{className:BN.root,children:[h.jsxs("button",{onClick:o,children:[h.jsx("p",{children:"🏠"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Home"})]}),h.jsxs("button",{onClick:u,children:[h.jsx("p",{children:"🛠️"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Workbench"})]}),h.jsxs("button",{onClick:$1,children:[h.jsx("p",{children:"🪪"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Account"})]}),h.jsxs("button",{onClick:Z1,children:[h.jsx("p",{children:"👥"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Users"})]})]})},kN=({children:n,isLogin:l})=>h.jsxs("div",{className:Gi.desktopLayout,children:[h.jsx(hh,{id:"default",className:"z-100"}),!l&&h.jsx(qN,{}),h.jsx("main",{className:Gi.main,children:n})]}),QN=({children:n,isLogin:l})=>h.jsxs("div",{className:Gi.mobileLayout,children:[h.jsx("main",{className:Gi.main,children:n}),!l&&h.jsx(HN,{})]}),YN=({children:n})=>{const l=mh(Lu.laptop),{pathname:r}=jt(),i=r===Ue.login.path;return l?h.jsx(kN,{isLogin:i,children:n}):h.jsx(QN,{isLogin:i,children:n})};fx.createRoot(document.getElementById("root")).render(h.jsxs(Ge.StrictMode,{children:[h.jsx(L3,{}),h.jsx(uS,{client:pt,children:h.jsx(A2,{children:h.jsx(YN,{children:h.jsx(_N,{})})})})]}));
|
|
237
|
+
.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 DC=n=>{if(!n)return;const l=pt.getQueryData([Jd]);if(!l)return;const r=pt.getQueryData([La,l.teamId]);return r==null?void 0:r.find(i=>i.id===n)},Iy=n=>window.matchMedia(n).matches;function mh(n,{defaultValue:l=!1,initializeWithValue:r=!0}={}){const[i,o]=b.useState(()=>r?Iy(n):l);return b.useLayoutEffect(()=>{const u=window.matchMedia(n);function d(){o(()=>Iy(n))}return d(),u.addListener?u.addListener(d):u.addEventListener("change",d),()=>{u.removeListener?u.removeListener(d):u.removeEventListener("change",d)}},[n]),i}const Lu={laptop:"(min-width: 1024px)"},MC=()=>window.matchMedia(Lu.laptop).matches,UC="_table_inecl_2",LC="_semi-transparent_inecl_2",qC="_table-loading_inecl_2",zC="_table-empty_inecl_2",BC="_table-row-cells_inecl_2",HC="_header-cell_inecl_2",kC="_header-actions_inecl_2",QC="_cell_inecl_2",YC="_cell-actions_inecl_2",VC="_table-config_inecl_2",KC="_table-action_inecl_2",GC="_blue_inecl_2",FC="_red_inecl_2",$C="_modal_inecl_2",XC="_options-container_inecl_2",ZC="_underlying-rows-btn_inecl_2",JC="_option-item_inecl_2",ne={table:UC,semiTransparent:LC,tableLoading:qC,tableEmpty:zC,tableRowCells:BC,headerCell:HC,headerActions:kC,cell:QC,cellActions:YC,tableConfig:VC,tableAction:KC,blue:GC,red:FC,modal:$C,optionsContainer:XC,underlyingRowsBtn:ZC,optionItem:JC},oa=b.createContext({name:"No name",hooks:[],availableJoins:[],allColumns:[],dataSourceId:"",entities:[],getValue:()=>{},getColumnType:()=>{},getEntityKey:()=>[]}),yt=b.createContext({state:fr({}),setState:()=>{}}),Yn=b.createContext({}),q1=()=>{const[n,l]=b.useState();return b.useMemo(()=>({show:!!n,position:n,open:i=>{i.preventDefault(),l({x:i.clientX-1,y:i.clientY-1})},close:()=>{l(void 0)}}),[n])},PC=n=>{if(n==="ASC")return"DESC";if(n!=="DESC")return"ASC"},IC=()=>{const{state:n,setState:l}=b.useContext(yt),r=b.useCallback(i=>{l(o=>{const u=o.orderBy[0];if(u&&u.column===i){const d=PC(u.direction);return d?{...o,orderBy:[{column:i,direction:d}]}:{...o,orderBy:[]}}return{...o,orderBy:[{column:i,direction:"ASC"}]}})},[l]);return{orderBy:n.orderBy,updateOrderBy:r}};function WC(n){var r;const l=(r=n.target)==null?void 0:r.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 od(n,l,r){var u,d,m;const i=(d=(u=n==null?void 0:n.rows)==null?void 0:u[l])==null?void 0:d[r],o=(m=n==null?void 0:n.columns)==null?void 0:m[r];return{value:i,column:o}}const e_=()=>{const{data:n}=b.useContext(Yn),{getColumnType:l}=b.useContext(oa),{setState:r}=b.useContext(yt),i=m=>{const{value:y,column:p}=od(n,m.row,m.col);if(p){const g=Gl(y,l(p.full));navigator.clipboard.writeText(g),qt.success("Copied!")}},o=m=>{const{value:y,column:p}=od(n,m.row,m.col);if(p){const g=Gl(y,l(p.full));E1(g)}},u=m=>{const{value:y,column:p}=od(n,m.row,m.col);let g=(p==null?void 0:p.full)||"",S;if((p==null?void 0:p.table)===""){qt.error("Filtering on aggregated column is not supported yet");return}if(g){let E;if(y==null)E={id:Ua(),isEnabled:!0,column:g,connector:"AND",operator:"IS NULL"};else{const C=Gl(y,l(g));E={id:Ua(),isEnabled:!0,column:g,connector:"AND",operator:"=",fn:S,value:[{value:C}]}}r(C=>({...C,filters:[...C.filters,E]})),qt.success(`Added new filter on column ${p==null?void 0:p.alias}`)}};return m=>{const y=WC(m);y&&(y.action==="copy"?i(y):y.action==="show"?o(y):y.action==="filter"&&u(y))}},t_="_container_hnjf3_2",n_="_content_hnjf3_2",a_="_backdrop_hnjf3_2",ud={container:t_,content:n_,backdrop:a_},z1=({children:n,handler:l})=>{const r=b.useRef(l.close);r.current=l.close;const i=b.useMemo(()=>{if(!l.position)return;const o={};if(typeof window<"u"){const u=l.position.y>window.innerHeight/2,d=l.position.x>window.innerWidth/2;u?o.bottom=window.innerHeight-l.position.y:o.top=l.position.y,MC()?d?o.right=window.innerWidth-l.position.x:o.left=l.position.x:(o.right=36,o.left=36)}return o},[l]);return b.useEffect(()=>{const o=u=>{u.code==="Escape"&&r.current()};return window.addEventListener("keyup",o),()=>{window.removeEventListener("keyup",o)}},[]),i?h.jsxs("div",{className:ud.container,children:[h.jsx("div",{className:ud.backdrop,onClick:o=>{o.stopPropagation(),o.preventDefault(),l.close()}}),h.jsx("div",{className:ud.content,style:i,children:n})]}):null},l_="_table_12hui_2",i_="_root_12hui_2",s_="_content_12hui_2",r_="_sub_12hui_2",ko={table:l_,root:i_,content:s_,sub:r_},B1=({hook:n,onClick:l})=>h.jsxs("button",{className:ko.root,onClick:l,title:n.where,children:[h.jsx("span",{children:"📄"}),h.jsxs("div",{className:ko.content,children:[h.jsxs("p",{className:ko.table,children:[" ",n.on.toTable]}),h.jsxs("span",{className:ko.sub,children:[n.on.toColumn," = ",n.on.fromTable,".",n.on.fromColumn]})]})]},n.where),pl=(n,l)=>n!=null&&n>l,o_=({handler:n,rowIndex:l})=>{const{hooks:r,entities:i,dataSourceId:o,getEntityKey:u,getValue:d}=b.useContext(oa),{state:m}=b.useContext(yt),{data:y}=b.useContext(Yn),[p,g]=b.useState(""),[S,E]=b.useState(""),C=b.useMemo(()=>y==null?void 0:y.rows[l],[y,l]),w=()=>{C&&(yl("⬇️ "+m.table,{joins:m.joins,table:m.table,dataSourceId:m.dataSourceId,filters:[...m.filters,...m.groupBy.map(Y=>({id:Ua(),connector:"AND",column:Y.value,operator:"=",value:[{value:d(C,Y)}]}))]},!0),n.close())},A=Y=>{if(!C)return;const H=d(C,{value:`${Y.on.fromTable}.${Y.on.fromColumn}`});yl(`↗️ ${Y.on.toColumn} equals ${H}`,{table:Y.on.toTable,dataSourceId:o,filters:[{id:Ua(),column:Y.on.toTable+"."+Y.on.toColumn,operator:H==null?"IS NULL":"=",connector:"AND",value:H!=null?[{value:H,isColumn:!1}]:void 0}]},!0),n.close()},j=Y=>{if(!C)return;const H=u(Y,C);n.close(),sh({tableName:Y,dataSourceId:o,entityId:H}),n.close()},_=b.useMemo(()=>p?i.filter(Y=>Y.includes(p)):i,[i,p]),O=b.useMemo(()=>{if(!y)return[];const Y=S.toLowerCase();return r.filter(H=>y.columns.some(I=>I.column===H.on.fromColumn&&I.table===H.on.fromTable)?H.on.toTable.toLowerCase().includes(Y):!1)},[S,r,y]),D=m.groupBy.length>0;return h.jsxs(z1,{handler:n,children:[i.length>0&&h.jsxs("div",{className:ne.optionsContainer,children:[h.jsxs("label",{className:"flex justify-between items-center gap-2 sticky left-0 top-0 input",children:[h.jsx("span",{className:"font-semibold",children:"📝"}),h.jsx("input",{className:"flex-1 outline-0",placeholder:"Edit/View row",value:p,onChange:Y=>g(Y.target.value)})]}),h.jsx("div",{className:"flex flex-col",children:pl(_.length,0)?_.map(Y=>h.jsx("button",{className:se(ne.optionItem,"font-semibold"),onClick:()=>j(Y),children:h.jsxs("span",{children:["📄 ",Y]})},Y)):h.jsx("p",{className:"text-center text-gray-800",children:"Empty"})})]}),r.length>0&&h.jsxs("div",{className:ne.optionsContainer,children:[h.jsxs("label",{className:"flex justify-between items-center gap-2 sticky left-0 top-0 p-1 input",children:[h.jsx("span",{className:"font-semibold",children:"↗️"}),h.jsx("input",{className:"flex-1 outline-0",placeholder:"Connected tables",value:S,onChange:Y=>E(Y.target.value)})]}),h.jsx("div",{className:"flex flex-col",children:O.length>0?O.map(Y=>h.jsx(B1,{hook:Y,onClick:()=>A(Y)},Y.where)):h.jsx("p",{className:"text-center text-gray-800",children:"Empty"})})]}),D&&h.jsx("button",{onClick:w,className:ne.underlyingRowsBtn,children:"🎯 Underlying rows"})]})},u_={ASC:"⬆️",DESC:"⬇️"},c_=()=>{const{data:n}=b.useContext(Yn),{orderBy:l,updateOrderBy:r}=IC(),i=(n==null?void 0:n.columns)||[],o=l[0];return h.jsx("thead",{children:h.jsx("tr",{children:i.map(u=>h.jsxs("td",{className:ne.headerCell,children:[h.jsxs("div",{className:"overflow-hidden",children:[h.jsx("p",{className:"text-xs truncate",children:u.table||"-"}),h.jsx("p",{className:"text-sm font-bold truncate",children:u.column})]}),h.jsx("div",{className:ne.headerActions,children:h.jsx("button",{onClick:()=>r(u.full),children:(o==null?void 0:o.column)===u.full?u_[o.direction]:"↕️"})})]},u.full))})})};function f_({value:n,row:l,col:r}){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 i=Gl(n);return h.jsxs(h.Fragment,{children:[h.jsx("span",{"data-row":l,className:"truncate block pointer-events-none",children:i}),h.jsxs("div",{className:ne.cellActions,children:[h.jsx("button",{"data-copy-col":r,"data-copy-row":l,children:"📋"}),h.jsx("button",{"data-show-col":r,"data-show-row":l,children:"👀"}),h.jsx("button",{"data-filter-col":r,"data-filter-row":l,children:"🔎"})]})]})}const d_=b.memo(({row:n,isLastRow:l,index:r})=>h.jsx("tr",{className:se(ne.tableRowCells,l&&"rounded-b-lg"),children:n.map((i,o)=>h.jsx("td",{className:ne.cell,"data-row":r,children:h.jsx(f_,{value:i,col:o,row:r})},o))})),h_=()=>{var g,S;const{data:n,error:l,isLoading:r,isFetching:i}=b.useContext(Yn),o=ih(l),u=e_(),d=q1(),[m,y]=b.useState(void 0),p=E=>{var A;const C=(A=E.target)==null?void 0:A.dataset,w=C==null?void 0:C.row;w!=null&&(y(parseInt(w)),d.open(E))};return h.jsxs(h.Fragment,{children:[m!=null&&d.show&&h.jsx(o_,{handler:d,rowIndex:m}),o&&h.jsx(Lt,{className:"my-4",variant:"danger",children:o}),r&&h.jsx("div",{className:ne.tableLoading,children:"Loading data"}),n&&h.jsxs("table",{className:se(ne.table,i&&ne.semiTransparent),onContextMenu:p,onClick:u,children:[h.jsx(c_,{}),h.jsxs("tbody",{children:[((g=n.rows)==null?void 0:g.length)<1&&h.jsx("tr",{className:ne.tableEmpty,children:h.jsx("td",{colSpan:n.columns.length,children:"No data"})}),(S=n.rows)==null?void 0:S.map((E,C)=>h.jsx(d_,{index:C,row:E,isLastRow:C===n.rows.length-1},C))]})]})]})},m_="_root_valvq_2",p_="_root-show_valvq_2",y_="_content-desktop_valvq_2",v_="_content-mobile_valvq_2",g_="_card_valvq_2",b_="_cards-list_valvq_2",x_="_sub-text_valvq_2",S_="_text_valvq_2",w_="_section-title_valvq_2",E_="_sidebar-action_valvq_2",C_="_sidebar-add-action_valvq_2",__="_section-container_valvq_2",j_="_close-button_valvq_2",N_="_section-open-btn_valvq_2",A_="_show_valvq_2",ie={root:m_,rootShow:p_,contentDesktop:y_,contentMobile:v_,card:g_,cardsList:b_,subText:x_,text:S_,sectionTitle:w_,sidebarAction:E_,sidebarAddAction:C_,sectionContainer:__,closeButton:j_,sectionOpenBtn:N_,show:A_};function T_(n,l){if(!n&&!l)return!0;if(!n||!l||n.length!==l.length)return!1;for(let r=0;r<n.length;r++)if(n[r]!==l[r])return!1;return!0}const H1=()=>{const{state:n,setState:l}=b.useContext(yt),r=b.useCallback(o=>{l(u=>({...u,filters:o}))},[l]),i=b.useCallback(o=>{l(u=>({...u,filters:u.filters.filter(d=>!(o.column===d.column&&o.operator===d.operator&&T_(o.value,d.value)))}))},[l]);return{filters:n.filters,removeFilter:i,setFilters:r}},R_=(n,l)=>n.type!==l.type||n.on!==l.on||n.table!==l.table,O_=(n,l)=>n.type===l.type&&n.on===l.on&&n.table===l.table,k1=()=>{const{state:n,setState:l}=b.useContext(yt),r=b.useCallback(i=>{l(o=>{const u=o.joins;if(u.some(m=>O_(m,i))){const m=i.table+".";return{...o,joins:u.filter(y=>R_(y,i)),columns:o.columns.filter(y=>!y.value.startsWith(m)),groupBy:o.groupBy.filter(y=>!y.value.startsWith(m)),orderBy:o.orderBy.filter(y=>!y.column.startsWith(m)),aggregations:o.aggregations.filter(y=>!y.value.startsWith(m)),filters:o.filters.filter(y=>!y.column.startsWith(m))}}return{...o,joins:[...u,i]}})},[l]);return{joins:n.joins,toggle:r}},ph=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"})),ki=new Map,D_=n=>{const l=[];return n.ctrlKey&&l.push("CTRL"),n.altKey&&l.push("ALT"),n.shiftKey&&l.push("SHIFT"),n.metaKey&&l.push("META"),l.push(n.key.toLowerCase()),l.join("+")},M_=n=>{var i,o,u;const l=(o=(i=n.target)==null?void 0:i.tagName)==null?void 0:o.toLowerCase();if(n.ctrlKey||n.altKey||n.metaKey||["input","textarea","select"].includes(l)||(u=n.target)!=null&&u.isContentEditable)return;const r=ki.get(D_(n));r&&r.length>0&&r[r.length-1].callback()},U_=(n,l,r="")=>{const i=n.toLowerCase(),o=ki.get(n);return o?ki.set(n,[...o,{callback:l,label:r}]):ki.set(i,[{callback:l,label:r}]),()=>{const u=n.toLowerCase(),d=ki.get(u);d&&ki.set(u,d.filter(m=>m.callback!==l))}};window.addEventListener("keyup",M_);function Tn(n,l,r){const i=b.useRef({callback:l,label:r});i.current.callback=l,b.useEffect(()=>U_(n,()=>{i.current.callback()},i.current.label),[n])}const L_=()=>{const n=xr("Hotkey"),l=Pt(),r=jt(),{data:i}=sa();Tn("n",()=>{i&&n()},"📖 New query"),Tn("w",()=>{if(!i)return;Ru.get().length<1?n():r.pathname!==Ue.workbench.path&&l(Ue.workbench.path)},"🛠️ Open Workbench"),Tn("h",()=>{r.pathname!==Ue.home.path&&l(Ue.home.path)},"🏠 Go home")},[q_,z_]=It(!1),yh=()=>z_(n=>!n),B_="_sidebar_1tu0c_2",H_="_sidebar-visible_1tu0c_2",k_="_sidebar-container_1tu0c_2",Q_="_sidebar-invisible_1tu0c_2",Y_="_backdrop_1tu0c_2",ir={sidebar:B_,sidebarVisible:H_,sidebarContainer:k_,sidebarInvisible:Q_,backdrop:Y_},V_=({children:n,backdropClose:l,isVisible:r,onClose:i,onClosed:o,contentClassName:u})=>{const[d,m]=b.useState(!1),y=()=>{l&&i()},p=g=>{r||getComputedStyle(g.currentTarget).opacity==="0"&&(m(!1),o&&o())};return b.useEffect(()=>{r&&m(!0)},[r]),h.jsxs("div",{onTransitionEnd:p,className:se(ir.sidebar,r?ir.sidebarVisible:ir.sidebarInvisible),children:[h.jsx("div",{onClick:y,className:ir.backdrop}),h.jsx("div",{className:se(ir.sidebarContainer,u),children:d&&n})]})},[qu,vh]=It({filters:!1,joins:!1,columns:!1,groupBy:!1,aggregate:!1}),qn=n=>vh(l=>({...l,[n]:!0})),zu=n=>vh(l=>({...l,[n]:!1})),mu=n=>vh(l=>({...l,[n]:!l[n]})),K_=()=>{const n=q_();return mh(Lu.laptop)?h.jsx("div",{className:se(ie.root,n&&ie.rootShow),children:h.jsxs("div",{className:se(ie.contentDesktop,"no-scrollbar"),children:[h.jsx(ev,{}),h.jsx(Wy,{}),h.jsx(sv,{}),h.jsx(iv,{}),h.jsx(lv,{}),h.jsx(nv,{}),h.jsx(av,{}),h.jsx(tv,{})]})}):h.jsx(V_,{isVisible:n,onClose:yh,backdropClose:!0,children:h.jsxs("div",{className:ie.contentMobile,children:[h.jsx(ev,{}),h.jsx(Wy,{}),h.jsx(sv,{}),h.jsx(iv,{}),h.jsx(lv,{}),h.jsx(nv,{}),h.jsx(av,{}),h.jsx(tv,{})]})})};function jr({onShow:n,show:l,title:r,items:i}){return h.jsxs("div",{className:"flex justify-between items-center",children:[h.jsx("p",{className:ie.sectionTitle,children:r}),i>0&&h.jsxs("button",{className:se(ie.sectionOpenBtn,l&&ie.show),onClick:n,children:[h.jsx("span",{children:i}),h.jsx(ph,{width:16,height:16})]})]})}function Wy(){const{name:n,tabId:l}=b.useContext(oa),{data:r}=b.useContext(Yn),i=()=>{l&&Pl("New tab name",n).then(u=>{u&&Ou(l,u)})},o=()=>{r!=null&&r.query&&(navigator.clipboard.writeText(r==null?void 0:r.query),qt.success("Query copied to clipboard"))};return Tn("r",i,"Rename tab"),h.jsxs("div",{className:"grid lg:grid-cols-2 gap-1 px-2 mb-4",children:[h.jsx("button",{className:ie.sidebarAction,onClick:i,children:h.jsx("span",{children:"✏️ Rename tab"})}),h.jsx("button",{className:ie.sidebarAction,onClick:o,children:h.jsx("span",{children:"🖋️ Copy SQL"})})]})}function ev(){const{state:n}=b.useContext(yt),{data:l}=Nu(n.dataSourceId);return h.jsxs("div",{className:ie.sectionContainer,children:[h.jsx("div",{className:ie.card,children:h.jsxs("div",{children:[h.jsx("p",{className:ie.subText,children:"📄 Table"}),h.jsx("p",{className:se(ie.text,"text-blue-600"),children:n.table})]})}),h.jsx("div",{className:se(ie.card,"mt-2"),children:h.jsxs("div",{children:[h.jsx("p",{className:ie.subText,children:"📦 Data source"}),h.jsx("p",{className:se(ie.text,"text-blue-600"),children:l==null?void 0:l.name})]})})]})}function tv(){const{state:n,setState:l}=b.useContext(yt),[r,i]=b.useState(!0),o=u=>{l(d=>({...d,groupBy:d.groupBy.filter(m=>ta(m)!==u)}))};return h.jsxs("div",{className:ie.sectionContainer,children:[h.jsx(jr,{title:"📚 Group by",show:r,onShow:()=>i(!r),items:n.groupBy.length}),r&&n.groupBy.length>0&&h.jsx("div",{className:ie.cardsList,children:n.groupBy.map(u=>h.jsxs("div",{className:ie.card,children:[h.jsx("span",{className:ie.text,children:ta(u)}),h.jsx("button",{className:ie.closeButton,onClick:()=>o(ta(u)),children:h.jsx(Qn,{width:20,height:20})})]},ta(u)))}),h.jsxs("button",{className:ie.sidebarAddAction,onClick:()=>qn("groupBy"),children:[h.jsx("span",{className:"hotkey",children:"G"}),h.jsx("span",{children:"Add group by"})]})]})}function nv(){const{state:n,setState:l}=b.useContext(yt),[r,i]=b.useState(!1),o=d=>{l(m=>({...m,columns:m.columns.filter(y=>ta(y)!==d)}))},u=n.aggregations.length>0||n.groupBy.length>0;return h.jsxs("div",{className:ie.sectionContainer,children:[h.jsx(jr,{title:"👀 Columns",show:r,onShow:()=>i(!r),items:u?0:n.columns.length}),u&&h.jsx(Lt,{variant:"warning",className:"border border-yellow-800 my-2",children:h.jsx("span",{className:ie.text,children:"Columns are ignored when there is at least one aggregation or group by"})}),!u&&r&&n.columns.length>0&&h.jsx("div",{className:ie.cardsList,children:n.columns.map(d=>h.jsxs("div",{className:ie.card,children:[h.jsx("span",{className:ie.text,children:ta(d)}),h.jsx("button",{className:ie.closeButton,onClick:()=>o(ta(d)),children:h.jsx(Qn,{width:20,height:20})})]}))}),!u&&h.jsxs("button",{className:ie.sidebarAddAction,onClick:()=>qn("columns"),children:[h.jsx("span",{className:"hotkey",children:"C"}),h.jsx("span",{children:"Show/Hide columns"})]})]})}function av(){const{state:n,setState:l}=b.useContext(yt),[r,i]=b.useState(!0),o=u=>{const d=ta(u);l(m=>({...m,aggregations:m.aggregations.filter(y=>y.fn!==u.fn||y.value!==u.value),orderBy:m.orderBy.filter(y=>y.column!==d)}))};return h.jsxs("div",{className:ie.sectionContainer,children:[h.jsx(jr,{title:"🔢 Aggregations",show:r,onShow:()=>i(!r),items:n.aggregations.length}),r&&n.aggregations.length>0&&h.jsx("div",{className:ie.cardsList,children:n.aggregations.map(u=>h.jsxs("div",{className:ie.card,children:[h.jsxs("span",{className:ie.text,children:[u.fn," ",u.value]}),h.jsx("button",{className:ie.closeButton,onClick:()=>o(u),children:h.jsx(Qn,{width:20,height:20})})]}))}),h.jsxs("button",{className:ie.sidebarAddAction,onClick:()=>qn("aggregate"),children:[h.jsx("span",{className:"hotkey",children:"A"}),h.jsx("span",{children:"Aggregate data"})]})]})}const G_=n=>(n==null?void 0:n.map(l=>l.value).join(", "))||"";function lv(){const{state:n}=b.useContext(yt),{removeFilter:l}=H1(),[r,i]=b.useState(!0),o=()=>{qn("filters")};return h.jsxs("div",{className:ie.sectionContainer,children:[h.jsx(jr,{title:"🎚️ Filters",show:r,onShow:()=>i(!r),items:n.filters.length}),r&&n.filters.length>0&&h.jsx("div",{className:ie.cardsList,children:n.filters.map((u,d)=>h.jsxs("div",{className:ie.card,children:[h.jsxs("div",{className:"overflow-hidden",children:[h.jsx("p",{className:se(ie.subText,"truncate"),children:u.column}),h.jsxs("p",{className:se(ie.text,"truncate"),children:[Wd[u.operator]," ",G_(u.value)]})]}),h.jsx("button",{className:ie.closeButton,onClick:()=>l(u),children:h.jsx(Qn,{width:20,height:20})})]},d))}),h.jsxs("button",{className:ie.sidebarAddAction,onClick:o,children:[h.jsx("span",{className:"hotkey",children:"F"}),h.jsx("span",{children:"Filter data"})]})]})}function iv(){const{toggle:n}=k1(),{availableJoins:l}=b.useContext(oa),{state:r}=b.useContext(yt),[i,o]=b.useState(!0);return h.jsxs("div",{className:ie.sectionContainer,children:[h.jsx(jr,{title:"📄 Joins",show:i,onShow:()=>o(!i),items:r.joins.length}),i&&r.joins.length>0&&h.jsx("div",{className:ie.cardsList,children:r.joins.map((u,d)=>h.jsxs("div",{className:ie.card,children:[h.jsxs("div",{className:"overflow-hidden",children:[h.jsxs("p",{className:se(ie.subText,"truncate"),children:["on ",u.on]}),h.jsx("p",{className:ie.text,children:u.table})]}),d===r.joins.length-1&&h.jsx("button",{className:ie.closeButton,onClick:()=>n(u),children:h.jsx(Qn,{width:20,height:20})})]},u.table+u.on))}),l.length>0&&h.jsxs("button",{onClick:()=>qn("joins"),className:ie.sidebarAddAction,children:[h.jsx("span",{className:"hotkey",children:"J"}),h.jsx("span",{children:"Join table"})]})]})}function sv(){const{state:n,setState:l}=b.useContext(yt);if(!n.orderBy.length)return null;const r=i=>{l(o=>({...o,orderBy:o.orderBy.filter(u=>u.column!==i.column&&u.direction!==i.direction)}))};return h.jsxs("div",{className:ie.sectionContainer,children:[h.jsx("p",{className:ie.sectionTitle,children:"Order by"}),h.jsx("div",{className:ie.cardsList,children:n.orderBy.map((i,o)=>h.jsxs("div",{className:ie.card,children:[h.jsxs("div",{className:"overflow-hidden",children:[h.jsx("p",{className:se(ie.subText,"truncate"),children:i.direction}),h.jsx("p",{className:ie.text,children:i.column})]}),h.jsx("button",{className:ie.closeButton,onClick:()=>r(i),children:h.jsx(Qn,{width:20,height:20})})]},o))})]})}const Q1=()=>{const{state:n,setState:l}=b.useContext(yt),r=b.useCallback(o=>{l(u=>({...u,page:o}))},[l]),i=b.useCallback(o=>{l(u=>({...u,size:o}))},[l]);return{page:n.page,size:n.size,setSize:i,setPage:r}},F_=n=>fn({queryKey:["query",n],queryFn:async()=>{const{data:l}=await Ve.get("/queries/"+n);return l.data},enabled:!!n}),$_=()=>cn({mutationFn:async n=>{const{data:l}=await Ve.post("/saved-queries",n);return l.data},onSuccess:()=>{pt.invalidateQueries(["queries"]),Wi()}}),X_=()=>cn({mutationFn:async n=>Ve.delete("/saved-queries/"+n),onSuccess:()=>{Wi()}}),Z_=()=>cn({mutationFn:async({id:n,payload:l})=>{const{data:r}=await Ve.patch("/queries/"+n,l);return r.data},onSuccess:n=>{pt.invalidateQueries(["query",n.id]),Wi(),k3(),n.isTrash}}),[J_,Y1]=It(void 0),Ud=()=>Y1(void 0);function P_(){return h.jsxs("div",{className:"flex items-center bg-white border-b border-gray-200 overflow-auto no-scrollbar",children:[h.jsx(I_,{}),h.jsx(W_,{}),h.jsx(ej,{}),h.jsx(tj,{})]})}function I_(){const{dataSourceId:n,name:l,tabId:r}=b.useContext(oa),{data:i}=Nu(n),{data:o}=b.useContext(Yn),u=Sr(Xt.EDITOR),d=$_(),m=()=>{var p,g;(p=o==null?void 0:o.columns)!=null&&p[0].table&&lh({table:(g=o==null?void 0:o.columns)==null?void 0:g[0].table,dataSourceId:n})},y=async()=>{const p=await Pl("Query name",l);!p||!(o!=null&&o.queryHistoryId)||(d.mutate({name:p,queryId:o.queryHistoryId}),r&&Ou(r,p))};return Tn("s",y,"Save query"),h.jsxs("div",{className:ne.tableConfig,children:[h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Manage filters",onClick:()=>qn("filters"),className:se(ne.tableAction,ne.blue),children:[h.jsx("span",{children:"Filter"}),h.jsx("span",{className:"hotkey",children:"F"})]}),h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Join tables",onClick:()=>qn("joins"),className:se(ne.tableAction,ne.blue),children:[h.jsx("span",{children:"Join"}),h.jsx("span",{className:"hotkey",children:"J"})]}),h.jsx(nj,{}),h.jsxs("button",{"data-tooltip-id":"explorer-more-actions",className:se(ne.tableAction,ne.blue),children:[h.jsx("span",{className:"whitespace-nowrap",children:"More actions"}),h.jsx(ph,{width:16,height:16,className:"rotate-90"})]}),h.jsxs(hh,{id:"explorer-more-actions",className:"z-10 shadow-md flex flex-col",clickable:!0,variant:"light",opacity:1,children:[h.jsxs("button",{onClick:()=>qn("columns"),className:se(ne.tableAction,ne.modal,ne.blue,"justify-between"),children:[h.jsx("span",{children:"Columns"}),h.jsx("span",{className:"hotkey",children:"C"})]}),h.jsxs("button",{onClick:()=>qn("groupBy"),className:se(ne.tableAction,ne.modal,ne.blue,"justify-between"),children:[h.jsx("span",{children:"Group by"}),h.jsx("span",{className:"hotkey",children:"G"})]}),h.jsxs("button",{onClick:()=>qn("aggregate"),className:se(ne.tableAction,ne.modal,ne.blue,"justify-between"),children:[h.jsx("span",{children:"Aggregate"}),h.jsx("span",{className:"hotkey",children:"A"})]}),h.jsxs("button",{onClick:yh,className:se(ne.tableAction,ne.modal,ne.blue,"justify-between"),children:[h.jsx("span",{children:"Query editor"}),h.jsx("span",{className:"hotkey",children:"E"})]}),u&&h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"h-0.5 my-2 bg-gray-100"}),h.jsxs("button",{onClick:y,className:se(ne.tableAction,ne.modal,ne.blue),children:[h.jsx("span",{children:"Save query"}),h.jsx("span",{className:"hotkey",children:"S"})]}),(i==null?void 0:i.allowInsert)===!0&&h.jsx("button",{onClick:m,className:se(ne.tableAction,ne.modal,ne.blue),children:"Insert new row"})]})]})]})}function W_(){const{name:n}=b.useContext(oa),{state:l}=b.useContext(yt),{refetch:r,data:i}=b.useContext(Yn),o=(window==null?void 0:window.location.hostname)!=="localhost",u=xr("Workbook"),d=()=>{yl(n,l,!0),Ud()},m=()=>{if(i!=null&&i.queryHistoryId){const y=new URL(window.location.href);y.pathname=Ue.share.path,y.searchParams.set("shareId",i.queryHistoryId),navigator.clipboard.writeText(y.toString()),qt.success("Share link copied to clipboard")}};return Tn("e",yh,"Show editor sidebar"),h.jsxs("div",{className:ne.tableConfig,children:[h.jsx("button",{"data-tooltip-id":"default","data-tooltip-content":"Refresh data",onClick:r,className:se(ne.tableAction,ne.blue),children:"Refresh"}),o&&h.jsx("button",{"data-tooltip-id":"default","data-tooltip-content":"Share query",onClick:m,className:se(ne.tableAction,ne.blue),children:"Share"}),h.jsx("button",{"data-tooltip-id":"default","data-tooltip-content":"Clone in a new tab",onClick:d,className:se(ne.tableAction,ne.blue),children:"Clone"}),h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Start new query tab",onClick:u,className:se(ne.tableAction,ne.blue),children:[h.jsx("span",{className:"whitespace-nowrap",children:"New query"}),h.jsx("span",{className:"hotkey",children:"N"})]})]})}function ej(){const{page:n,size:l,setPage:r}=Q1(),{data:i}=b.useContext(Yn),o=(i==null?void 0:i.rows.length)===l;return h.jsxs("div",{className:ne.tableConfig,children:[h.jsx("button",{"data-tooltip-content":"Previous page","data-tooltip-id":"default",disabled:n<=0,className:se(ne.tableAction,ne.blue),onClick:()=>r(n-1),children:"Prev"}),h.jsx("span",{className:"text-sm bg-gray-50 rounded-md px-2 border border-gray-200",children:n+1}),h.jsx("button",{"data-tooltip-content":"Next page","data-tooltip-id":"default",disabled:!o,className:se(ne.tableAction,ne.blue),onClick:()=>r(n+1),children:"Next"})]})}function tj(){const{size:n,setSize:l}=Q1();return h.jsx("div",{className:ne.tableConfig,children:h.jsx("label",{className:ne.tableAction,"data-tooltip-content":"Size","data-tooltip-id":"default",children:h.jsxs("select",{style:{height:"20px"},value:n,onChange:r=>l(parseInt(r.target.value,10)),children:[h.jsx("option",{value:5,children:"5 rows"}),h.jsx("option",{value:10,children:"10 rows"}),h.jsx("option",{value:20,children:"20 rows"}),h.jsx("option",{value:50,children:"50 rows"}),h.jsx("option",{value:100,children:"100 rows"}),h.jsx("option",{value:200,children:"200 rows"})]})})})}function nj(){const{state:n,setState:l}=b.useContext(yt),r=()=>{l(o=>({...o,searchAll:void 0}))},i=()=>{Pl("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(o=>{o!==void 0&&l(u=>({...u,searchAll:o.length>0?o:void 0}))})};return Tn("k",i,"Search text"),n.searchAll?h.jsx("button",{"data-tooltip-id":"default","data-tooltip-content":"Remove search all filter",onClick:r,className:se(ne.tableAction,ne.red),children:h.jsxs("span",{className:"truncate px-1",children:["❌ ",n.searchAll]})}):h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Search text in all columns",onClick:i,className:se(ne.tableAction,ne.blue),children:[h.jsx("span",{className:"whitespace-nowrap",children:"Search text"}),h.jsx("span",{className:"hotkey",children:"K"})]})}const aj="_drop-container_1labe_2",lj="_item_1labe_2",rv={dropContainer:aj,item:lj},Ld=({dataSourceId:n,focusId:l,placeholder:r="Column",onChange:i,value:o,autoFocus:u,allowTables:d})=>{const{data:m}=es(n),y=b.useRef(null),p=b.useMemo(()=>{if(!m)return[];let _=m;return d&&(_=m.filter(O=>d.includes(O.tableName))),_.flatMap(O=>O.columns.map(D=>({value:O.tableName+"."+D.name,label:D.name,table:O.tableName,searchValue:D.name.toLowerCase()})))},[m,d]),g=b.useMemo(()=>{const _=o.toLowerCase()||"",O=[];for(let D=0;D<p.length&&O.length<10;D++)p[D].searchValue.includes(_)&&O.push(p[D]);return O},[p,o]),[S,E]=b.useState(!1),[C,w]=b.useState(0),A=_=>{var O;if(_.key==="ArrowDown")_.preventDefault(),w(D=>(D+1)%g.length);else if(_.key==="ArrowUp")_.preventDefault(),w(D=>(D-1+g.length)%g.length);else if(_.key==="Enter"&&C>=0&&C<g.length){_.preventDefault();const D=g[C].value;E(!1);const Y=p.findIndex(H=>H.value===D)>-1;i(((O=g[C])==null?void 0:O.value)||D,Y,!0)}};b.useEffect(()=>{var O;const _=(O=y.current)==null?void 0:O.querySelector('[data-is-active="true"]');_&&_.scrollIntoView({behavior:"smooth",block:"nearest"})},[C]);const j=_=>{const O=_.currentTarget.value,D=p.findIndex(Y=>Y.value===O)>-1;i(O,D,!1)};return h.jsxs("div",{className:"relative",onFocus:()=>E(!0),onBlur:()=>E(!1),children:[h.jsx("input",{autoFocus:u,onKeyDown:A,value:o,onChange:j,className:"input w-full",placeholder:r,"data-focus":l}),S&&g.length>0&&h.jsx("div",{className:rv.dropContainer,ref:y,tabIndex:-1,children:g.map((_,O)=>h.jsxs("div",{className:rv.item,"data-is-active":C===O,onMouseDownCapture:D=>{D.preventDefault(),E(!1),i(_.value,!0,!0)},children:[h.jsx("span",{className:"text-xs font-semibold truncate",children:_.table}),h.jsx("p",{className:"truncate text-sm",children:_.label})]},O))})]})},ij="_drop-container_jg8ux_2",sj="_item_jg8ux_2",ov={dropContainer:ij,item:sj};function rj(n){return o4.includes(n)?i4:u4.includes(n)?l4:c4.includes(n)?s4:Id}const oj=({value:n,onChange:l,autoFocus:r,focusId:i,colType:o})=>{const u=b.useMemo(()=>{const E=n.toLowerCase()||"";return rj(o||"").filter(C=>C.label.includes(E))},[n,o]),d=b.useRef(null),[m,y]=b.useState(!1),[p,g]=b.useState(0),S=E=>{var C;E.key==="ArrowDown"?(E.preventDefault(),g(w=>(w+1)%u.length)):E.key==="ArrowUp"?(E.preventDefault(),g(w=>(w-1+u.length)%u.length)):E.key==="Enter"&&(p>=0&&p<u.length?(E.preventDefault(),y(!1),l(((C=u[p])==null?void 0:C.label)||"",!0)):l(n,!0))};return b.useEffect(()=>{var C;const E=(C=d.current)==null?void 0:C.querySelector('[data-is-active="true"]');E&&E.scrollIntoView({behavior:"smooth",block:"nearest"})},[p]),h.jsxs("div",{className:"relative",children:[h.jsx("input",{onKeyDown:S,value:n,onChange:E=>l(E.target.value,!1),className:"input w-full",placeholder:"Operator",autoFocus:r,onFocus:()=>y(!0),onBlur:()=>y(!1),"data-focus":i}),m&&u.length>0&&h.jsx("ul",{className:ov.dropContainer,ref:d,tabIndex:-1,children:u.map((E,C)=>h.jsx("li",{className:ov.item,"data-is-active":p===C,onMouseDownCapture:w=>{w.preventDefault(),y(!1),l(E.label,!0)},children:E.label},C))})]})},uj="_actions_r2knb_2",cj="_filter-actions_r2knb_2",V1={actions:uj,filterActions:cj},fj=["=","<",">",">=","<>","!=","<="];function dj(n){for(let l=0;l<n.length;l++){const r=n[l];if(!r.operator.length&&!r.value.length&&!r.column.length)continue;if(!r.column.includes("."))return qt.error(`Filter #${l+1} has invalid column value`),!1;const i=eh[r.operator];if(!i)return qt.error(`Filter #${l+1} has invalid operator`),!1;if(r.isColumnRef&&!fj.includes(i))return qt.error(`Filter #${l+1} cannot reference another column because it uses '${r.operator}' operator`),!1}return!0}function hj(n){const l=[];return n.forEach(r=>{if(!r.operator.length||!r.column.length||r.operator!=="is null"&&r.operator!=="is not null"&&!r.value.length)return;const i=eh[r.operator];l.push({id:r.id,value:r.isColumnRef?[{value:r.value,isColumn:!0}]:r4(i,r.value),operator:i,column:r.column,isEnabled:!0,connector:"AND"})}),l}function mj(n){let l="";if(n.value)for(let r=0;r<n.value.length;r++)l+=n.value[r].value,r<n.value.length-1&&(l+=", ");return l}const pj=({filter:n,dataSourceId:l,allowedTables:r,inspections:i,autoFocus:o,onChangeColumn:u,onChangeOperator:d,onChangeValue:m,onRemoveFilter:y,onIsColumnChange:p})=>{const g=b.useMemo(()=>{if(!i)return"";let S=null;for(const E of i)for(const C of E.columns)E.tableName+"."+C.name===n.column&&(S=C);return S!=null&&S.type?S.type:""},[n.column,i]);return h.jsxs("div",{className:"flex gap-2 items-center",children:[h.jsx("label",{className:"w-full",children:h.jsx(Ld,{dataSourceId:l,onChange:S=>u(n.id,S),value:n.column,allowTables:r,focusId:"column",autoFocus:o})}),h.jsx("label",{children:h.jsx(oj,{onChange:S=>d(n.id,S),focusId:"operator",colType:g,value:n.operator})}),b1(eh[n.operator])&&h.jsx("label",{className:"w-full",children:n.isColumnRef?h.jsx(Ld,{dataSourceId:l,onChange:S=>m(n.id,S),value:n.value,allowTables:r,focusId:"value",placeholder:"Search column"}):h.jsx("input",{className:"input w-full",placeholder:"Filter value",value:n.value,onChange:S=>m(n.id,S.currentTarget.value),"data-focus":"value"})}),h.jsxs("div",{className:V1.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:se("p-0.5 cursor-pointer rounded-lg border",n.isColumnRef?"bg-blue-50 border-blue-200":"bg-white border-white"),onClick:()=>p(n.id,!n.isColumnRef),children:"🏷️"}),h.jsx("button",{tabIndex:-1,"data-tooltip-id":"default","data-tooltip-content":"Remove aggregation",className:"p-0.5 text-sm cursor-pointer",onClick:()=>y(n.id),children:h.jsx(Qn,{width:20,height:20,className:"text-red-600"})})]})]})},yj=()=>{const{state:n}=b.useContext(yt),{setFilters:l}=H1(),r=qu(A=>A.filters),{data:i}=es(n.dataSourceId),o=b.useMemo(()=>[n.table,...n.joins.map(A=>A.table)],[n.table,n.joins]),[u,d]=b.useState([]),m=(A,j)=>{d(_=>[..._.map(O=>O.id===A?{...O,column:j}:O)])},y=(A,j)=>{d(_=>[..._.map(O=>O.id===A?{...O,operator:j}:O)])},p=(A,j)=>{d(_=>[..._.map(O=>O.id===A?{...O,value:j}:O)])},g=()=>{d(A=>[...A,{id:Ua(),value:"",column:"",operator:"",isColumnRef:!1}])},S=(A,j)=>{d(_=>[..._.map(O=>O.id===A?{...O,isColumnRef:j}:O)])},E=A=>{d(j=>j.filter(_=>_.id!==A))},C=()=>zu("filters"),w=()=>{dj(u)&&(l(hj(u)),C())};return b.useEffect(()=>{if(!r){d([]);return}d(()=>{const A=n.filters.map(j=>{var _,O;return{id:j.id,value:mj(j),column:j.column,operator:Wd[j.operator],isColumnRef:!!((O=(_=j.value)==null?void 0:_[0])!=null&&O.isColumn)}});return A.push({id:Ua(),value:"",column:"",operator:"",isColumnRef:!1}),A})},[r]),Tn("f",()=>{mu("filters")},"Add new filter"),h.jsxs(Yt,{isVisible:r,onClose:C,portal:!0,children:[h.jsx(On,{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:[u.length<1&&h.jsx("p",{className:"p-1 text-center rounded-lg bg-gray-50 border border-gray-200",children:"No filters"}),u.map((A,j)=>h.jsx(pj,{filter:A,dataSourceId:n.dataSourceId,allowedTables:o,inspections:i||[],onChangeColumn:m,onChangeOperator:y,onChangeValue:p,onRemoveFilter:E,onIsColumnChange:S,autoFocus:j===u.length-1},A.id))]}),h.jsxs("div",{className:V1.actions,children:[h.jsx("button",{className:"button tertiary",onClick:g,children:"Add filter"}),h.jsx("button",{className:"button primary",onClick:w,children:"Apply filters"})]})]})},vj="_card_phvek_2",gj="_cards-list_phvek_2",bj="_join-modal_phvek_2",xj="_close-button_phvek_2",Qo={card:vj,cardsList:gj,joinModal:bj,closeButton:xj},Sj=()=>{const{isFetching:n}=b.useContext(Yn),l=qu(p=>p.joins),{toggle:r,joins:i}=k1(),{availableJoins:o}=b.useContext(oa),[u,d]=b.useState(""),m=b.useMemo(()=>{const p=u.toLowerCase();return o.filter(g=>g.on.toTable.toLowerCase().includes(p))},[o,u]),y=()=>zu("joins");return Tn("j",()=>{o.length>0?qn("joins"):qt.error("No available tables to join")},"Add new join"),h.jsxs(Yt,{isVisible:l,onClose:y,portal:!0,children:[h.jsx(On,{onClick:y}),h.jsxs("div",{className:Qo.joinModal,children:[h.jsx("h2",{className:"text-lg font-semibold mb-4",children:"Join table"}),i.length>0&&h.jsx("div",{className:Qo.cardsList,children:i.map((p,g)=>h.jsxs("div",{className:Qo.card,children:[h.jsxs("p",{className:"text-sm truncate",children:[p.table," on ",p.on]}),g===i.length-1&&h.jsx("button",{className:Qo.closeButton,onClick:()=>r(p),disabled:n,children:h.jsx(Qn,{width:20,height:20})})]},p.table+p.on))}),m.length>0?h.jsx("input",{className:"input w-full",placeholder:"Filter",autoFocus:!0,onChange:p=>d(p.target.value),value:u,disabled:n}):h.jsx(Lt,{variant:"warning",children:h.jsx("p",{className:"text-sm truncate",children:"No more tables to join"})}),h.jsx("div",{className:`flex flex-col mt-2 overflow-y-auto ${n?"opacity-40":""}`,children:m.map(p=>h.jsx(B1,{hook:p,onClick:()=>{n||(r({table:p.on.toTable,type:"LEFT",on:p.where}),d(""))}},p.where))})]})]})};function wj(n){return n.reduce((l,r)=>(l[r]=!0,l),{})}function Ej(n){return n.reduce((l,r)=>(l[r]=!0,l),{})}const Cj="_container_141nc_2",_j="_column-label_141nc_2",jj="_not-active_141nc_2",Wo={container:Cj,columnLabel:_j,notActive:jj};function Nj(n){if(!n)return[];const l={};return n.forEach(r=>{l[r.table]?l[r.table].push({value:r.full,ogColumn:r.column,label:hl(r.column),type:r.type}):l[r.table]=[{value:r.full,ogColumn:r.column,label:hl(r.column),type:r.type}],f4[r.type]&&["YEAR","MONTH","DAY"].forEach(i=>{l[r.table].push({value:i+" "+r.full,ogColumn:r.column,label:i+" "+hl(r.column),type:"number",nested:!0})})}),Object.entries(l).reduce((r,[i,o])=>(r.push({name:hl(i),columns:o}),r),[])}function Aj(n,l){const r=l.toLowerCase();return n.map(i=>{const o=i.columns.filter(u=>u.label.toLowerCase().includes(r)||u.ogColumn.toLowerCase().includes(r));return{...i,columns:o}}).filter(i=>i.columns.length>0)}const Tj=({column:n,selected:l,onCheck:r})=>h.jsxs("label",{className:se(Wo.columnLabel,l?Wo.active:Wo.notActive,n.nested&&"pl-5!"),children:[h.jsx("input",{type:"checkbox",checked:l[n.value],name:n.value,onChange:r}),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),Rj={columns:"c",groupBy:"g"},uv=({mode:n})=>{const l=qu(_=>_[n]),{allColumns:r}=b.useContext(oa),{state:i,setState:o}=b.useContext(yt),[u,d]=b.useState({}),[m,y]=b.useState(""),p=b.useMemo(()=>Nj(r),[r]),g=i.aggregations.length>0||i.groupBy.length>0,S=b.useMemo(()=>m?Aj(p,m):p,[m,p]),E=_=>{d(O=>({...O,[_.target.name]:_.target.checked}))},C=_=>{const O=_.target.checked;d(D=>{for(const Y of r)D[Y.full]=O;return{...D}})},w=()=>{zu(n)},A=()=>{const _=[];for(const[O,D]of Object.entries(u))if(D){const[Y,H]=O.split(" ");_.push({value:H||Y,fn:H?Y:void 0})}o(O=>({...O,[n]:_})),w()},j=b.useMemo(()=>{for(const _ of r)if(!u[_.full])return!1;return!0},[u,r]);return Tn(Rj[n],()=>{n==="columns"?g?qt.error("Columns are ignored when there is at least one aggregation or group by"):mu("columns"):mu("groupBy")},"Manage "+n),b.useEffect(()=>{if(!l){d({});return}d(()=>wj(i[n].map(_=>_.fn?_.fn+" "+_.value:_.value)))},[l,d]),h.jsxs(Yt,{isVisible:l,onClose:w,portal:!0,children:[h.jsx(On,{onClick:w}),h.jsxs("div",{className:Wo.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:_=>y(_.target.value)}),h.jsx("div",{className:"overflow-y-auto",children:S.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(Tj,{column:O,selected:u,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:j,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:A,children:"Apply"})]})]})]})},Oj="_options-container_14i8j_2",Dj={optionsContainer:Oj},cd="COUNT all",Mj=n=>n.distinct?[n.fn,"DISTINCT",n.value].join(" "):[n.fn,n.value].join(" "),Uj=()=>{const n=qu(w=>w.aggregate),{dataSourceId:l}=b.useContext(oa),{setState:r,state:i}=b.useContext(yt),{data:o}=b.useContext(Yn),[u,d]=b.useState({fn:"",col:""}),m=w=>d({...u,fn:w.currentTarget.value}),y=w=>d({...u,col:w}),p=()=>zu("aggregate"),g=()=>{const w=u.fn===cd?{value:"*",fn:"COUNT"}:{fn:u.fn,value:u.col,distinct:u.fn==="COUNT"};r(A=>({...A,aggregations:[...A.aggregations,w]}))},S=u.fn===cd,E=S?!1:!u.col||!u.fn,C=w=>{const A=ta(w);r(j=>({...j,aggregations:j.aggregations.filter(_=>_.fn!==w.fn||_.value!==w.value),orderBy:j.orderBy.filter(_=>_.column!==A)}))};return Tn("a",()=>{mu("aggregate")},"Aggregate data"),h.jsxs(Yt,{isVisible:n,onClose:p,backdropClose:!0,portal:!0,children:[h.jsx(On,{onClick:p}),h.jsxs("div",{children:[h.jsx("h2",{className:"text-lg font-semibold",children:"Aggregate"}),pl(i.aggregations.length,0)&&h.jsx("div",{className:"flex flex-col gap-1 mt-4",children:i.aggregations.map((w,A)=>h.jsxs("p",{className:"p-2 rounded-md bg-gray-50 flex items-center justify-between",children:[h.jsx("span",{children:Mj(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(Qn,{width:20,height:20,className:"text-red-600"})})]},A))}),h.jsxs("div",{className:Dj.optionsContainer,children:[h.jsxs("label",{className:se(S&&"col-span-2"),children:[h.jsx("p",{className:"font-semibold text-xs",children:"Function"}),h.jsxs("select",{className:"input w-full",value:u.fn,onChange:m,autoFocus:!0,children:[h.jsx("option",{value:"",disabled:!0,children:"Select function"}),h.jsx("option",{value:cd,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"})]})]}),!S&&h.jsxs("label",{children:[h.jsx("p",{className:"font-semibold text-xs",children:"Column"}),h.jsx(Ld,{dataSourceId:l,allowTables:(o==null?void 0:o.tables)||[],onChange:y,value:u.col})]}),h.jsx("button",{className:"button primary",disabled:E,onClick:g,children:"Add"})]})]})]})},K1=({options:n,updater:l,name:r,tabId:i})=>{const o=m4(n,l),{state:u}=o,d=lE({datasourceId:n.dataSourceId,name:r,opts:{table:n.table,filters:u.filters,joins:u.joins,orderBy:u.orderBy,columns:u.columns,aggregations:u.aggregations,groupBy:u.groupBy,searchAll:u.searchAll},page:u.page,size:u.size}),m=h4(d.data,n.dataSourceId,r,i);return h.jsx(oa,{value:m,children:h.jsx(yt,{value:o,children:h.jsxs(Yn,{value:d,children:[h.jsx(P_,{}),h.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[h.jsxs("div",{className:"m-1 flex-1 overflow-auto pb-12 no-scrollbar",children:[h.jsx("div",{className:"pb-0.5 sticky bottom-0"}),h.jsx(h_,{})]}),h.jsx(yj,{}),h.jsx(Sj,{}),h.jsx(uv,{mode:"columns"}),h.jsx(uv,{mode:"groupBy"}),h.jsx(Uj,{}),h.jsx(K_,{})]})]})})})},Lj=({tab:n})=>{const l=b.useCallback(r=>{Tu(i=>i.map(o=>o.id!==n.id?o:{...o,options:r(o.options)}))},[n]);return h.jsx(K1,{updater:l,options:n.options,name:n.label,tabId:n.id})},qj=({content:n,activeAnchor:l})=>{if(!l)return null;const r=l.getAttribute("data-tab-id"),i=Ru.get().find(d=>d.id===r),o=DC(i==null?void 0:i.options.dataSourceId);if(!i)return n;const u=()=>{Pl("New tab name",i.label).then(d=>{d&&Ou(i.id,d)})};return h.jsxs("div",{children:[h.jsxs("button",{className:ea.tooltipLabel,onClick:u,children:[h.jsxs("div",{className:"overflow-hidden",children:[h.jsx("p",{className:"text-xs",children:"label"}),h.jsx("p",{className:"truncate font-semibold",children:i.label})]}),h.jsx("span",{children:"✏️"})]}),h.jsxs("div",{className:ea.tooltipInfoEntry,children:[h.jsx("p",{className:"text-sm",children:"table"}),h.jsx("p",{className:"truncate font-semibold",children:i.options.table})]}),o&&h.jsxs("div",{className:ea.tooltipInfoEntry,children:[h.jsxs("p",{className:"text-sm",children:["data source [",o.dbType,"]"]}),h.jsx("p",{className:"truncate font-semibold",children:o.name})]}),i.options.joins.length>0&&h.jsxs("div",{className:ea.tooltipInfoEntry,children:[h.jsx("p",{className:"text-sm",children:"joins"}),h.jsx("p",{className:"truncate font-semibold",children:i.options.joins.map(d=>d.table).join(", ")})]}),i.options.filters.length>0&&h.jsxs("div",{className:ea.tooltipInfoEntry,children:[h.jsx("p",{className:"text-sm",children:"filters"}),i.options.filters.map(d=>h.jsx("p",{className:"truncate font-semibold",children:I4(d)}))]})]})},zj=()=>{const n=y4(),l=Au(),r=mh(Lu.laptop),i=b.useMemo(()=>{if(!l)return;const m=l.find(y=>y.id===n);return m||l[0]},[n,l]),o=m=>{m.stopPropagation(),m.preventDefault();const y=m.currentTarget.getAttribute("data-tab-id");y&&qy(y)},u=m=>{m.button===1&&qy(m.currentTarget.dataset.tabId)},d=m=>{const y=l.find(p=>p.id===m);Pl("New tab name",y==null?void 0:y.label).then(p=>{p&&Ou(m,p)})};return l.length<1?h.jsx(t2,{to:"/"}):h.jsxs("div",{className:"h-screen max-h-screen bg-(--bg) flex flex-col",children:[r&&h.jsx(hh,{id:"tab",render:qj,className:"z-10 shadow-md p-0!",offset:-1,noArrow:!0,opacity:1,variant:"light",clickable:!0,delayShow:500}),i&&h.jsx(Lj,{tab:i}),h.jsx("div",{className:se(ea.tabs,"no-scrollbar",!r&&ea.mobile),children:l==null?void 0:l.map(m=>h.jsxs("div",{onClick:()=>nh(m.id),className:se(ea.tab,m.id===(i==null?void 0:i.id)&&ea.active),"data-tab-id":m.id,"data-tooltip-id":"tab","data-tooltip-content":m.label,onAuxClick:u,onContextMenu:y=>{y.preventDefault(),d(m.id)},children:[h.jsxs("span",{className:"truncate w-full",children:["📄 ",m.label]}),h.jsx("button",{"data-tab-id":m.id,className:ea.closeButton,onClick:o,children:h.jsx(Qn,{width:20,height:20})})]},m.id))})]})},Bj=()=>{const n=J_(),l=b.useCallback(r=>{Y1(i=>i?{...i,options:r(i.options)}:(qt.error("Something went wrong."),i))},[]);return n?h.jsxs(Yt,{isVisible:!0,onClose:Ud,children:[h.jsx(On,{onClick:Ud}),h.jsx("div",{className:"border border-gray-200 bg-(--bg) flex flex-col",children:h.jsx(K1,{name:n.label,options:n.options,updater:l})})]}):null},Hj="_root_cmyhu_2",kj="_down_cmyhu_2",Qj="_chevron_cmyhu_2",Yj="_table-name-container_cmyhu_2",Vj="_link_cmyhu_2",Kj="_table-name_cmyhu_2",Gj="_ul_cmyhu_2",Fj="_column-type_cmyhu_2",Ra={root:Hj,down:kj,chevron:Qj,tableNameContainer:Yj,link:Vj,tableName:Kj,ul:Gj,columnType:Fj},[i6,$j]=It(!1),G1=()=>$j(!1),Xj=new Intl.DateTimeFormat("en",{dateStyle:"full",timeStyle:"long"});function Zj(n,l){if(l&&n.toLowerCase().includes(l))return"bg-yellow-200"}const Jj=({insp:n,filter:l,expanded:r})=>{const i=b.useMemo(()=>r?n.columns:l.length<1?[]:n.columns.filter(o=>o.name.toLowerCase().includes(l)),[n,l,r]);return h.jsx("ul",{className:Ra.ul,children:i.map(o=>h.jsx(h.Fragment,{children:h.jsxs("li",{children:[o.isPrimary?"🔐":"🏷️"," ",h.jsx("span",{className:Zj(o.name,l),children:o.name})," ",h.jsxs("span",{className:Ra.columnType,children:["[",o.type,"]"]}),o.ref&&h.jsxs("span",{children:[" ➡️ ",h.jsx("span",{className:Ra.columnType,children:o.ref.table}),".",o.ref.field]})]},o.name+o.type)}))},n.id)};function Pj({id:n}){const{data:l}=Nu(n),{data:r}=es(n),i=Pt(),{pathname:o}=jt(),u=F3(),d=y1(),m=$3(),y=b.useMemo(()=>l!=null&&l.lastInspected?Xj.format(new Date(l.lastInspected)):"--",[l]),[p,g]=b.useState({}),[S,E]=b.useState(""),[C,w]=b.useState("table"),A=Sr(Xt.EDITOR),j=S.toLowerCase(),_=b.useMemo(()=>{if(!j||!r)return r||[];const W=[];for(const re of r){if(re.tableName.toLowerCase().includes(j)){W.push(re);continue}C!=="table"&&re.columns.findIndex(pe=>pe.name.toLowerCase().includes(j))>=0&&W.push(re)}return W},[j,r,C]),O=W=>{g(re=>({...re,[W]:!re[W]}))},D=W=>{yl(W,{table:W,dataSourceId:n},!0),Yi(void 0),G1(),o!==Ue.workbench.path&&i(Ue.workbench.path)},Y=()=>{d.mutate(n)},H=async()=>{const W=await Pl("Enter name",l==null?void 0:l.name);W&&u.mutate({id:n,dataSource:{name:W}})},$=async()=>{await w1("Are you sure you want to delete this data source?")&&(m.mutate(n),Yi(void 0))},I=C==="column";return h.jsxs("div",{className:Ra.root,children:[h.jsxs("h3",{className:"page-head flex gap-2",children:[l&&h.jsx(ah,{size:32,type:l.dbType}),h.jsx("span",{className:"truncate",children:l==null?void 0:l.name})]}),h.jsx("p",{className:"mt-1 text-sm font-semibold",children:y}),A&&h.jsxs("div",{className:"mt-2 flex gap-2",children:[h.jsx("button",{disabled:d.isLoading,onClick:Y,className:"button tertiary flex items-center gap-1",children:"Refresh schema"}),h.jsx("button",{disabled:d.isLoading,onClick:H,className:"button tertiary",children:"Rename"}),h.jsx("button",{disabled:d.isLoading,onClick:$,className:"button tertiary",children:"Delete"})]}),h.jsxs("div",{className:"flex gap-1 items-center mb-2 mt-4",children:[h.jsx("input",{className:"input flex-1 bg-gray-50",placeholder:I?"Search column":"Search table",value:S,onChange:W=>E(W.target.value),autoFocus:!0}),h.jsx("button",{className:"button primary w-20",onClick:()=>w(I?"table":"column"),children:I?"Column":"Table"})]}),h.jsx("div",{className:"overflow-y-auto",children:_==null?void 0:_.map(W=>h.jsxs("div",{children:[h.jsxs("div",{className:Ra.tableNameContainer,children:[h.jsx("button",{className:se(Ra.chevron,p[W.id]&&Ra.down),onClick:()=>O(W.id),children:h.jsx(ph,{width:16,height:16})}),h.jsx("button",{className:se(Ra.tableName,"flex-1"),onClick:()=>O(W.id),children:W.tableName}),h.jsx("button",{className:Ra.link,onClick:()=>D(W.tableName),children:"↗️"})]}),(p[W.id]||S.length>0)&&h.jsx(Jj,{insp:W,filter:I?j:"",expanded:p[W.id]})]},W.id))})]})}const Ij=()=>{const n=V4(),[l,r]=b.useState(void 0);b.useEffect(()=>{n&&r(n)},[n]);const i=()=>Yi(void 0);return h.jsxs(Yt,{isVisible:n!=null,onClose:i,onClosed:()=>r(void 0),backdropClose:!0,children:[h.jsx(On,{onClick:i}),l&&h.jsx(Pj,{id:l})]})};function Wj(n,l=500){const[r,i]=b.useState(n);return b.useEffect(()=>{const o=setTimeout(()=>i(n),l);return()=>clearTimeout(o)},[n,l]),r}const eN="_search_17rcq_2",tN="_entry_17rcq_2",nN="_ds_17rcq_2",aN="_ds-entry_17rcq_2",Yo={search:eN,entry:tN,ds:nN,dsEntry:aN},[lN,iN]=th({initialData:[],localStorageKey:"selected-data-sources-v1"}),sN=n=>iN(l=>{const r=l.indexOf(n);return r>-1?(l.splice(r,1),[...l]):[...l,n]}),rN={table:"📄",query:"📖"},oN=({onTable:n,onQuery:l,autoFocus:r})=>{const[i,o]=b.useState(""),[u,d]=b.useState(-1),m=Wj(i,200),y=lN(),{data:p}=sa(),{data:g}=Pd({teamId:p==null?void 0:p.teamId}),{data:S}=Q3(m,{teamId:p==null?void 0:p.teamId,selectedDataSources:y}),E=j=>{j.type==="table"?n(j.name,j.dataSourceId):j.type==="query"&&l(j.id,j.dataSourceId)},C=j=>{var _;S&&(j.key==="ArrowDown"?(j.preventDefault(),d(O=>(O+1)%S.length)):j.key==="ArrowUp"?(j.preventDefault(),d(O=>(O-1+S.length)%S.length)):j.key==="Enter"&&u>=0&&(_=S[u])!=null&&_.name&&(j.preventDefault(),E(S[u])))},w=j=>{const _=j.currentTarget.dataset.tableId,O=S==null?void 0:S.find(D=>D.id===_);O&&E(O)},A=b.useMemo(()=>Ej(y),[y]);return h.jsxs("div",{className:"overflow-hidden flex flex-col w-full lg:w-lg",children:[pl(g==null?void 0:g.length,0)&&h.jsx("div",{className:"flex overflow-x-auto mb-2 gap-2 no-scrollbar",children:g.map(j=>h.jsxs("label",{className:Yo.dsEntry,children:[h.jsx("input",{type:"checkbox",checked:A[j.id]===!0,onChange:()=>sN(j.id)}),h.jsx("span",{children:j.name})]},j.id))}),h.jsx("input",{className:Yo.search,placeholder:"Search table or saved query to start from",value:i,onChange:j=>o(j.target.value),onKeyDown:C,autoFocus:r}),pl(S==null?void 0:S.length,0)&&h.jsx("div",{className:"overflow-y-auto max-h-full mt-2",children:S.map((j,_)=>h.jsxs("button",{className:Yo.entry,"data-is-active":u===_,"data-table-id":j.id,onClick:w,children:[h.jsxs("p",{className:"font-semibold",children:[rN[j.type]," ",j.name]}),h.jsxs("p",{className:Yo.ds,children:["📦 ",j.dataSourceName]})]},j.id))})]})},uN=()=>{const n=S4(),l=(o,u)=>{n==null||n.onConfirm("table",o,u)},r=(o,u)=>{n==null||n.onConfirm("query",o,u)},i=()=>{n==null||n.onCancel()};return h.jsxs(Yt,{isVisible:!!n,onClose:i,children:[h.jsx(On,{onClick:i}),h.jsx(oN,{autoFocus:!0,onTable:l,onQuery:r})]})},cN=()=>{const n=jt();b.useEffect(()=>{},[n.pathname])},[fN,F1]=It(!1),fd=()=>F1(!1),$1=()=>F1(!0),dN=({repeatPassword:n,password:l})=>l.length<1?null:l.length<8?h.jsx(Lt,{variant:"warning",children:"New password should be at least 8 characters long"}):l!==n?h.jsx(Lt,{variant:"warning",children:"Repeat password should match new password"}):null,hN=()=>{const n=fN(),{data:l}=sa(),{mutateAsync:r,isLoading:i}=X3(),o=Pt(),[{password:u,repeatPassword:d},{change:m,touched:y,reset:p}]=wr({password:"",repeatPassword:""}),g=()=>{o("/"),br.logout().then(()=>{fd()})},S=()=>{r({password:u}).then(()=>{p(),qt.success("Password successfully updated!")})},E=u.length<8||u!==d||i,C=y.includes("password");return h.jsxs(Yt,{isVisible:n,onClose:fd,children:[h.jsx(On,{onClick:fd}),h.jsxs("div",{className:"w-full lg:w-lg flex flex-col gap-2",children:[h.jsx(S1,{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==null?void 0: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:u,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(dN,{password:u,repeatPassword:d}),h.jsxs("div",{className:"flex justify-end gap-2 mt-2",children:[h.jsx("button",{className:"button tertiary",disabled:E,onClick:S,children:"Update password"}),h.jsx("button",{className:"button danger",onClick:g,children:"Log out"})]})]})]})},[mN,X1]=It(!1),Z1=()=>X1(!0),cv=()=>X1(!1),pN=n=>fn({queryKey:["team-users"],queryFn:async()=>{const{data:l}=await Ve.get("/teams/"+n+"/users");return l.data},enabled:!!n}),yN=()=>cn({mutationFn:async({role:n,teamId:l,userId:r})=>(await Ve.patch("/teams/"+l+"/user-role",{role:n,userId:r}),!0),onSuccess:()=>{pt.invalidateQueries({queryKey:["team-users"]})}}),vN=()=>cn({mutationFn:async({teamId:n,userId:l})=>(await Ve.delete("/teams/"+n,{params:{userId:l}}),!0),onSuccess:()=>{pt.invalidateQueries({queryKey:["team-users"]})}}),gN="_user-entry_1v0j4_2",bN={userEntry:gN},xN=()=>{const n=mN(),{data:l}=sa(),{data:r}=pN(l==null?void 0:l.teamId),{mutate:i,isLoading:o}=Z3(),{mutate:u,isLoading:d}=yN(),{mutate:m,isLoading:y}=vN(),[p,{change:g,reset:S}]=wr({password:"",username:""}),E=()=>{i({username:p.username,password:p.password,teamId:(l==null?void 0:l.teamId)||""}),S()},C=(_,O)=>{u({teamId:l.teamId,role:O,userId:_})},w=_=>{w1("Are you sure you want to remove this user?").then(O=>{O&&m({userId:_,teamId:l.teamId})})},A=Sr(Xt.ADMIN),j=o||d||y;return h.jsxs(Yt,{isVisible:n,onClose:cv,backdropClose:!0,children:[h.jsx(On,{onClick:cv}),h.jsxs("div",{className:"w-full lg:w-lg flex flex-col overflow-hidden",children:[h.jsx(S1,{children:"Manage users"}),pl(r==null?void 0:r.length,0)&&h.jsx("div",{className:"mt-4 overflow-y-auto flex-1",children:r.map(_=>h.jsxs("div",{className:bN.userEntry,children:[h.jsxs("select",{className:"input",value:_.role,disabled:!A||j,onChange:O=>C(_.id,O.currentTarget.value),children:[h.jsx("option",{value:Xt.OWNER,children:"Owner"}),h.jsx("option",{value:Xt.ADMIN,children:"Admin"}),h.jsx("option",{value:Xt.EDITOR,children:"Editor"}),h.jsx("option",{value:Xt.READ_ONLY,children:"Reader"})]}),h.jsx("p",{className:"flex-1 mx-2",children:_.name}),A&&h.jsx("button",{className:"p-1 cursor-pointer text-red-500 text-sm",onClick:()=>w(_.id),children:"❌"})]},_.id))}),A&&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:g("username"),value:p.username,placeholder:"Username",disabled:j}),h.jsx("input",{className:"input",onChange:g("password"),value:p.password,type:"password",name:"newPassword",autoComplete:"new-password",placeholder:"Password",disabled:j}),h.jsx("button",{className:"button primary",onClick:E,disabled:j,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."})]})]})]})},SN=()=>{const[n,l]=b.useState(""),[r,i]=b.useState(""),[o,u]=b.useState(),[d,m]=b.useState(!1),y=Pt(),p=g=>{g.preventDefault(),u(void 0),br.login({password:r,username:n}).then(()=>{y("/",{replace:!0})}).catch(u)};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:p,children:[h.jsx("p",{className:"font-semibold text-xl min-w-md",children:"Login"}),o&&h.jsx(Lt,{variant:"danger",children:"Failed to login. Please verify your credentials"}),h.jsx("input",{value:n,onChange:g=>l(g.currentTarget.value),className:"input",placeholder:"User name"}),h.jsx("input",{value:r,onChange:g=>i(g.currentTarget.value),className:"input",type:"password",placeholder:"Password"}),h.jsx("button",{type:"submit",className:"button primary",children:"Login"}),d?h.jsxs(Lt,{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?"})]})})})},wN=()=>{const n=Pt(),{pathname:l}=jt(),{data:r,isLoading:i}=v1();b.useEffect(()=>{!r&&!i&&l!==Ue.login.path&&n(Ue.login.path)},[r,i,n,l])},EN=()=>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..."})]}),CN=()=>{const[n]=M2(),l=Pt(),{data:r,isLoading:i,isError:o}=F_(n.get("shareId"));return b.useEffect(()=>{var u;r&&(yl(r.name,{...r.opts,dataSourceId:(u=r.dataSource)==null?void 0:u.id},!0),l(Ue.workbench.path,{replace:!0}))},[r]),h.jsxs("div",{className:"page-container flex items-center justify-center h-screen",children:[i&&h.jsxs("div",{className:"flex items-center flex-col gap-2",children:[h.jsx(EN,{}),h.jsx("p",{children:"Fetching query information"})]}),o&&h.jsx(Lt,{variant:"danger",children:"Failed to load query information"})]})};function _N(){return L_(),cN(),wN(),h.jsxs(h.Fragment,{children:[h.jsxs(a2,{children:[h.jsx(sr,{path:Ue.home.path,element:h.jsx(Z4,{})}),h.jsx(sr,{path:Ue.workbench.path,element:h.jsx(zj,{})}),h.jsx(sr,{path:Ue.login.path,element:h.jsx(SN,{})}),h.jsx(sr,{path:Ue.share.path,element:h.jsx(CN,{})})]}),h.jsx(Bj,{}),h.jsx(uE,{}),h.jsx(bE,{}),h.jsx(DE,{}),h.jsx(Ij,{}),h.jsx(uN,{}),h.jsx(hN,{}),h.jsx(xN,{}),h.jsx(NE,{}),h.jsx(wE,{})]})}const jN="_desktop-layout_iepur_2",NN="_mobile-layout_iepur_2",AN="_nav_iepur_2",TN="_main_iepur_2",RN="_header_iepur_2",Gi={desktopLayout:jN,mobileLayout:NN,nav:AN,main:TN,header:RN},ON="_container_1i181_2",DN="_menu_1i181_2",pu={container:ON,menu:DN},MN=({name:n,id:l,onRename:r,onDelete:i,onOpen:o})=>{const u=q1();return h.jsxs("button",{className:pu.menu,onContextMenu:u.open,onClick:()=>o(l),children:[h.jsx(z1,{handler:u,children:h.jsxs("div",{className:"context-menu-container",children:[h.jsx("button",{onClick:d=>{d.preventDefault(),d.stopPropagation(),u.close(),r(l)},className:"context-menu-item",children:"✏️ Rename"}),h.jsx("button",{onClick:d=>{d.preventDefault(),d.stopPropagation(),u.close(),i(l)},className:"context-menu-item",children:"🗑️ Delete"})]})}),h.jsxs("span",{children:["📖 ",n]})]})},UN=({dataSource:n,index:l})=>{const r=()=>{Yi(n.id)};return Tn(l.toString(),()=>{Yi(i=>{if(i!==n.id)return n.id})},n.name),h.jsxs("button",{className:pu.menu,onClick:r,children:[h.jsx(ah,{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})]})},LN=()=>{const n=Pt(),l=jt(),{data:r}=sa(),{data:i}=B3(r==null?void 0:r.teamId),{data:o}=H3(r==null?void 0:r.teamId),u=Au(),d=Z_(),m=X_(),y=E=>{x1(E).then(C=>{var w;yl(C.name,fr({...C.opts,dataSourceId:(w=C.dataSource)==null?void 0:w.id}),!0),l.pathname!==Ue.workbench.path&&n(Ue.workbench.path)})},p=async E=>{const C=o==null?void 0:o.find(A=>A.id===E),w=await Pl("New name?",C==null?void 0:C.name);w&&d.mutate({id:E,payload:{name:w}})},g=E=>{var w;const C=(w=o==null?void 0:o.find(A=>A.id===E))==null?void 0:w.savedQueryId;C&&m.mutate(C)},S=E=>{nh(E),l.pathname!==Ue.workbench.path&&n(Ue.workbench.path)};return h.jsx("div",{className:pu.container,children:h.jsxs("div",{className:"flex-1 overflow-y-auto",children:[pl(i==null?void 0: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((E,C)=>h.jsx(UN,{dataSource:E,index:C+1},E.id))]}),pl(o==null?void 0:o.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"}),o.map(E=>h.jsx(MN,{onDelete:g,onRename:p,onOpen:y,name:E.name,id:E.id},E.savedQueryId))]}),pl(u==null?void 0:u.length,0)&&h.jsxs("div",{className:"mt-4",children:[h.jsx("p",{className:"font-semibold text-sm text-gray-600 mb-2",children:"WORKBENCH TABS"}),u==null?void 0:u.map(E=>h.jsx("button",{className:pu.menu,onClick:()=>S(E.id),children:h.jsxs("span",{children:["📄 ",E.label]})},E.id))]})]})})},qN=()=>{const n=Pt(),{pathname:l}=jt(),{data:r}=sa(),i=()=>{G1(),l!==Ue.home.path&&n(Ue.home.path)};return h.jsxs("nav",{className:Gi.nav,children:[r&&h.jsxs("div",{className:Gi.header,children:[h.jsx("button",{onClick:i,children:"🏠 Home"}),h.jsxs("button",{onClick:$1,children:["🪪 ",r.username]}),h.jsx("button",{onClick:Z1,children:"👥 Manage users"})]}),h.jsx(LN,{})]})},zN="_root_18apu_2",BN={root:zN},HN=()=>{const{pathname:n}=jt(),l=Pt(),r=xr("Mobile home workbench"),i=Au(),o=()=>{n!==Ue.home.path&&l(Ue.home.path)},u=()=>{i.length<1?r():n!==Ue.workbench.path&&l(Ue.workbench.path)};return h.jsxs("div",{className:BN.root,children:[h.jsxs("button",{onClick:o,children:[h.jsx("p",{children:"🏠"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Home"})]}),h.jsxs("button",{onClick:u,children:[h.jsx("p",{children:"🛠️"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Workbench"})]}),h.jsxs("button",{onClick:$1,children:[h.jsx("p",{children:"🪪"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Account"})]}),h.jsxs("button",{onClick:Z1,children:[h.jsx("p",{children:"👥"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Users"})]})]})},kN=({children:n,isLogin:l})=>h.jsxs("div",{className:Gi.desktopLayout,children:[h.jsx(hh,{id:"default",className:"z-100"}),!l&&h.jsx(qN,{}),h.jsx("main",{className:Gi.main,children:n})]}),QN=({children:n,isLogin:l})=>h.jsxs("div",{className:Gi.mobileLayout,children:[h.jsx("main",{className:Gi.main,children:n}),!l&&h.jsx(HN,{})]}),YN=({children:n})=>{const l=mh(Lu.laptop),{pathname:r}=jt(),i=r===Ue.login.path;return l?h.jsx(kN,{isLogin:i,children:n}):h.jsx(QN,{isLogin:i,children:n})};fx.createRoot(document.getElementById("root")).render(h.jsxs(Ge.StrictMode,{children:[h.jsx(L3,{}),h.jsx(uS,{client:pt,children:h.jsx(A2,{children:h.jsx(YN,{children:h.jsx(_N,{})})})})]}));
|