@dataramen/cli 0.0.51-beta.3 → 0.0.51

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.
@@ -234,4 +234,4 @@ to {
234
234
  Licensed under the MIT License (MIT), see
235
235
  http://jedwatson.github.io/classnames
236
236
  */var Qy;function EC(){return Qy||(Qy=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,s(m)))}return u}function s(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})()}(id)),id.exports}var CC=EC();const Dd=pu(CC);var Yy={};const _C="react-tooltip-core-styles",NC="react-tooltip-base-styles",Vy={core:!1,base:!1};function Ky({css:n,id:l=NC,type:r="base",ref:s}){var o,u;if(!n||typeof document>"u"||Vy[r]||r==="core"&&typeof process<"u"&&(!((o=process==null?void 0:Yy)===null||o===void 0)&&o.REACT_TOOLTIP_DISABLE_CORE_STYLES)||r!=="base"&&typeof process<"u"&&(!((u=process==null?void 0:Yy)===null||u===void 0)&&u.REACT_TOOLTIP_DISABLE_BASE_STYLES))return;r==="core"&&(l=_C),s||(s={});const{insertAt:d}=s;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)),Vy[r]=!0}const Gy=async({elementReference:n=null,tooltipReference:l=null,tooltipArrowReference:r=null,place:s="top",offset:o=10,strategy:u="absolute",middlewares:d=[bC(Number(o)),SC({fallbackAxisSideDirection:"start"}),xC({padding:5})],border:m,arrowSize:y=8})=>{if(!n)return{tooltipStyles:{},tooltipArrowStyles:{},place:s};if(l===null)return{tooltipStyles:{},tooltipArrowStyles:{},place:s};const p=d;return r?(p.push(wC({element:r,padding:5})),ky(n,l,{placement:s,strategy:u,middleware:p}).then(({x:g,y:S,placement:w,middlewareData:C})=>{var E,A;const j={left:`${g}px`,top:`${S}px`,border:m},{x:_,y:R}=(E=C.arrow)!==null&&E!==void 0?E:{x:0,y:0},D=(A={top:"bottom",right:"left",bottom:"top",left:"right"}[w.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:R!=null?`${R}px`:"",right:"",bottom:"",...Y,[D]:`-${y/2+H}px`},place:w}})):ky(n,l,{placement:"bottom",strategy:u,middleware:p}).then(({x:g,y:S,placement:w})=>({tooltipStyles:{left:`${g}px`,top:`${S}px`},tooltipArrowStyles:{},place:w}))},Fy=(n,l)=>!("CSS"in window&&"supports"in window.CSS)||window.CSS.supports(n,l),$y=(n,l,r)=>{let s=null;const o=function(...u){const d=()=>{s=null};!s&&(n.apply(this,u),s=setTimeout(d,l))};return o.cancel=()=>{s&&(clearTimeout(s),s=null)},o},Xy=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(!Xy(n)||!Xy(l))return n===l;const r=Object.keys(n),s=Object.keys(l);return r.length===s.length&&r.every(o=>Md(n[o],l[o]))},jC=n=>{if(!(n instanceof HTMLElement||n instanceof SVGElement))return!1;const l=getComputedStyle(n);return["overflow","overflow-x","overflow-y"].some(r=>{const s=l.getPropertyValue(r);return s==="auto"||s==="scroll"})},Zy=n=>{if(!n)return null;let l=n.parentElement;for(;l;){if(jC(l))return l;l=l.parentElement}return document.scrollingElement||document.documentElement},AC=typeof window<"u"?b.useLayoutEffect:b.useEffect,Tn=n=>{n.current&&(clearTimeout(n.current),n.current=null)},TC="DEFAULT_TOOLTIP_ID",RC={anchorRefs:new Set,activeAnchor:{current:null},attach:()=>{},detach:()=>{},setActiveAnchor:()=>{}},OC=b.createContext({getTooltipData:()=>RC});function z1(n=TC){return b.useContext(OC).getTooltipData(n)}var Bs={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 DC=({forwardRef:n,id:l,className:r,classNameArrow:s,variant:o="dark",anchorId:u,anchorSelect:d,place:m="top",offset:y=10,events:p=["hover"],openOnClick:g=!1,positionStrategy:S="absolute",middlewares:w,wrapper:C,delayShow:E=0,delayHide:A=0,float:j=!1,hidden:_=!1,noArrow:R=!1,clickable:D=!1,closeOnEsc:Y=!1,closeOnScroll:H=!1,closeOnResize:$=!1,openEvents:W,closeEvents:I,globalCloseEvents:re,imperativeModeOnly:pe,style:qe,position:Ee,afterShow:Ge,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),jt=b.useRef(null),hn=b.useRef(null),ua=b.useRef(null),[mn,ai]=b.useState({tooltipStyles:{},tooltipArrowStyles:{},place:m}),[qt,Bt]=b.useState(!1),[ca,Kn]=b.useState(!1),[Fe,Gn]=b.useState(null),gl=b.useRef(!1),za=b.useRef(null),{anchorRefs:bl,setActiveAnchor:Il}=z1(l),pn=b.useRef(!1),[tt,Yt]=b.useState([]),st=b.useRef(!1),qa=g||p.includes("click"),li=qa||(W==null?void 0:W.click)||(W==null?void 0:W.dblclick)||(W==null?void 0:W.mousedown),Ba=W?{...W}:{mouseover:!0,focus:!0,mouseenter:!1,click:!1,dblclick:!1,mousedown:!1};!W&&qa&&Object.assign(Ba,{mouseenter:!1,focus:!1,mouseover:!1,click:!0});const yn=I?{...I}:{mouseout:!0,blur:!0,mouseleave:!1,click:!1,dblclick:!1,mouseup:!1};!I&&qa&&Object.assign(yn,{mouseleave:!1,blur:!1,mouseout:!1});const At=re?{...re}:{escape:Y||!1,scroll:H||!1,resize:$||!1,clickOutsideAnchor:li||!1};pe&&(Object.assign(Ba,{mouseover:!1,focus:!1,mouseenter:!1,click:!1,dblclick:!1,mousedown:!1}),Object.assign(yn,{mouseout:!1,blur:!1,mouseleave:!1,click:!1,dblclick:!1,mouseup:!1}),Object.assign(At,{escape:!1,scroll:!1,resize:!1,clickOutsideAnchor:!1})),AC(()=>(st.current=!0,()=>{st.current=!1}),[]);const Be=X=>{st.current&&(X&&Kn(!0),setTimeout(()=>{st.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(qt!==gl.current)if(Tn(ua),gl.current=qt,qt)Ge==null||Ge();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)}},[qt]);const fa=X=>{ai(te=>Md(te,X)?te:X)},On=(X=E)=>{Tn(jt),ca?Be(!0):jt.current=setTimeout(()=>{Be(!0)},X)},Ha=(X=A)=>{Tn(hn),hn.current=setTimeout(()=>{pn.current||Be(!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});E?On():Be(!0),P(de),Il({current:de}),Tn(hn)},da=()=>{D?Ha(A||100):A?Ha():Be(!1),Tn(jt)},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})};Gy({place:(de=Fe==null?void 0:Fe.place)!==null&&de!==void 0?de:m,offset:y,elementReference:We,tooltipReference:Ze.current,tooltipArrowReference:Vn.current,strategy:S,middlewares:w,border:J,arrowSize:ce}).then(vt=>{fa(vt)})},vn=X=>{if(!X)return;const te=X,de={x:te.clientX,y:te.clientY};Fn(de),za.current=de},xl=X=>{var te;if(!qt)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))||(Be(!1),Tn(jt)))},Sl=$y(ka,50),it=$y(da,50),Tt=X=>{it.cancel(),Sl(X)},oe=()=>{Sl.cancel(),it()},_e=b.useCallback(()=>{var X,te;const de=(X=Fe==null?void 0:Fe.position)!==null&&X!==void 0?X:Ee;de?Fn(de):j?za.current&&Fn(za.current):Q!=null&&Q.isConnected&&Gy({place:(te=Fe==null?void 0:Fe.place)!==null&&te!==void 0?te:m,offset:y,elementReference:Q,tooltipReference:Ze.current,tooltipArrowReference:Vn.current,strategy:S,middlewares:w,border:J,arrowSize:ce}).then(We=>{st.current&&fa(We)})},[qt,Q,B,qe,m,Fe==null?void 0:Fe.place,y,S,Ee,Fe==null?void 0:Fe.position,j,ce]);b.useEffect(()=>{var X,te;const de=new Set(bl);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=()=>{Be(!1)},gn=Zy(Q),Wt=Zy(Ze.current);At.scroll&&(window.addEventListener("scroll",vt),gn==null||gn.addEventListener("scroll",vt),Wt==null||Wt.addEventListener("scroll",vt));let rt=null;At.resize?window.addEventListener("resize",vt):Q&&Ze.current&&(rt=gC(Q,Ze.current,_e,{ancestorResize:!0,elementResize:!0,layoutShift:!0}));const Ot=Oe=>{Oe.key==="Escape"&&Be(!1)};At.escape&&window.addEventListener("keydown",Ot),At.clickOutsideAnchor&&window.addEventListener("click",xl);const Re=[],en=Oe=>!!(Oe!=null&&Oe.target&&(Q!=null&&Q.contains(Oe.target))),wl=Oe=>{qt&&en(Oe)||ka(Oe)},Qa=Oe=>{qt&&en(Oe)&&da()},ot=["mouseover","mouseout","mouseenter","mouseleave","focus","blur"],si=["click","dblclick","mousedown","mouseup"];Object.entries(Ba).forEach(([Oe,bn])=>{bn&&(ot.includes(Oe)?Re.push({event:Oe,listener:Tt}):si.includes(Oe)&&Re.push({event:Oe,listener:wl}))}),Object.entries(yn).forEach(([Oe,bn])=>{bn&&(ot.includes(Oe)?Re.push({event:Oe,listener:oe}):si.includes(Oe)&&Re.push({event:Oe,listener:Qa}))}),j&&Re.push({event:"pointermove",listener:vn});const ii=()=>{pn.current=!0},$n=()=>{pn.current=!1,da()},ha=D&&(yn.mouseout||yn.mouseleave);return ha&&((X=Ze.current)===null||X===void 0||X.addEventListener("mouseover",ii),(te=Ze.current)===null||te===void 0||te.addEventListener("mouseout",$n)),Re.forEach(({event:Oe,listener:bn})=>{de.forEach(Wl=>{var El;(El=Wl.current)===null||El===void 0||El.addEventListener(Oe,bn)})}),()=>{var Oe,bn;At.scroll&&(window.removeEventListener("scroll",vt),gn==null||gn.removeEventListener("scroll",vt),Wt==null||Wt.removeEventListener("scroll",vt)),At.resize?window.removeEventListener("resize",vt):rt==null||rt(),At.clickOutsideAnchor&&window.removeEventListener("click",xl),At.escape&&window.removeEventListener("keydown",Ot),ha&&((Oe=Ze.current)===null||Oe===void 0||Oe.removeEventListener("mouseover",ii),(bn=Ze.current)===null||bn===void 0||bn.removeEventListener("mouseout",$n)),Re.forEach(({event:Wl,listener:El})=>{de.forEach(es=>{var Ya;(Ya=es.current)===null||Ya===void 0||Ya.removeEventListener(Wl,El)})})}},[Q,_e,ca,bl,tt,W,I,re,qa,E,A]),b.useEffect(()=>{var X,te;let de=(te=(X=Fe==null?void 0:Fe.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 gn=[],Wt=[];vt.forEach(rt=>{if(rt.type==="attributes"&&rt.attributeName==="data-tooltip-id"&&(rt.target.getAttribute("data-tooltip-id")===l?gn.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),Be(!1),P(null),Tn(jt),Tn(hn),!0)})}if(de)try{const Ot=[...rt.addedNodes].filter(Re=>Re.nodeType===1);gn.push(...Ot.filter(Re=>Re.matches(de))),gn.push(...Ot.flatMap(Re=>[...Re.querySelectorAll(de)]))}catch{}}}),(gn.length||Wt.length)&&Yt(rt=>[...rt.filter(Ot=>!Wt.includes(Ot)),...gn])});return We.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-tooltip-id"],attributeOldValue:!0}),()=>{We.disconnect()}},[l,d,Fe==null?void 0:Fe.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&&Be(!0),()=>{Tn(jt),Tn(hn)}),[]),b.useEffect(()=>{var X;let te=(X=Fe==null?void 0:Fe.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));Yt(de)}catch{Yt([])}},[l,d,Fe==null?void 0:Fe.anchorSelect]),b.useEffect(()=>{jt.current&&(Tn(jt),On(E))},[E]);const Ht=(Me=Fe==null?void 0:Fe.content)!==null&&Me!==void 0?Me:B,Rt=qt&&Object.keys(mn.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?On(X.delay):Be(!0)},close:X=>{X!=null&&X.delay?Ha(X.delay):Be(!1)},activeAnchor:Q,place:mn.place,isOpen:!!(ca&&!_&&Ht&&Rt)})),ca&&!_&&Ht?Ke.createElement(C,{id:l,role:St,className:Dd("react-tooltip",Bs.tooltip,rd.tooltip,rd[o],r,`react-tooltip__place-${mn.place}`,Bs[Rt?"show":"closing"],Rt?"react-tooltip__show":"react-tooltip__closing",S==="fixed"&&Bs.fixed,D&&Bs.clickable),onTransitionEnd:X=>{Tn(ua),qt||X.propertyName!=="opacity"||(Kn(!1),Gn(null),ye==null||ye())},style:{...qe,...mn.tooltipStyles,opacity:le!==void 0&&Rt?le:void 0},ref:Ze},Ht,Ke.createElement(C,{className:Dd("react-tooltip-arrow",Bs.arrow,rd.arrow,s,R&&Bs.noArrow),style:{...mn.tooltipArrowStyles,background:Ce?`linear-gradient(to right bottom, transparent 50%, ${Ce} 50%)`:void 0,"--rt-arrow-size":`${ce}px`},ref:Vn})):null},MC=({content:n})=>Ke.createElement("span",{dangerouslySetInnerHTML:{__html:n}}),Mu=Ke.forwardRef(({id:n,anchorId:l,anchorSelect:r,content:s,html:o,render:u,className:d,classNameArrow:m,variant:y="dark",place:p="top",offset:g=10,wrapper:S="div",children:w=null,events:C=["hover"],openOnClick:E=!1,positionStrategy:A="absolute",middlewares:j,delayShow:_=0,delayHide:R=0,float:D=!1,hidden:Y=!1,noArrow:H=!1,clickable:$=!1,closeOnEsc:W=!1,closeOnScroll:I=!1,closeOnResize:re=!1,openEvents:pe,closeEvents:qe,globalCloseEvents:Ee,imperativeModeOnly:Ge=!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(s),[jt,hn]=b.useState(o),[ua,mn]=b.useState(p),[ai,qt]=b.useState(y),[Bt,ca]=b.useState(g),[Kn,Fe]=b.useState(_),[Gn,gl]=b.useState(R),[za,bl]=b.useState(D),[Il,pn]=b.useState(Y),[tt,Yt]=b.useState(S),[st,qa]=b.useState(C),[li,Ba]=b.useState(A),[yn,At]=b.useState(null),[Be,fa]=b.useState(null),On=b.useRef(Z),{anchorRefs:Ha,activeAnchor:ka}=z1(n),da=it=>it==null?void 0:it.getAttributeNames().reduce((Tt,oe)=>{var _e;return oe.startsWith("data-tooltip-")&&(Tt[oe.replace(/^data-tooltip-/,"")]=(_e=it==null?void 0:it.getAttribute(oe))!==null&&_e!==void 0?_e:null),Tt},{}),Fn=it=>{const Tt={place:oe=>{var _e;mn((_e=oe)!==null&&_e!==void 0?_e:p)},content:oe=>{Vn(oe??s)},html:oe=>{hn(oe??o)},variant:oe=>{var _e;qt((_e=oe)!==null&&_e!==void 0?_e:y)},offset:oe=>{ca(oe===null?g:Number(oe))},wrapper:oe=>{var _e;Yt((_e=oe)!==null&&_e!==void 0?_e:S)},events:oe=>{const _e=oe==null?void 0:oe.split(" ");qa(_e??C)},"position-strategy":oe=>{var _e;Ba((_e=oe)!==null&&_e!==void 0?_e:A)},"delay-show":oe=>{Fe(oe===null?_:Number(oe))},"delay-hide":oe=>{gl(oe===null?R:Number(oe))},float:oe=>{bl(oe===null?D:oe==="true")},hidden:oe=>{pn(oe===null?Y:oe==="true")},"class-name":oe=>{At(oe)}};Object.values(Tt).forEach(oe=>oe(null)),Object.entries(it).forEach(([oe,_e])=>{var Ht;(Ht=Tt[oe])===null||Ht===void 0||Ht.call(Tt,_e)})};b.useEffect(()=>{Vn(s)},[s]),b.useEffect(()=>{hn(o)},[o]),b.useEffect(()=>{mn(p)},[p]),b.useEffect(()=>{qt(y)},[y]),b.useEffect(()=>{ca(g)},[g]),b.useEffect(()=>{Fe(_)},[_]),b.useEffect(()=>{gl(R)},[R]),b.useEffect(()=>{bl(D)},[D]),b.useEffect(()=>{pn(Y)},[Y]),b.useEffect(()=>{Ba(A)},[A]),b.useEffect(()=>{On.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 it;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=(it=Be??_e)!==null&&it!==void 0?it: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,Be,l,r]),b.useEffect(()=>{ye!=null&&ye.border&&console.warn("[react-tooltip] Do not set `style.border`. Use `border` prop instead."),ue&&!Fy("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&&!Fy("opacity",`${T}`)&&console.warn(`[react-tooltip] "${T}" is not a valid \`opacity\`.`)},[]);let vn=w;const xl=b.useRef(null);if(u){const it=u({content:(Be==null?void 0:Be.getAttribute("data-tooltip-content"))||Ze||null,activeAnchor:Be});vn=it?Ke.createElement("div",{ref:xl,className:"react-tooltip-content-wrapper"},it):null}else Ze&&(vn=Ze);jt&&(vn=Ke.createElement(MC,{content:jt}));const Sl={forwardRef:Me,id:n,anchorId:l,anchorSelect:r,className:Dd(d,yn),classNameArrow:m,content:vn,contentWrapperRef:xl,place:ua,variant:ai,offset:Bt,wrapper:tt,events:st,openOnClick:E,positionStrategy:li,middlewares:j,delayShow:Kn,delayHide:Gn,float:za,hidden:Il,noArrow:H,clickable:$,closeOnEsc:W,closeOnScroll:I,closeOnResize:re,openEvents:pe,closeEvents:qe,globalCloseEvents:Ee,imperativeModeOnly:Ge,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:Be,setActiveAnchor:it=>fa(it),role:St};return Ke.createElement(DC,{...Sl})});typeof window<"u"&&window.addEventListener("react-tooltip-inject-styles",n=>{n.detail.disableCore||Ky({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||Ky({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 UC=n=>{if(!n)return;const l=yt.getQueryData([Jd]);if(!l)return;const r=yt.getQueryData([La,l.teamId]);return r==null?void 0:r.find(s=>s.id===n)},Jy=n=>window.matchMedia(n).matches;function dh(n,{defaultValue:l=!1,initializeWithValue:r=!0}={}){const[s,o]=b.useState(()=>r?Jy(n):l);return b.useLayoutEffect(()=>{const u=window.matchMedia(n);function d(){o(()=>Jy(n))}return d(),u.addListener?u.addListener(d):u.addEventListener("change",d),()=>{u.removeListener?u.removeListener(d):u.removeEventListener("change",d)}},[n]),s}const Uu={laptop:"(min-width: 1024px)"},LC=()=>window.matchMedia(Uu.laptop).matches,zC="_table_1yv46_2",qC="_semi-transparent_1yv46_2",BC="_table-loading_1yv46_2",HC="_table-empty_1yv46_2",kC="_table-row-cells_1yv46_2",QC="_header-cell_1yv46_2",YC="_header-actions_1yv46_2",VC="_cell_1yv46_2",KC="_cell-actions_1yv46_2",GC="_table-config_1yv46_2",FC="_table-action_1yv46_2",$C="_blue_1yv46_2",XC="_red_1yv46_2",ZC="_modal_1yv46_2",JC="_size_1yv46_2",PC="_options-container_1yv46_2",IC="_underlying-rows-btn_1yv46_2",WC="_option-item_1yv46_2",ne={table:zC,semiTransparent:qC,tableLoading:BC,tableEmpty:HC,tableRowCells:kC,headerCell:QC,headerActions:YC,cell:VC,cellActions:KC,tableConfig:GC,tableAction:FC,blue:$C,red:XC,modal:ZC,size:JC,optionsContainer:PC,underlyingRowsBtn:IC,optionItem:WC},oa=b.createContext({name:"No name",hooks:[],availableJoins:[],allColumns:[],dataSourceId:"",entities:[],getValue:()=>{},getColumnType:()=>{},getEntityKey:()=>[]}),ht=b.createContext({state:fr({}),setState:()=>{}}),Yn=b.createContext({}),q1=()=>{const[n,l]=b.useState();return b.useMemo(()=>({show:!!n,position:n,open:s=>{s.preventDefault(),l({x:s.clientX-1,y:s.clientY-1})},close:()=>{l(void 0)}}),[n])},e_=n=>{if(n==="ASC")return"DESC";if(n!=="DESC")return"ASC"},t_=()=>{const{state:n,setState:l}=b.useContext(ht),r=b.useCallback(s=>{l(o=>{const u=o.orderBy[0];if(u&&u.column===s){const d=e_(u.direction);return d?{...o,orderBy:[{column:s,direction:d}]}:{...o,orderBy:[]}}return{...o,orderBy:[{column:s,direction:"ASC"}]}})},[l]);return{orderBy:n.orderBy,updateOrderBy:r}};function n_(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 s=(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:s,column:o}}const a_=()=>{const{data:n}=b.useContext(Yn),{getColumnType:l}=b.useContext(oa),{setState:r}=b.useContext(ht),s=m=>{const{value:y,column:p}=od(n,m.row,m.col);if(p){const g=Kl(y,l(p.full));navigator.clipboard.writeText(g),zt.success("Copied!")}},o=m=>{const{value:y,column:p}=od(n,m.row,m.col);if(p){const g=Kl(y,l(p.full));C1(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)===""){zt.error("Filtering on aggregated column is not supported yet");return}if(g){let w;if(y==null)w={id:Ua(),isEnabled:!0,column:g,connector:"AND",operator:"IS NULL"};else{const C=Kl(y,l(g));w={id:Ua(),isEnabled:!0,column:g,connector:"AND",operator:"=",fn:S,value:[{value:C}]}}r(C=>({...C,filters:[...C.filters,w]})),zt.success(`Added new filter on column ${p==null?void 0:p.alias}`)}};return m=>{const y=n_(m);y&&(y.action==="copy"?s(y):y.action==="show"?o(y):y.action==="filter"&&u(y))}},l_="_container_ld4dc_2",s_="_content_ld4dc_2",i_="_backdrop_ld4dc_2",ud={container:l_,content:s_,backdrop:i_},B1=({children:n,handler:l})=>{const r=b.useRef(l.close);r.current=l.close;const s=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,LC()?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)}},[]),s?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:s,children:n})]}):null},r_="_table_nc86f_2",o_="_root_nc86f_2",u_="_content_nc86f_2",c_="_sub_nc86f_2",ko={table:r_,root:o_,content:u_,sub:c_},H1=({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),Zl=(n,l)=>n!=null&&n>l,f_=({handler:n,rowIndex:l})=>{const{hooks:r,entities:s,dataSourceId:o,getEntityKey:u,getValue:d}=b.useContext(oa),{state:m}=b.useContext(ht),{data:y}=b.useContext(Yn),[p,g]=b.useState(""),[S,w]=b.useState(""),C=b.useMemo(()=>y==null?void 0:y.rows[l],[y,l]),E=()=>{C&&(pl("⬇️ "+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}`});pl(`↗️ ${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?s.filter(Y=>Y.includes(p)):s,[s,p]),R=b.useMemo(()=>{if(!y)return[];const Y=S.toLowerCase();return r.filter(H=>y.columns.some(W=>W.column===H.on.fromColumn&&W.table===H.on.fromTable)?H.on.toTable.toLowerCase().includes(Y):!1)},[S,r,y]),D=m.groupBy.length>0;return h.jsxs(B1,{handler:n,children:[s.length>0&&h.jsxs("div",{className:ne.optionsContainer,children:[h.jsxs("label",{className:"flex items-center gap-2 border-b border-b-gray-200 p-2 bg-(--bg)",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 overflow-y-auto",children:Zl(_.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 p-2 text-gray-800",children:"Empty"})})]}),r.length>0&&h.jsxs("div",{className:ne.optionsContainer,children:[h.jsxs("label",{className:"flex items-center gap-2 border-b border-b-gray-200 p-2 bg-(--bg)",children:[h.jsx("span",{className:"font-semibold",children:"↗️"}),h.jsx("input",{className:"flex-1 outline-0",placeholder:"Connected tables",value:S,onChange:Y=>w(Y.target.value)})]}),h.jsx("div",{className:"flex flex-col overflow-y-auto",children:R.length>0?R.map(Y=>h.jsx(H1,{hook:Y,onClick:()=>A(Y)},Y.where)):h.jsx("p",{className:"text-center p-2 text-gray-800",children:"Empty"})})]}),D&&h.jsx("button",{onClick:E,className:ne.underlyingRowsBtn,children:"🎯 Underlying rows"})]})},d_={ASC:"⬆️",DESC:"⬇️"},h_=()=>{const{data:n}=b.useContext(Yn),{orderBy:l,updateOrderBy:r}=t_(),s=(n==null?void 0:n.columns)||[],o=l[0];return h.jsx("thead",{children:h.jsxs("tr",{children:[h.jsx("td",{className:"p-1 text-center w-8 text-sm text-gray-600",children:"#"}),s.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?d_[o.direction]:"↕️"})})]},u.full))]})})};function m_({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 s=Kl(n);return h.jsxs(h.Fragment,{children:[h.jsx("span",{"data-row":l,className:"truncate block pointer-events-none",children:s}),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 p_=b.memo(({row:n,isLastRow:l,index:r,offset:s})=>h.jsxs("tr",{className:se(ne.tableRowCells,l&&"rounded-b-lg"),children:[h.jsx("td",{className:"p-1 text-center align-middle text-xs w-8 text-blue-500",children:r+1+s}),n.map((o,u)=>h.jsx("td",{className:ne.cell,"data-row":r,children:h.jsx(m_,{value:o,col:u,row:r})},u))]})),y_=()=>{var C,E;const{data:n,error:l,isLoading:r,isFetching:s}=b.useContext(Yn),{state:{page:o,size:u}}=b.useContext(ht),d=lh(l),m=a_(),y=q1(),[p,g]=b.useState(void 0),S=A=>{var R;const j=(R=A.target)==null?void 0:R.dataset,_=j==null?void 0:j.row;_!=null&&(g(parseInt(_)),y.open(A))},w=o*u;return h.jsxs(h.Fragment,{children:[p!=null&&y.show&&h.jsx(f_,{handler:y,rowIndex:p}),d&&h.jsx(Lt,{className:"my-4",variant:"danger",children:d}),r&&h.jsx("div",{className:ne.tableLoading,children:"Loading data"}),n&&h.jsxs("table",{className:se(ne.table,s&&ne.semiTransparent),onContextMenu:S,onClick:m,children:[h.jsx(h_,{}),h.jsxs("tbody",{children:[((C=n.rows)==null?void 0:C.length)<1&&h.jsx("tr",{className:ne.tableEmpty,children:h.jsx("td",{colSpan:n.columns.length+1,children:"No data"})}),(E=n.rows)==null?void 0:E.map((A,j)=>h.jsx(p_,{index:j,offset:w,row:A,isLastRow:j===n.rows.length-1},j))]})]})]})},v_="_root_12ips_2",g_="_root-show_12ips_2",b_="_content-desktop_12ips_2",x_="_content-mobile_12ips_2",S_="_card_12ips_2",w_="_cards-list_12ips_2",E_="_sub-text_12ips_2",C_="_text_12ips_2",__="_section-title_12ips_2",N_="_sidebar-action_12ips_2",j_="_sidebar-add-action_12ips_2",A_="_section-container_12ips_2",T_="_close-button_12ips_2",R_="_section-open-btn_12ips_2",O_="_show_12ips_2",ie={root:v_,rootShow:g_,contentDesktop:b_,contentMobile:x_,card:S_,cardsList:w_,subText:E_,text:C_,sectionTitle:__,sidebarAction:N_,sidebarAddAction:j_,sectionContainer:A_,closeButton:T_,sectionOpenBtn:R_,show:O_};function D_(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 k1=()=>{const{state:n,setState:l}=b.useContext(ht),r=b.useCallback(o=>{l(u=>({...u,filters:o}))},[l]),s=b.useCallback(o=>{l(u=>({...u,filters:u.filters.filter(d=>!(o.column===d.column&&o.operator===d.operator&&D_(o.value,d.value)))}))},[l]);return{filters:n.filters,removeFilter:s,setFilters:r}},M_=(n,l)=>n.type!==l.type||n.on!==l.on||n.table!==l.table,U_=(n,l)=>n.type===l.type&&n.on===l.on&&n.table===l.table,Q1=()=>{const{state:n,setState:l}=b.useContext(ht),r=b.useCallback(s=>{l(o=>{const u=o.joins;if(u.some(m=>U_(m,s))){const m=s.table+".";return{...o,joins:u.filter(y=>M_(y,s)),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,s]}})},[l]);return{joins:n.joins,toggle:r}},Lu=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"})),ks=new Map,L_=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("+")},z_=n=>{var s,o,u;const l=(o=(s=n.target)==null?void 0:s.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=ks.get(L_(n));r&&r.length>0&&r[r.length-1].callback()},q_=(n,l,r="")=>{const s=n.toLowerCase(),o=ks.get(n);return o?ks.set(n,[...o,{callback:l,label:r}]):ks.set(s,[{callback:l,label:r}]),()=>{const u=n.toLowerCase(),d=ks.get(u);d&&ks.set(u,d.filter(m=>m.callback!==l))}};window.addEventListener("keyup",z_);function cn(n,l,r){const s=b.useRef({callback:l,label:r});s.current.callback=l,b.useEffect(()=>q_(n,()=>{s.current.callback()},s.current.label),[n])}const B_=()=>{const n=xr("Hotkey"),l=Jt(),r=Nt(),{data:s}=ia();cn("n",()=>{s&&n()},"📖 New query"),cn("w",()=>{if(!s)return;Au.get().length<1?n():r.pathname!==Xe.workbench.path&&l(Xe.workbench.path)},"🛠️ Open Workbench"),cn("h",()=>{r.pathname!==Xe.home.path&&l(Xe.home.path)},"🏠 Go home")},[H_,k_]=Pt(!1),hh=()=>k_(n=>!n),Q_="_sidebar_4a0zp_2",Y_="_sidebar-visible_4a0zp_2",V_="_sidebar-container_4a0zp_2",K_="_sidebar-invisible_4a0zp_2",G_="_backdrop_4a0zp_2",sr={sidebar:Q_,sidebarVisible:Y_,sidebarContainer:V_,sidebarInvisible:K_,backdrop:G_},Y1=({children:n,backdropClose:l,isVisible:r,onClose:s,onClosed:o,contentClassName:u})=>{const[d,m]=b.useState(!1),y=b.useRef(s);y.current=s;const p=()=>{l&&s()},g=S=>{r||getComputedStyle(S.currentTarget).opacity==="0"&&(m(!1),o&&o())};return b.useEffect(()=>{r&&m(!0)},[r]),b.useEffect(()=>{const S=w=>{r&&w.key==="Escape"&&y.current()};return window.addEventListener("keydown",S),()=>{window.removeEventListener("keydown",S)}},[r]),h.jsxs("div",{onTransitionEnd:g,className:se(sr.sidebar,r?sr.sidebarVisible:sr.sidebarInvisible),children:[h.jsx("div",{onClick:p,className:sr.backdrop}),h.jsx("div",{className:se(sr.sidebarContainer,u),children:d&&n})]})},[zu,mh]=Pt({filters:!1,joins:!1,columns:!1,groupBy:!1,aggregate:!1}),Ln=n=>mh(l=>({...l,[n]:!0})),qu=n=>mh(l=>({...l,[n]:!1})),mu=n=>mh(l=>({...l,[n]:!l[n]})),F_=()=>{const n=H_();return dh(Uu.laptop)?h.jsx("div",{className:se(ie.root,n&&ie.rootShow),children:h.jsxs("div",{className:se(ie.contentDesktop,"no-scrollbar"),children:[h.jsx(Iy,{}),h.jsx(Py,{}),h.jsx(lv,{}),h.jsx(av,{}),h.jsx(nv,{}),h.jsx(ev,{}),h.jsx(tv,{}),h.jsx(Wy,{})]})}):h.jsx(Y1,{isVisible:n,onClose:hh,backdropClose:!0,children:h.jsxs("div",{className:ie.contentMobile,children:[h.jsx(Iy,{}),h.jsx(Py,{}),h.jsx(lv,{}),h.jsx(av,{}),h.jsx(nv,{}),h.jsx(ev,{}),h.jsx(tv,{}),h.jsx(Wy,{})]})})};function Nr({onShow:n,show:l,title:r,items:s}){return h.jsxs("div",{className:"flex justify-between items-center",children:[h.jsx("p",{className:ie.sectionTitle,children:r}),s>0&&h.jsxs("button",{className:se(ie.sectionOpenBtn,l&&ie.show),onClick:n,children:[h.jsx("span",{children:s}),h.jsx(Lu,{width:16,height:16})]})]})}function Py(){const{name:n,tabId:l}=b.useContext(oa),{data:r}=b.useContext(Yn),s=()=>{l&&Pl("New tab name",n).then(u=>{u&&Tu(l,u)})},o=()=>{r!=null&&r.query&&(navigator.clipboard.writeText(r==null?void 0:r.query),zt.success("Query copied to clipboard"))};return cn("r",s,"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:s,children:h.jsx("span",{children:"✏️ Rename tab"})}),h.jsx("button",{className:ie.sidebarAction,onClick:o,children:h.jsx("span",{children:"🖋️ Copy SQL"})})]})}function Iy(){const{state:n}=b.useContext(ht),{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 Wy(){const{state:n,setState:l}=b.useContext(ht),[r,s]=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(Nr,{title:"📚 Group by",show:r,onShow:()=>s(!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(kn,{width:20,height:20})})]},ta(u)))}),h.jsxs("button",{className:ie.sidebarAddAction,onClick:()=>Ln("groupBy"),children:[h.jsx("span",{className:"hotkey",children:"G"}),h.jsx("span",{children:"Add group by"})]})]})}function ev(){const{state:n,setState:l}=b.useContext(ht),[r,s]=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(Nr,{title:"👀 Columns",show:r,onShow:()=>s(!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(kn,{width:20,height:20})})]}))}),!u&&h.jsxs("button",{className:ie.sidebarAddAction,onClick:()=>Ln("columns"),children:[h.jsx("span",{className:"hotkey",children:"C"}),h.jsx("span",{children:"Show/Hide columns"})]})]})}function tv(){const{state:n,setState:l}=b.useContext(ht),[r,s]=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(Nr,{title:"🔢 Aggregations",show:r,onShow:()=>s(!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(kn,{width:20,height:20})})]}))}),h.jsxs("button",{className:ie.sidebarAddAction,onClick:()=>Ln("aggregate"),children:[h.jsx("span",{className:"hotkey",children:"A"}),h.jsx("span",{children:"Aggregate data"})]})]})}const $_=n=>(n==null?void 0:n.map(l=>l.value).join(", "))||"";function nv(){const{state:n}=b.useContext(ht),{removeFilter:l}=k1(),[r,s]=b.useState(!0),o=()=>{Ln("filters")};return h.jsxs("div",{className:ie.sectionContainer,children:[h.jsx(Nr,{title:"🎚️ Filters",show:r,onShow:()=>s(!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]," ",$_(u.value)]})]}),h.jsx("button",{className:ie.closeButton,onClick:()=>l(u),children:h.jsx(kn,{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 av(){const{toggle:n}=Q1(),{availableJoins:l}=b.useContext(oa),{state:r}=b.useContext(ht),[s,o]=b.useState(!0);return h.jsxs("div",{className:ie.sectionContainer,children:[h.jsx(Nr,{title:"📄 Joins",show:s,onShow:()=>o(!s),items:r.joins.length}),s&&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(kn,{width:20,height:20})})]},u.table+u.on))}),l.length>0&&h.jsxs("button",{onClick:()=>Ln("joins"),className:ie.sidebarAddAction,children:[h.jsx("span",{className:"hotkey",children:"J"}),h.jsx("span",{children:"Join table"})]})]})}function lv(){const{state:n,setState:l}=b.useContext(ht);if(!n.orderBy.length)return null;const r=s=>{l(o=>({...o,orderBy:o.orderBy.filter(u=>u.column!==s.column&&u.direction!==s.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((s,o)=>h.jsxs("div",{className:ie.card,children:[h.jsxs("div",{className:"overflow-hidden",children:[h.jsx("p",{className:se(ie.subText,"truncate"),children:s.direction}),h.jsx("p",{className:ie.text,children:s.column})]}),h.jsx("button",{className:ie.closeButton,onClick:()=>r(s),children:h.jsx(kn,{width:20,height:20})})]},o))})]})}const V1=()=>{const{state:n,setState:l}=b.useContext(ht),r=b.useCallback(o=>{l(u=>({...u,page:o}))},[l]),s=b.useCallback(o=>{l(u=>({...u,size:o}))},[l]);return{page:n.page,size:n.size,setSize:s,setPage:r}},X_=n=>dn({queryKey:["query",n],queryFn:async()=>{const{data:l}=await Ye.get("/queries/"+n);return l.data},enabled:!!n}),Z_=()=>fn({mutationFn:async n=>{const{data:l}=await Ye.post("/saved-queries",n);return l.data},onSuccess:()=>{yt.invalidateQueries(["queries"]),Ws()}}),J_=()=>fn({mutationFn:async n=>Ye.delete("/saved-queries/"+n),onSuccess:()=>{Ws()}}),P_=()=>fn({mutationFn:async({id:n,payload:l})=>{const{data:r}=await Ye.patch("/queries/"+n,l);return r.data},onSuccess:n=>{yt.invalidateQueries(["query",n.id]),Ws(),Y3(),n.isTrash}}),[I_,K1]=Pt(void 0),Ud=()=>K1(void 0);function W_(){return h.jsxs("div",{className:"flex items-center bg-white border-b border-gray-200 overflow-auto no-scrollbar",children:[h.jsx(e6,{}),h.jsx(n6,{}),h.jsx(a6,{})]})}function e6(){const{dataSourceId:n,name:l,tabId:r}=b.useContext(oa),{data:s}=Nu(n),{data:o}=b.useContext(Yn),u=Sr($t.EDITOR),d=Z_(),m=()=>{var p,g;(p=o==null?void 0:o.columns)!=null&&p[0].table&&ah({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&&Tu(r,p))};return cn("s",y,"Save query"),h.jsxs("div",{className:ne.tableConfig,children:[h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Manage filters",onClick:()=>Ln("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:()=>Ln("joins"),className:se(ne.tableAction,ne.blue),children:[h.jsx("span",{children:"Join"}),h.jsx("span",{className:"hotkey",children:"J"})]}),h.jsx(l6,{}),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(Lu,{width:16,height:16,className:"rotate-90"})]}),h.jsxs(Mu,{id:"explorer-more-actions",className:"z-10 shadow-md flex flex-col",clickable:!0,variant:"light",opacity:1,children:[h.jsxs("button",{onClick:()=>Ln("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:()=>Ln("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:()=>Ln("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:hh,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"})]}),(s==null?void 0:s.allowInsert)===!0&&h.jsx("button",{onClick:m,className:se(ne.tableAction,ne.modal,ne.blue),children:"Insert new row"})]})]})]})}const t6=[5,10,20,50,100,200];function n6(){const{name:n}=b.useContext(oa),{state:l}=b.useContext(ht),{refetch:r,data:s}=b.useContext(Yn),{size:o,setSize:u}=V1(),d=(window==null?void 0:window.location.hostname)!=="localhost",m=()=>{pl(n,l,!0),Ud()},y=()=>{if(s!=null&&s.queryHistoryId){const p=new URL(window.location.href);p.pathname=Xe.share.path,p.searchParams.set("shareId",s.queryHistoryId),navigator.clipboard.writeText(p.toString()),zt.success("Share link copied to clipboard")}};return cn("e",hh,"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"}),d&&h.jsx("button",{"data-tooltip-id":"default","data-tooltip-content":"Share query",onClick:y,className:se(ne.tableAction,ne.blue),children:"Share"}),h.jsx("button",{"data-tooltip-id":"default","data-tooltip-content":"Clone in a new tab",onClick:m,className:se(ne.tableAction,ne.blue),children:"Clone"}),h.jsxs("button",{"data-tooltip-id":"rows-num",className:se(ne.tableAction,ne.size,ne.blue),children:[h.jsxs("span",{className:"whitespace-nowrap",children:[o," rows"]}),h.jsx(Lu,{width:16,height:16,className:"rotate-90"})]}),h.jsx(Mu,{id:"rows-num",className:"z-10 shadow-md flex",clickable:!0,variant:"light",opacity:1,children:t6.map(p=>h.jsx("button",{onClick:()=>u(p),className:se(ne.tableAction,ne.blue),children:h.jsx("span",{children:p})}))})]})}function a6(){const{page:n,size:l,setPage:r}=V1(),{data:s}=b.useContext(Yn),o=(s==null?void 0:s.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 l6(){const{state:n,setState:l}=b.useContext(ht),r=()=>{l(o=>({...o,searchAll:void 0}))},s=()=>{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 cn("k",s,"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:s,className:se(ne.tableAction,ne.blue),children:[h.jsx("span",{className:"whitespace-nowrap",children:"Search text"}),h.jsx("span",{className:"hotkey",children:"K"})]})}const s6="_drop-container_745yh_2",i6="_item_745yh_2",sv={dropContainer:s6,item:i6},Ld=({dataSourceId:n,focusId:l,placeholder:r="Column",onChange:s,value:o,autoFocus:u,allowTables:d})=>{const{data:m}=ei(n),y=b.useRef(null),p=b.useMemo(()=>{if(!m)return[];let _=m;return d&&(_=m.filter(R=>d.includes(R.tableName))),_.flatMap(R=>R.columns.map(D=>({value:R.tableName+"."+D.name,label:D.name,table:R.tableName,searchValue:D.name.toLowerCase()})))},[m,d]),g=b.useMemo(()=>{const _=o.toLowerCase()||"",R=[];for(let D=0;D<p.length&&R.length<10;D++)p[D].searchValue.includes(_)&&R.push(p[D]);return R},[p,o]),[S,w]=b.useState(!1),[C,E]=b.useState(0),A=_=>{var R;if(_.key==="ArrowDown")_.preventDefault(),E(D=>(D+1)%g.length);else if(_.key==="ArrowUp")_.preventDefault(),E(D=>(D-1+g.length)%g.length);else if(_.key==="Enter"&&C>=0&&C<g.length){_.preventDefault();const D=g[C].value;w(!1);const Y=p.findIndex(H=>H.value===D)>-1;s(((R=g[C])==null?void 0:R.value)||D,Y,!0)}};b.useEffect(()=>{var R;const _=(R=y.current)==null?void 0:R.querySelector('[data-is-active="true"]');_&&_.scrollIntoView({behavior:"smooth",block:"nearest"})},[C]);const j=_=>{const R=_.currentTarget.value,D=p.findIndex(Y=>Y.value===R)>-1;s(R,D,!1)};return h.jsxs("div",{className:"relative",onFocus:()=>w(!0),onBlur:()=>w(!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:sv.dropContainer,ref:y,tabIndex:-1,children:g.map((_,R)=>h.jsxs("div",{className:sv.item,"data-is-active":C===R,onMouseDownCapture:D=>{D.preventDefault(),w(!1),s(_.value,!0,!0)},children:[h.jsx("span",{className:"text-xs font-semibold truncate",children:_.table}),h.jsx("p",{className:"truncate text-sm",children:_.label})]},R))})]})},r6="_drop-container_a7zi8_2",o6="_item_a7zi8_2",iv={dropContainer:r6,item:o6};function u6(n){return c4.includes(n)?r4:f4.includes(n)?i4:d4.includes(n)?o4:Id}const c6=({value:n,onChange:l,autoFocus:r,focusId:s,colType:o})=>{const u=b.useMemo(()=>{const w=n.toLowerCase()||"";return u6(o||"").filter(C=>C.label.includes(w))},[n,o]),d=b.useRef(null),[m,y]=b.useState(!1),[p,g]=b.useState(0),S=w=>{var C;w.key==="ArrowDown"?(w.preventDefault(),g(E=>(E+1)%u.length)):w.key==="ArrowUp"?(w.preventDefault(),g(E=>(E-1+u.length)%u.length)):w.key==="Enter"&&(p>=0&&p<u.length?(w.preventDefault(),y(!1),l(((C=u[p])==null?void 0:C.label)||"",!0)):l(n,!0))};return b.useEffect(()=>{var C;const w=(C=d.current)==null?void 0:C.querySelector('[data-is-active="true"]');w&&w.scrollIntoView({behavior:"smooth",block:"nearest"})},[p]),h.jsxs("div",{className:"relative",children:[h.jsx("input",{onKeyDown:S,value:n,onChange:w=>l(w.target.value,!1),className:"input w-full",placeholder:"Operator",autoFocus:r,onFocus:()=>y(!0),onBlur:()=>y(!1),"data-focus":s}),m&&u.length>0&&h.jsx("ul",{className:iv.dropContainer,ref:d,tabIndex:-1,children:u.map((w,C)=>h.jsx("li",{className:iv.item,"data-is-active":p===C,onMouseDownCapture:E=>{E.preventDefault(),y(!1),l(w.label,!0)},children:w.label},C))})]})},f6="_actions_14av2_2",d6="_filter-actions_14av2_2",G1={actions:f6,filterActions:d6},h6=["=","<",">",">=","<>","!=","<="];function m6(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 zt.error(`Filter #${l+1} has invalid column value`),!1;const s=eh[r.operator];if(!s)return zt.error(`Filter #${l+1} has invalid operator`),!1;if(r.isColumnRef&&!h6.includes(s))return zt.error(`Filter #${l+1} cannot reference another column because it uses '${r.operator}' operator`),!1}return!0}function p6(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 s=eh[r.operator];l.push({id:r.id,value:r.isColumnRef?[{value:r.value,isColumn:!0}]:u4(s,r.value),operator:s,column:r.column,isEnabled:!0,connector:"AND"})}),l}function y6(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 v6=({filter:n,dataSourceId:l,allowedTables:r,inspections:s,autoFocus:o,onChangeColumn:u,onChangeOperator:d,onChangeValue:m,onRemoveFilter:y,onIsColumnChange:p})=>{const g=b.useMemo(()=>{if(!s)return"";let S=null;for(const w of s)for(const C of w.columns)w.tableName+"."+C.name===n.column&&(S=C);return S!=null&&S.type?S.type:""},[n.column,s]);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(c6,{onChange:S=>d(n.id,S),focusId:"operator",colType:g,value:n.operator})}),g1(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:G1.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 filter",className:"p-0.5 text-sm cursor-pointer",onClick:()=>y(n.id),children:h.jsx(kn,{width:20,height:20,className:"text-red-600"})})]})]})},g6=()=>{const{state:n}=b.useContext(ht),{setFilters:l}=k1(),r=zu(A=>A.filters),{data:s}=ei(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(R=>R.id===A?{...R,column:j}:R)])},y=(A,j)=>{d(_=>[..._.map(R=>R.id===A?{...R,operator:j}:R)])},p=(A,j)=>{d(_=>[..._.map(R=>R.id===A?{...R,value:j}:R)])},g=()=>{d(A=>[...A,{id:Ua(),value:"",column:"",operator:"",isColumnRef:!1}])},S=(A,j)=>{d(_=>[..._.map(R=>R.id===A?{...R,isColumnRef:j}:R)])},w=A=>{d(j=>j.filter(_=>_.id!==A))},C=()=>qu("filters"),E=()=>{m6(u)&&(l(p6(u)),C())};return b.useEffect(()=>{if(!r){d([]);return}d(()=>{const A=n.filters.map(j=>{var _,R;return{id:j.id,value:y6(j),column:j.column,operator:Wd[j.operator],isColumnRef:!!((R=(_=j.value)==null?void 0:_[0])!=null&&R.isColumn)}});return A.push({id:Ua(),value:"",column:"",operator:"",isColumnRef:!1}),A})},[r]),cn("f",()=>{mu("filters")},"Add new filter"),cn("ctrl+f",()=>{alert("Save filters")},"Save filters"),h.jsxs(It,{isVisible:r,onClose:C,portal:!0,children:[h.jsx(Qn,{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(v6,{filter:A,dataSourceId:n.dataSourceId,allowedTables:o,inspections:s||[],onChangeColumn:m,onChangeOperator:y,onChangeValue:p,onRemoveFilter:w,onIsColumnChange:S,autoFocus:j===u.length-1},A.id))]}),h.jsxs("div",{className:G1.actions,children:[h.jsx("button",{className:"button tertiary",onClick:g,children:"Add filter"}),h.jsx("button",{className:"button primary",onClick:E,children:"Apply filters"})]})]})},b6="_card_7tspz_2",x6="_cards-list_7tspz_2",S6="_join-modal_7tspz_2",w6="_close-button_7tspz_2",Qo={card:b6,cardsList:x6,joinModal:S6,closeButton:w6},E6=()=>{const{isFetching:n}=b.useContext(Yn),l=zu(p=>p.joins),{toggle:r,joins:s}=Q1(),{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=()=>qu("joins");return cn("j",()=>{o.length>0?Ln("joins"):zt.error("No available tables to join")},"Add new join"),h.jsxs(It,{isVisible:l,onClose:y,portal:!0,children:[h.jsx(Qn,{onClick:y}),h.jsxs("div",{className:Qo.joinModal,children:[h.jsx("h2",{className:"text-lg font-semibold mb-4",children:"Join table"}),s.length>0&&h.jsx("div",{className:Qo.cardsList,children:s.map((p,g)=>h.jsxs("div",{className:Qo.card,children:[h.jsxs("p",{className:"text-sm truncate",children:[p.table," on ",p.on]}),g===s.length-1&&h.jsx("button",{className:Qo.closeButton,onClick:()=>r(p),disabled:n,children:h.jsx(kn,{width:20,height:20})})]},p.table+p.on))}),o.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(H1,{hook:p,onClick:()=>{n||(r({table:p.on.toTable,type:"LEFT",on:p.where}),d(""))}},p.where))})]})]})};function C6(n){return n.reduce((l,r)=>(l[r]=!0,l),{})}function rv(n){return n.reduce((l,r)=>(l[r]=!0,l),{})}const _6="_container_18lan_2",N6="_column-label_18lan_2",j6="_not-active_18lan_2",Wo={container:_6,columnLabel:N6,notActive:j6};function A6(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}],h4[r.type]&&["YEAR","MONTH","DAY"].forEach(s=>{l[r.table].push({value:s+" "+r.full,ogColumn:r.column,label:s+" "+hl(r.column),type:"number",nested:!0})})}),Object.entries(l).reduce((r,[s,o])=>(r.push({name:hl(s),columns:o}),r),[])}function T6(n,l){const r=l.toLowerCase();return n.map(s=>{const o=s.columns.filter(u=>u.label.toLowerCase().includes(r)||u.ogColumn.toLowerCase().includes(r));return{...s,columns:o}}).filter(s=>s.columns.length>0)}const R6=({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),O6={columns:"c",groupBy:"g"},ov=({mode:n})=>{const l=zu(_=>_[n]),{allColumns:r}=b.useContext(oa),{state:s,setState:o}=b.useContext(ht),[u,d]=b.useState({}),[m,y]=b.useState(""),p=b.useMemo(()=>A6(r),[r]),g=s.aggregations.length>0||s.groupBy.length>0,S=b.useMemo(()=>m?T6(p,m):p,[m,p]),w=_=>{d(R=>({...R,[_.target.name]:_.target.checked}))},C=_=>{const R=_.target.checked;d(D=>{for(const Y of r)D[Y.full]=R;return{...D}})},E=()=>{qu(n)},A=()=>{const _=[];for(const[R,D]of Object.entries(u))if(D){const[Y,H]=R.split(" ");_.push({value:H||Y,fn:H?Y:void 0})}o(R=>({...R,[n]:_})),E()},j=b.useMemo(()=>{for(const _ of r)if(!u[_.full])return!1;return!0},[u,r]);return cn(O6[n],()=>{n==="columns"?g?zt.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(()=>C6(s[n].map(_=>_.fn?_.fn+" "+_.value:_.value)))},[l,d]),h.jsxs(It,{isVisible:l,onClose:E,portal:!0,children:[h.jsx(Qn,{onClick:E}),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(R=>h.jsx(R6,{column:R,selected:u,onCheck:w},R.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:E,children:"Cancel"}),h.jsx("button",{className:"button primary",onClick:A,children:"Apply"})]})]})]})},D6="_options-container_15aey_2",M6={optionsContainer:D6},cd="COUNT all",U6=n=>n.distinct?[n.fn,"DISTINCT",n.value].join(" "):[n.fn,n.value].join(" "),L6=()=>{const n=zu(E=>E.aggregate),{dataSourceId:l}=b.useContext(oa),{setState:r,state:s}=b.useContext(ht),{data:o}=b.useContext(Yn),[u,d]=b.useState({fn:"",col:""}),m=E=>d({...u,fn:E.currentTarget.value}),y=E=>d({...u,col:E}),p=()=>qu("aggregate"),g=()=>{const E=u.fn===cd?{value:"*",fn:"COUNT"}:{fn:u.fn,value:u.col,distinct:u.fn==="COUNT"};r(A=>({...A,aggregations:[...A.aggregations,E]}))},S=u.fn===cd,w=S?!1:!u.col||!u.fn,C=E=>{const A=ta(E);r(j=>({...j,aggregations:j.aggregations.filter(_=>_.fn!==E.fn||_.value!==E.value),orderBy:j.orderBy.filter(_=>_.column!==A)}))};return cn("a",()=>{mu("aggregate")},"Aggregate data"),h.jsxs(It,{isVisible:n,onClose:p,backdropClose:!0,portal:!0,children:[h.jsx(Qn,{onClick:p}),h.jsxs("div",{children:[h.jsx("h2",{className:"text-lg font-semibold",children:"Aggregate"}),Zl(s.aggregations.length,0)&&h.jsx("div",{className:"flex flex-col gap-1 mt-4",children:s.aggregations.map((E,A)=>h.jsxs("p",{className:"p-2 rounded-md bg-gray-50 flex items-center justify-between",children:[h.jsx("span",{children:U6(E)}),h.jsx("button",{tabIndex:-1,"data-tooltip-id":"default","data-tooltip-content":"Remove aggregation",className:"p-0.5 text-sm cursor-pointer",onClick:()=>C(E),children:h.jsx(kn,{width:20,height:20,className:"text-red-600"})})]},A))}),h.jsxs("div",{className:M6.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:w,onClick:g,children:"Add"})]})]})]})},F1=({options:n,updater:l,name:r,tabId:s})=>{const o=y4(n,l),{state:u}=o,d=iE({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=p4(d.data,n.dataSourceId,r,s);return h.jsx(oa,{value:m,children:h.jsx(ht,{value:o,children:h.jsxs(Yn,{value:d,children:[h.jsx(W_,{}),h.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[h.jsxs("div",{className:"m-2 flex-1 overflow-auto pb-24 lg:pb-12 no-scrollbar",children:[h.jsx("div",{className:"pb-0.5 sticky bottom-0"}),h.jsx(y_,{})]}),h.jsx(g6,{}),h.jsx(E6,{}),h.jsx(ov,{mode:"columns"}),h.jsx(ov,{mode:"groupBy"}),h.jsx(L6,{}),h.jsx(F_,{})]})]})})})},z6=({tab:n})=>{const l=b.useCallback(r=>{ju(s=>s.map(o=>o.id!==n.id?o:{...o,options:r(o.options)}))},[n]);return h.jsx(F1,{updater:l,options:n.options,name:n.label,tabId:n.id})},q6=({content:n,activeAnchor:l})=>{if(!l)return null;const r=l.getAttribute("data-tab-id"),s=Au.get().find(d=>d.id===r),o=UC(s==null?void 0:s.options.dataSourceId);if(!s)return n;const u=()=>{Pl("New tab name",s.label).then(d=>{d&&Tu(s.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:s.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:s.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})]}),s.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:s.options.joins.map(d=>d.table).join(", ")})]}),s.options.filters.length>0&&h.jsxs("div",{className:ea.tooltipInfoEntry,children:[h.jsx("p",{className:"text-sm",children:"filters"}),s.options.filters.map(d=>h.jsx("p",{className:"truncate font-semibold",children:eE(d)}))]})]})},B6=()=>{const n=g4(),l=b1(),r=dh(Uu.laptop),s=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&&Uy(y)},u=m=>{m.button===1&&Uy(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&&Tu(m,p)})};return l.length<1?h.jsx(a2,{to:"/"}):h.jsxs("div",{className:"h-screen max-h-screen bg-(--bg) flex flex-col",children:[r&&h.jsx(Mu,{id:"tab",render:q6,className:"z-10 shadow-md p-0!",offset:-1,noArrow:!0,opacity:1,variant:"light",clickable:!0,delayShow:500}),s&&h.jsx(z6,{tab:s}),h.jsx("div",{className:se(ea.tabs,"no-scrollbar",!r&&ea.mobile),children:l==null?void 0:l.map(m=>h.jsxs("div",{onClick:()=>x1(m.id),className:se(ea.tab,m.id===(s==null?void 0:s.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(kn,{width:20,height:20})})]},m.id))})]})},H6=()=>{const n=I_(),l=b.useCallback(r=>{K1(s=>s?{...s,options:r(s.options)}:(zt.error("Something went wrong."),s))},[]);return n?h.jsxs(It,{isVisible:!0,onClose:Ud,children:[h.jsx(Qn,{onClick:Ud}),h.jsx("div",{className:"border border-gray-200 bg-(--bg) flex flex-col",children:h.jsx(F1,{name:n.label,options:n.options,updater:l})})]}):null},k6="_root_16wvc_2",Q6="_down_16wvc_2",Y6="_chevron_16wvc_2",V6="_table-name-container_16wvc_2",K6="_link_16wvc_2",G6="_table-name_16wvc_2",F6="_ul_16wvc_2",$6="_column-type_16wvc_2",Ra={root:k6,down:Q6,chevron:Y6,tableNameContainer:V6,link:K6,tableName:G6,ul:F6,columnType:$6},[ij,X6]=Pt(!1),$1=()=>X6(!1),Z6=new Intl.DateTimeFormat("en",{dateStyle:"full",timeStyle:"long"});function J6(n,l){if(l&&n.toLowerCase().includes(l))return"bg-yellow-200"}const P6=({insp:n,filter:l,expanded:r})=>{const s=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:s.map(o=>h.jsx(h.Fragment,{children:h.jsxs("li",{children:[o.isPrimary?"🔐":"🏷️"," ",h.jsx("span",{className:J6(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 I6({id:n}){const{data:l}=Nu(n),{data:r}=ei(n),s=Jt(),{pathname:o}=Nt(),u=X3(),d=p1(),m=Z3(),y=b.useMemo(()=>l!=null&&l.lastInspected?Z6.format(new Date(l.lastInspected)):"--",[l]),[p,g]=b.useState({}),[S,w]=b.useState(""),[C,E]=b.useState("table"),A=Sr($t.EDITOR),j=S.toLowerCase(),_=b.useMemo(()=>{if(!j||!r)return r||[];const I=[];for(const re of r){if(re.tableName.toLowerCase().includes(j)){I.push(re);continue}C!=="table"&&re.columns.findIndex(pe=>pe.name.toLowerCase().includes(j))>=0&&I.push(re)}return I},[j,r,C]),R=I=>{g(re=>({...re,[I]:!re[I]}))},D=I=>{pl(I,{table:I,dataSourceId:n},!0),Ys(void 0),$1(),o!==Xe.workbench.path&&s(Xe.workbench.path)},Y=()=>{d.mutate(n)},H=async()=>{const I=await Pl("Enter name",l==null?void 0:l.name);I&&u.mutate({id:n,dataSource:{name:I}})},$=async()=>{await E1("Are you sure you want to delete this data source?")&&(m.mutate(n),Ys(void 0))},W=C==="column";return h.jsxs("div",{className:Ra.root,children:[h.jsxs("h3",{className:"page-head flex gap-2",children:[l&&h.jsx(nh,{size:32,type:l.dbType}),h.jsx("span",{className:"truncate",children:l==null?void 0:l.name})]}),h.jsx("p",{className:"mt-2 text-xs text-gray-800",children:"Last DB inspection"}),h.jsx("p",{className:"text-sm font-semibold",children: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-2 items-center mb-2 mt-4",children:[h.jsxs("select",{className:"input",value:C,onChange:I=>E(I.currentTarget.value),children:[h.jsx("option",{value:"table",children:"Table"}),h.jsx("option",{value:"column",children:"Column"})]}),h.jsx("input",{className:"input flex-1 bg-gray-50",placeholder:W?"Search column":"Search table",value:S,onChange:I=>w(I.target.value),autoFocus:!0})]}),h.jsx("div",{className:"overflow-y-auto",children:_==null?void 0:_.map(I=>h.jsxs("div",{children:[h.jsxs("div",{className:Ra.tableNameContainer,children:[h.jsx("button",{className:se(Ra.chevron,p[I.id]&&Ra.down),onClick:()=>R(I.id),children:h.jsx(Lu,{width:16,height:16})}),h.jsx("button",{className:se(Ra.tableName,"flex-1"),onClick:()=>R(I.id),children:I.tableName}),h.jsx("button",{className:Ra.link,onClick:()=>D(I.tableName),children:"↗️"})]}),(p[I.id]||S.length>0)&&h.jsx(P6,{insp:I,filter:W?j:"",expanded:p[I.id]})]},I.id))})]})}const W6=()=>{const n=G4(),[l,r]=b.useState(void 0);b.useEffect(()=>{n&&r(n)},[n]);const s=()=>Ys(void 0);return h.jsx(Y1,{isVisible:n!=null,onClose:s,onClosed:()=>r(void 0),backdropClose:!0,children:l&&h.jsx(I6,{id:l})})};function eN(n,l=500){const[r,s]=b.useState(n);return b.useEffect(()=>{const o=setTimeout(()=>s(n),l);return()=>clearTimeout(o)},[n,l]),r}const tN="_search_1vn45_2",nN="_entry_1vn45_2",aN="_ds_1vn45_2",lN="_ds-entry_1vn45_2",Yo={search:tN,entry:nN,ds:aN,dsEntry:lN},[sN,iN]=th({initialData:[],localStorageKey:"selected-data-sources-v1"}),rN=n=>iN(l=>{const r=l.indexOf(n);return r>-1?(l.splice(r,1),[...l]):[...l,n]}),oN={table:"📄",query:"📖"},uN=({onTable:n,onQuery:l,autoFocus:r})=>{const[s,o]=b.useState(""),[u,d]=b.useState(-1),m=eN(s,200),y=sN(),{data:p}=ia(),{data:g}=Pd({teamId:p==null?void 0:p.teamId}),S=b.useMemo(()=>{const _=[],R=rv(y);if(!g||g.length===0)return[];for(const D of g)R[D.id]&&_.push(D.id);return _},[y,g]),{data:w}=V3(m,{teamId:p==null?void 0:p.teamId,selectedDataSources:S}),C=_=>{_.type==="table"?n(_.name,_.dataSourceId):_.type==="query"&&l(_.id,_.dataSourceId)},E=_=>{var R;w&&(_.key==="ArrowDown"?(_.preventDefault(),d(D=>(D+1)%w.length)):_.key==="ArrowUp"?(_.preventDefault(),d(D=>(D-1+w.length)%w.length)):_.key==="Enter"&&u>=0&&(R=w[u])!=null&&R.name&&(_.preventDefault(),C(w[u])))},A=_=>{const R=_.currentTarget.dataset.tableId,D=w==null?void 0:w.find(Y=>Y.id===R);D&&C(D)},j=b.useMemo(()=>rv(y),[y]);return h.jsxs("div",{className:"overflow-hidden flex flex-col w-full lg:w-lg",children:[Zl(g==null?void 0:g.length,0)&&h.jsx("div",{className:"flex overflow-x-auto mb-2 gap-2 no-scrollbar",children:g.map(_=>h.jsxs("label",{className:Yo.dsEntry,children:[h.jsx("input",{type:"checkbox",checked:j[_.id]===!0,onChange:()=>rN(_.id)}),h.jsx("span",{children:_.name})]},_.id))}),h.jsx("input",{className:Yo.search,placeholder:"Search table or saved query to start from",value:s,onChange:_=>o(_.target.value),onKeyDown:E,autoFocus:r}),Zl(w==null?void 0:w.length,0)&&h.jsx("div",{className:"overflow-y-auto max-h-full mt-2",children:w.map((_,R)=>h.jsxs("button",{className:Yo.entry,"data-is-active":u===R,"data-table-id":_.id,onClick:A,children:[h.jsxs("p",{className:"font-semibold",children:[oN[_.type]," ",_.name]}),h.jsxs("p",{className:Yo.ds,children:["📦 ",_.dataSourceName]})]},_.id))})]})},cN=()=>{const n=E4(),l=(o,u)=>{n==null||n.onConfirm("table",o,u)},r=(o,u)=>{n==null||n.onConfirm("query",o,u)},s=()=>{n==null||n.onCancel()};return h.jsxs(It,{isVisible:!!n,onClose:s,children:[h.jsx(Qn,{onClick:s}),h.jsx(uN,{autoFocus:!0,onTable:l,onQuery:r})]})},fN=()=>{const n=Nt();b.useEffect(()=>{},[n.pathname])},[dN,X1]=Pt(!1),fd=()=>X1(!1),Z1=()=>X1(!0),hN=({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,mN=()=>{const n=dN(),{data:l}=ia(),{mutateAsync:r,isLoading:s}=J3(),o=Jt(),[{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(),zt.success("Password successfully updated!")})},w=u.length<8||u!==d||s,C=y.includes("password");return h.jsxs(It,{isVisible:n,onClose:fd,children:[h.jsx(Qn,{onClick:fd}),h.jsxs("div",{className:"w-full lg:w-lg flex flex-col gap-2",children:[h.jsx(w1,{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(hN,{password:u,repeatPassword:d}),h.jsxs("div",{className:"flex justify-end gap-2 mt-2",children:[h.jsx("button",{className:"button tertiary",disabled:w,onClick:S,children:"Update password"}),h.jsx("button",{className:"button danger",onClick:g,children:"Log out"})]})]})]})},[pN,J1]=Pt(!1),P1=()=>J1(!0),uv=()=>J1(!1),yN=n=>dn({queryKey:["team-users"],queryFn:async()=>{const{data:l}=await Ye.get("/teams/"+n+"/users");return l.data},enabled:!!n}),vN=()=>fn({mutationFn:async({role:n,teamId:l,userId:r})=>(await Ye.patch("/teams/"+l+"/user-role",{role:n,userId:r}),!0),onSuccess:()=>{yt.invalidateQueries({queryKey:["team-users"]})}}),gN=()=>fn({mutationFn:async({teamId:n,userId:l})=>(await Ye.delete("/teams/"+n,{params:{userId:l}}),!0),onSuccess:()=>{yt.invalidateQueries({queryKey:["team-users"]})}}),bN="_user-entry_jtuip_2",xN={userEntry:bN},SN=()=>{const n=pN(),{data:l}=ia(),{data:r}=yN(l==null?void 0:l.teamId),{mutate:s,isLoading:o}=P3(),{mutate:u,isLoading:d}=vN(),{mutate:m,isLoading:y}=gN(),[p,{change:g,reset:S}]=wr({password:"",username:""}),w=()=>{s({username:p.username,password:p.password,teamId:(l==null?void 0:l.teamId)||""}),S()},C=(_,R)=>{u({teamId:l.teamId,role:R,userId:_})},E=_=>{E1("Are you sure you want to remove this user?").then(R=>{R&&m({userId:_,teamId:l.teamId})})},A=Sr($t.ADMIN),j=o||d||y;return h.jsxs(It,{isVisible:n,onClose:uv,backdropClose:!0,children:[h.jsx(Qn,{onClick:uv}),h.jsxs("div",{className:"w-full lg:w-lg flex flex-col overflow-hidden",children:[h.jsx(w1,{children:"Manage users"}),Zl(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:xN.userEntry,children:[h.jsxs("select",{className:"input",value:_.role,disabled:!A||j,onChange:R=>C(_.id,R.currentTarget.value),children:[h.jsx("option",{value:$t.OWNER,children:"Owner"}),h.jsx("option",{value:$t.ADMIN,children:"Admin"}),h.jsx("option",{value:$t.EDITOR,children:"Editor"}),h.jsx("option",{value:$t.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:()=>E(_.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:w,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."})]})]})]})},wN=()=>{const[n,l]=b.useState(""),[r,s]=b.useState(""),[o,u]=b.useState(),[d,m]=b.useState(!1),y=Jt(),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=>s(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?"})]})})})},EN=()=>{const n=Jt(),{pathname:l}=Nt(),{data:r,isLoading:s}=y1();b.useEffect(()=>{!r&&!s&&l!==Xe.login.path&&n(Xe.login.path)},[r,s,n,l])},CN=()=>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..."})]}),_N=()=>{const[n]=L2(),l=Jt(),{data:r,isLoading:s,isError:o}=X_(n.get("shareId"));return b.useEffect(()=>{var u;r&&(pl(r.name,{...r.opts,dataSourceId:(u=r.dataSource)==null?void 0:u.id},!0),l(Xe.workbench.path,{replace:!0}))},[r]),h.jsxs("div",{className:"page-container flex items-center justify-center h-screen",children:[s&&h.jsxs("div",{className:"flex items-center flex-col gap-2",children:[h.jsx(CN,{}),h.jsx("p",{children:"Fetching query information"})]}),o&&h.jsx(Lt,{variant:"danger",children:"Failed to load query information"})]})};function NN(){return B_(),fN(),EN(),h.jsxs(h.Fragment,{children:[h.jsxs(s2,{children:[h.jsx(ir,{path:Xe.home.path,element:h.jsx(P4,{})}),h.jsx(ir,{path:Xe.workbench.path,element:h.jsx(B6,{})}),h.jsx(ir,{path:Xe.login.path,element:h.jsx(wN,{})}),h.jsx(ir,{path:Xe.share.path,element:h.jsx(_N,{})})]}),h.jsx(H6,{}),h.jsx(fE,{}),h.jsx(SE,{}),h.jsx(UE,{}),h.jsx(W6,{}),h.jsx(cN,{}),h.jsx(mN,{}),h.jsx(SN,{}),h.jsx(TE,{}),h.jsx(CE,{})]})}const jN="_desktop-layout_svwiu_2",AN="_mobile-layout_svwiu_2",TN="_nav_svwiu_2",RN="_main_svwiu_2",ON="_header_svwiu_2",Gs={desktopLayout:jN,mobileLayout:AN,nav:TN,main:RN,header:ON},DN="_container_1y5b4_2",MN="_menu_1y5b4_2",ph={container:DN,menu:MN},UN=({name:n,id:l,onRename:r,onDelete:s,onOpen:o})=>{const u=q1();return h.jsxs("button",{className:ph.menu,onContextMenu:u.open,onClick:()=>o(l),children:[h.jsx(B1,{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(),s(l)},className:"context-menu-item",children:"🗑️ Delete"})]})}),h.jsxs("span",{children:["📖 ",n]})]})},LN=({dataSource:n,index:l})=>{const r=()=>{Ys(n.id)};return cn(l.toString(),()=>{Ys(s=>{if(s!==n.id)return n.id})},n.name),h.jsxs("button",{className:ph.menu,onClick:r,children:[h.jsx(nh,{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})]})},zN=()=>{const n=Jt(),l=Nt(),{data:r}=ia(),{data:s}=k3(r==null?void 0:r.teamId),{data:o}=Q3(r==null?void 0:r.teamId),u=P_(),d=J_(),m=g=>{S1(g).then(S=>{var w;pl(S.name,fr({...S.opts,dataSourceId:(w=S.dataSource)==null?void 0:w.id}),!0),l.pathname!==Xe.workbench.path&&n(Xe.workbench.path)})},y=async g=>{const S=o==null?void 0:o.find(C=>C.id===g),w=await Pl("New name?",S==null?void 0:S.name);w&&u.mutate({id:g,payload:{name:w}})},p=g=>{var w;const S=(w=o==null?void 0:o.find(C=>C.id===g))==null?void 0:w.savedQueryId;S&&d.mutate(S)};return h.jsx("div",{className:ph.container,children:h.jsxs("div",{className:"flex-1 overflow-y-auto",children:[Zl(s==null?void 0:s.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"}),s.map((g,S)=>h.jsx(LN,{dataSource:g,index:S+1},g.id))]}),Zl(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(g=>h.jsx(UN,{onDelete:p,onRename:y,onOpen:m,name:g.name,id:g.id},g.savedQueryId))]})]})})},qN=()=>{const n=Jt(),{pathname:l}=Nt(),{data:r}=ia(),s=xr("Desktop nav"),o=()=>{$1(),l!==Xe.home.path&&n(Xe.home.path)};return h.jsxs("nav",{className:Gs.nav,children:[r&&h.jsxs("div",{className:Gs.header,children:[h.jsxs("button",{onClick:o,className:"flex justify-between items-center",children:[h.jsx("span",{children:"🏠 Home"}),h.jsx("span",{className:"hotkey",children:"H"})]}),h.jsxs("button",{onClick:s,className:"flex justify-between items-center",children:[h.jsx("span",{children:"🔎 New query"}),h.jsx("span",{className:"hotkey",children:"N"})]}),h.jsxs("button",{onClick:Z1,children:["🪪 ",r.username]}),h.jsx("button",{onClick:P1,children:"👥 Manage users"})]}),h.jsx(zN,{})]})},BN="_root_iws5j_2",HN={root:BN},kN=()=>{const{pathname:n}=Nt(),l=Jt(),r=xr("Mobile nav"),s=()=>{n!==Xe.home.path&&l(Xe.home.path)};return h.jsxs("div",{className:HN.root,children:[h.jsxs("button",{onClick:s,children:[h.jsx("p",{children:"🏠"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Home"})]}),h.jsxs("button",{onClick:r,children:[h.jsx("p",{children:"🔎"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"New query"})]}),h.jsxs("button",{onClick:Z1,children:[h.jsx("p",{children:"🪪"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Account"})]}),h.jsxs("button",{onClick:P1,children:[h.jsx("p",{children:"👥"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Users"})]})]})},QN=({children:n,isLogin:l})=>h.jsxs("div",{className:Gs.desktopLayout,children:[h.jsx(Mu,{id:"default",className:"z-100"}),!l&&h.jsx(qN,{}),h.jsx("main",{className:Gs.main,children:n})]}),YN=({children:n,isLogin:l})=>h.jsxs("div",{className:Gs.mobileLayout,children:[h.jsx("main",{className:Gs.main,children:n}),!l&&h.jsx(kN,{})]}),VN=({children:n})=>{const l=dh(Uu.laptop),{pathname:r}=Nt(),s=r===Xe.login.path;return l?h.jsx(QN,{isLogin:s,children:n}):h.jsx(YN,{isLogin:s,children:n})};hx.createRoot(document.getElementById("root")).render(h.jsxs(Ke.StrictMode,{children:[h.jsx(q3,{}),h.jsx(fS,{client:yt,children:h.jsx(R2,{children:h.jsx(VN,{children:h.jsx(NN,{})})})})]}));
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 UC=n=>{if(!n)return;const l=yt.getQueryData([Jd]);if(!l)return;const r=yt.getQueryData([La,l.teamId]);return r==null?void 0:r.find(s=>s.id===n)},Jy=n=>window.matchMedia(n).matches;function dh(n,{defaultValue:l=!1,initializeWithValue:r=!0}={}){const[s,o]=b.useState(()=>r?Jy(n):l);return b.useLayoutEffect(()=>{const u=window.matchMedia(n);function d(){o(()=>Jy(n))}return d(),u.addListener?u.addListener(d):u.addEventListener("change",d),()=>{u.removeListener?u.removeListener(d):u.removeEventListener("change",d)}},[n]),s}const Uu={laptop:"(min-width: 1024px)"},LC=()=>window.matchMedia(Uu.laptop).matches,zC="_table_1yv46_2",qC="_semi-transparent_1yv46_2",BC="_table-loading_1yv46_2",HC="_table-empty_1yv46_2",kC="_table-row-cells_1yv46_2",QC="_header-cell_1yv46_2",YC="_header-actions_1yv46_2",VC="_cell_1yv46_2",KC="_cell-actions_1yv46_2",GC="_table-config_1yv46_2",FC="_table-action_1yv46_2",$C="_blue_1yv46_2",XC="_red_1yv46_2",ZC="_modal_1yv46_2",JC="_size_1yv46_2",PC="_options-container_1yv46_2",IC="_underlying-rows-btn_1yv46_2",WC="_option-item_1yv46_2",ne={table:zC,semiTransparent:qC,tableLoading:BC,tableEmpty:HC,tableRowCells:kC,headerCell:QC,headerActions:YC,cell:VC,cellActions:KC,tableConfig:GC,tableAction:FC,blue:$C,red:XC,modal:ZC,size:JC,optionsContainer:PC,underlyingRowsBtn:IC,optionItem:WC},oa=b.createContext({name:"No name",hooks:[],availableJoins:[],allColumns:[],dataSourceId:"",entities:[],getValue:()=>{},getColumnType:()=>{},getEntityKey:()=>[]}),ht=b.createContext({state:fr({}),setState:()=>{}}),Yn=b.createContext({}),q1=()=>{const[n,l]=b.useState();return b.useMemo(()=>({show:!!n,position:n,open:s=>{s.preventDefault(),l({x:s.clientX-1,y:s.clientY-1})},close:()=>{l(void 0)}}),[n])},e_=n=>{if(n==="ASC")return"DESC";if(n!=="DESC")return"ASC"},t_=()=>{const{state:n,setState:l}=b.useContext(ht),r=b.useCallback(s=>{l(o=>{const u=o.orderBy[0];if(u&&u.column===s){const d=e_(u.direction);return d?{...o,orderBy:[{column:s,direction:d}]}:{...o,orderBy:[]}}return{...o,orderBy:[{column:s,direction:"ASC"}]}})},[l]);return{orderBy:n.orderBy,updateOrderBy:r}};function n_(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 s=(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:s,column:o}}const a_=()=>{const{data:n}=b.useContext(Yn),{getColumnType:l}=b.useContext(oa),{setState:r}=b.useContext(ht),s=m=>{const{value:y,column:p}=od(n,m.row,m.col);if(p){const g=Kl(y,l(p.full));navigator.clipboard.writeText(g),zt.success("Copied!")}},o=m=>{const{value:y,column:p}=od(n,m.row,m.col);if(p){const g=Kl(y,l(p.full));C1(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)===""){zt.error("Filtering on aggregated column is not supported yet");return}if(g){let w;if(y==null)w={id:Ua(),isEnabled:!0,column:g,connector:"AND",operator:"IS NULL"};else{const C=Kl(y,l(g));w={id:Ua(),isEnabled:!0,column:g,connector:"AND",operator:"=",fn:S,value:[{value:C}]}}r(C=>({...C,filters:[...C.filters,w]})),zt.success(`Added new filter on column ${p==null?void 0:p.alias}`)}};return m=>{const y=n_(m);y&&(y.action==="copy"?s(y):y.action==="show"?o(y):y.action==="filter"&&u(y))}},l_="_container_ld4dc_2",s_="_content_ld4dc_2",i_="_backdrop_ld4dc_2",ud={container:l_,content:s_,backdrop:i_},B1=({children:n,handler:l})=>{const r=b.useRef(l.close);r.current=l.close;const s=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,LC()?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)}},[]),s?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:s,children:n})]}):null},r_="_table_nc86f_2",o_="_root_nc86f_2",u_="_content_nc86f_2",c_="_sub_nc86f_2",ko={table:r_,root:o_,content:u_,sub:c_},H1=({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),Zl=(n,l)=>n!=null&&n>l,f_=({handler:n,rowIndex:l})=>{const{hooks:r,entities:s,dataSourceId:o,getEntityKey:u,getValue:d}=b.useContext(oa),{state:m}=b.useContext(ht),{data:y}=b.useContext(Yn),[p,g]=b.useState(""),[S,w]=b.useState(""),C=b.useMemo(()=>y==null?void 0:y.rows[l],[y,l]),E=()=>{C&&(pl("⬇️ "+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}`});pl(`↗️ ${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?s.filter(Y=>Y.includes(p)):s,[s,p]),R=b.useMemo(()=>{if(!y)return[];const Y=S.toLowerCase();return r.filter(H=>y.columns.some(W=>W.column===H.on.fromColumn&&W.table===H.on.fromTable)?H.on.toTable.toLowerCase().includes(Y):!1)},[S,r,y]),D=m.groupBy.length>0;return h.jsxs(B1,{handler:n,children:[s.length>0&&h.jsxs("div",{className:ne.optionsContainer,children:[h.jsxs("label",{className:"flex items-center gap-2 border-b border-b-gray-200 p-2 bg-(--bg)",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 overflow-y-auto",children:Zl(_.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 p-2 text-gray-800",children:"Empty"})})]}),r.length>0&&h.jsxs("div",{className:ne.optionsContainer,children:[h.jsxs("label",{className:"flex items-center gap-2 border-b border-b-gray-200 p-2 bg-(--bg)",children:[h.jsx("span",{className:"font-semibold",children:"↗️"}),h.jsx("input",{className:"flex-1 outline-0",placeholder:"Connected tables",value:S,onChange:Y=>w(Y.target.value)})]}),h.jsx("div",{className:"flex flex-col overflow-y-auto",children:R.length>0?R.map(Y=>h.jsx(H1,{hook:Y,onClick:()=>A(Y)},Y.where)):h.jsx("p",{className:"text-center p-2 text-gray-800",children:"Empty"})})]}),D&&h.jsx("button",{onClick:E,className:ne.underlyingRowsBtn,children:"🎯 Underlying rows"})]})},d_={ASC:"⬆️",DESC:"⬇️"},h_=()=>{const{data:n}=b.useContext(Yn),{orderBy:l,updateOrderBy:r}=t_(),s=(n==null?void 0:n.columns)||[],o=l[0];return h.jsx("thead",{children:h.jsxs("tr",{children:[h.jsx("td",{className:"p-1 text-center w-8 text-sm text-gray-600",children:"#"}),s.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?d_[o.direction]:"↕️"})})]},u.full))]})})};function m_({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 s=Kl(n);return h.jsxs(h.Fragment,{children:[h.jsx("span",{"data-row":l,className:"truncate block pointer-events-none",children:s}),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 p_=b.memo(({row:n,isLastRow:l,index:r,offset:s})=>h.jsxs("tr",{className:se(ne.tableRowCells,l&&"rounded-b-lg"),children:[h.jsx("td",{className:"p-1 text-center align-middle text-xs w-8 text-blue-500",children:r+1+s}),n.map((o,u)=>h.jsx("td",{className:ne.cell,"data-row":r,children:h.jsx(m_,{value:o,col:u,row:r})},u))]})),y_=()=>{var C,E;const{data:n,error:l,isLoading:r,isFetching:s}=b.useContext(Yn),{state:{page:o,size:u}}=b.useContext(ht),d=lh(l),m=a_(),y=q1(),[p,g]=b.useState(void 0),S=A=>{var R;const j=(R=A.target)==null?void 0:R.dataset,_=j==null?void 0:j.row;_!=null&&(g(parseInt(_)),y.open(A))},w=o*u;return h.jsxs(h.Fragment,{children:[p!=null&&y.show&&h.jsx(f_,{handler:y,rowIndex:p}),d&&h.jsx(Lt,{className:"my-4",variant:"danger",children:d}),r&&h.jsx("div",{className:ne.tableLoading,children:"Loading data"}),n&&h.jsxs("table",{className:se(ne.table,s&&ne.semiTransparent),onContextMenu:S,onClick:m,children:[h.jsx(h_,{}),h.jsxs("tbody",{children:[((C=n.rows)==null?void 0:C.length)<1&&h.jsx("tr",{className:ne.tableEmpty,children:h.jsx("td",{colSpan:n.columns.length+1,children:"No data"})}),(E=n.rows)==null?void 0:E.map((A,j)=>h.jsx(p_,{index:j,offset:w,row:A,isLastRow:j===n.rows.length-1},j))]})]})]})},v_="_root_12ips_2",g_="_root-show_12ips_2",b_="_content-desktop_12ips_2",x_="_content-mobile_12ips_2",S_="_card_12ips_2",w_="_cards-list_12ips_2",E_="_sub-text_12ips_2",C_="_text_12ips_2",__="_section-title_12ips_2",N_="_sidebar-action_12ips_2",j_="_sidebar-add-action_12ips_2",A_="_section-container_12ips_2",T_="_close-button_12ips_2",R_="_section-open-btn_12ips_2",O_="_show_12ips_2",ie={root:v_,rootShow:g_,contentDesktop:b_,contentMobile:x_,card:S_,cardsList:w_,subText:E_,text:C_,sectionTitle:__,sidebarAction:N_,sidebarAddAction:j_,sectionContainer:A_,closeButton:T_,sectionOpenBtn:R_,show:O_};function D_(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 k1=()=>{const{state:n,setState:l}=b.useContext(ht),r=b.useCallback(o=>{l(u=>({...u,filters:o}))},[l]),s=b.useCallback(o=>{l(u=>({...u,filters:u.filters.filter(d=>!(o.column===d.column&&o.operator===d.operator&&D_(o.value,d.value)))}))},[l]);return{filters:n.filters,removeFilter:s,setFilters:r}},M_=(n,l)=>n.type!==l.type||n.on!==l.on||n.table!==l.table,U_=(n,l)=>n.type===l.type&&n.on===l.on&&n.table===l.table,Q1=()=>{const{state:n,setState:l}=b.useContext(ht),r=b.useCallback(s=>{l(o=>{const u=o.joins;if(u.some(m=>U_(m,s))){const m=s.table+".";return{...o,joins:u.filter(y=>M_(y,s)),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,s]}})},[l]);return{joins:n.joins,toggle:r}},Lu=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"})),ks=new Map,L_=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("+")},z_=n=>{var s,o,u;const l=(o=(s=n.target)==null?void 0:s.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=ks.get(L_(n));r&&r.length>0&&r[r.length-1].callback()},q_=(n,l,r="")=>{const s=n.toLowerCase(),o=ks.get(n);return o?ks.set(n,[...o,{callback:l,label:r}]):ks.set(s,[{callback:l,label:r}]),()=>{const u=n.toLowerCase(),d=ks.get(u);d&&ks.set(u,d.filter(m=>m.callback!==l))}};window.addEventListener("keyup",z_);function cn(n,l,r){const s=b.useRef({callback:l,label:r});s.current.callback=l,b.useEffect(()=>q_(n,()=>{s.current.callback()},s.current.label),[n])}const B_=()=>{const n=xr("Hotkey"),l=Jt(),r=Nt(),{data:s}=ia();cn("n",()=>{s&&n()},"📖 New query"),cn("w",()=>{if(!s)return;Au.get().length<1?n():r.pathname!==Xe.workbench.path&&l(Xe.workbench.path)},"🛠️ Open Workbench"),cn("h",()=>{r.pathname!==Xe.home.path&&l(Xe.home.path)},"🏠 Go home")},[H_,k_]=Pt(!1),hh=()=>k_(n=>!n),Q_="_sidebar_4a0zp_2",Y_="_sidebar-visible_4a0zp_2",V_="_sidebar-container_4a0zp_2",K_="_sidebar-invisible_4a0zp_2",G_="_backdrop_4a0zp_2",sr={sidebar:Q_,sidebarVisible:Y_,sidebarContainer:V_,sidebarInvisible:K_,backdrop:G_},Y1=({children:n,backdropClose:l,isVisible:r,onClose:s,onClosed:o,contentClassName:u})=>{const[d,m]=b.useState(!1),y=b.useRef(s);y.current=s;const p=()=>{l&&s()},g=S=>{r||getComputedStyle(S.currentTarget).opacity==="0"&&(m(!1),o&&o())};return b.useEffect(()=>{r&&m(!0)},[r]),b.useEffect(()=>{const S=w=>{r&&w.key==="Escape"&&y.current()};return window.addEventListener("keydown",S),()=>{window.removeEventListener("keydown",S)}},[r]),h.jsxs("div",{onTransitionEnd:g,className:se(sr.sidebar,r?sr.sidebarVisible:sr.sidebarInvisible),children:[h.jsx("div",{onClick:p,className:sr.backdrop}),h.jsx("div",{className:se(sr.sidebarContainer,u),children:d&&n})]})},[zu,mh]=Pt({filters:!1,joins:!1,columns:!1,groupBy:!1,aggregate:!1}),Ln=n=>mh(l=>({...l,[n]:!0})),qu=n=>mh(l=>({...l,[n]:!1})),mu=n=>mh(l=>({...l,[n]:!l[n]})),F_=()=>{const n=H_();return dh(Uu.laptop)?h.jsx("div",{className:se(ie.root,n&&ie.rootShow),children:h.jsxs("div",{className:se(ie.contentDesktop,"no-scrollbar"),children:[h.jsx(Iy,{}),h.jsx(Py,{}),h.jsx(lv,{}),h.jsx(av,{}),h.jsx(nv,{}),h.jsx(ev,{}),h.jsx(tv,{}),h.jsx(Wy,{})]})}):h.jsx(Y1,{isVisible:n,onClose:hh,backdropClose:!0,children:h.jsxs("div",{className:ie.contentMobile,children:[h.jsx(Iy,{}),h.jsx(Py,{}),h.jsx(lv,{}),h.jsx(av,{}),h.jsx(nv,{}),h.jsx(ev,{}),h.jsx(tv,{}),h.jsx(Wy,{})]})})};function Nr({onShow:n,show:l,title:r,items:s}){return h.jsxs("div",{className:"flex justify-between items-center",children:[h.jsx("p",{className:ie.sectionTitle,children:r}),s>0&&h.jsxs("button",{className:se(ie.sectionOpenBtn,l&&ie.show),onClick:n,children:[h.jsx("span",{children:s}),h.jsx(Lu,{width:16,height:16})]})]})}function Py(){const{name:n,tabId:l}=b.useContext(oa),{data:r}=b.useContext(Yn),s=()=>{l&&Pl("New tab name",n).then(u=>{u&&Tu(l,u)})},o=()=>{r!=null&&r.query&&(navigator.clipboard.writeText(r==null?void 0:r.query),zt.success("Query copied to clipboard"))};return cn("r",s,"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:s,children:h.jsx("span",{children:"✏️ Rename tab"})}),h.jsx("button",{className:ie.sidebarAction,onClick:o,children:h.jsx("span",{children:"🖋️ Copy SQL"})})]})}function Iy(){const{state:n}=b.useContext(ht),{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 Wy(){const{state:n,setState:l}=b.useContext(ht),[r,s]=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(Nr,{title:"📚 Group by",show:r,onShow:()=>s(!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(kn,{width:20,height:20})})]},ta(u)))}),h.jsxs("button",{className:ie.sidebarAddAction,onClick:()=>Ln("groupBy"),children:[h.jsx("span",{className:"hotkey",children:"G"}),h.jsx("span",{children:"Add group by"})]})]})}function ev(){const{state:n,setState:l}=b.useContext(ht),[r,s]=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(Nr,{title:"👀 Columns",show:r,onShow:()=>s(!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(kn,{width:20,height:20})})]}))}),!u&&h.jsxs("button",{className:ie.sidebarAddAction,onClick:()=>Ln("columns"),children:[h.jsx("span",{className:"hotkey",children:"C"}),h.jsx("span",{children:"Show/Hide columns"})]})]})}function tv(){const{state:n,setState:l}=b.useContext(ht),[r,s]=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(Nr,{title:"🔢 Aggregations",show:r,onShow:()=>s(!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(kn,{width:20,height:20})})]}))}),h.jsxs("button",{className:ie.sidebarAddAction,onClick:()=>Ln("aggregate"),children:[h.jsx("span",{className:"hotkey",children:"A"}),h.jsx("span",{children:"Aggregate data"})]})]})}const $_=n=>(n==null?void 0:n.map(l=>l.value).join(", "))||"";function nv(){const{state:n}=b.useContext(ht),{removeFilter:l}=k1(),[r,s]=b.useState(!0),o=()=>{Ln("filters")};return h.jsxs("div",{className:ie.sectionContainer,children:[h.jsx(Nr,{title:"🎚️ Filters",show:r,onShow:()=>s(!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]," ",$_(u.value)]})]}),h.jsx("button",{className:ie.closeButton,onClick:()=>l(u),children:h.jsx(kn,{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 av(){const{toggle:n}=Q1(),{availableJoins:l}=b.useContext(oa),{state:r}=b.useContext(ht),[s,o]=b.useState(!0);return h.jsxs("div",{className:ie.sectionContainer,children:[h.jsx(Nr,{title:"📄 Joins",show:s,onShow:()=>o(!s),items:r.joins.length}),s&&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(kn,{width:20,height:20})})]},u.table+u.on))}),l.length>0&&h.jsxs("button",{onClick:()=>Ln("joins"),className:ie.sidebarAddAction,children:[h.jsx("span",{className:"hotkey",children:"J"}),h.jsx("span",{children:"Join table"})]})]})}function lv(){const{state:n,setState:l}=b.useContext(ht);if(!n.orderBy.length)return null;const r=s=>{l(o=>({...o,orderBy:o.orderBy.filter(u=>u.column!==s.column&&u.direction!==s.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((s,o)=>h.jsxs("div",{className:ie.card,children:[h.jsxs("div",{className:"overflow-hidden",children:[h.jsx("p",{className:se(ie.subText,"truncate"),children:s.direction}),h.jsx("p",{className:ie.text,children:s.column})]}),h.jsx("button",{className:ie.closeButton,onClick:()=>r(s),children:h.jsx(kn,{width:20,height:20})})]},o))})]})}const V1=()=>{const{state:n,setState:l}=b.useContext(ht),r=b.useCallback(o=>{l(u=>({...u,page:o}))},[l]),s=b.useCallback(o=>{l(u=>({...u,size:o}))},[l]);return{page:n.page,size:n.size,setSize:s,setPage:r}},X_=n=>dn({queryKey:["query",n],queryFn:async()=>{const{data:l}=await Ye.get("/queries/"+n);return l.data},enabled:!!n}),Z_=()=>fn({mutationFn:async n=>{const{data:l}=await Ye.post("/saved-queries",n);return l.data},onSuccess:()=>{yt.invalidateQueries(["queries"]),Ws()}}),J_=()=>fn({mutationFn:async n=>Ye.delete("/saved-queries/"+n),onSuccess:()=>{Ws()}}),P_=()=>fn({mutationFn:async({id:n,payload:l})=>{const{data:r}=await Ye.patch("/queries/"+n,l);return r.data},onSuccess:n=>{yt.invalidateQueries(["query",n.id]),Ws(),Y3(),n.isTrash}}),[I_,K1]=Pt(void 0),Ud=()=>K1(void 0);function W_(){return h.jsxs("div",{className:"flex items-center bg-white border-b border-gray-200 overflow-auto no-scrollbar",children:[h.jsx(e6,{}),h.jsx(n6,{}),h.jsx(a6,{})]})}function e6(){const{dataSourceId:n,name:l,tabId:r}=b.useContext(oa),{data:s}=Nu(n),{data:o}=b.useContext(Yn),u=Sr($t.EDITOR),d=Z_(),m=()=>{var p,g;(p=o==null?void 0:o.columns)!=null&&p[0].table&&ah({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&&Tu(r,p))};return cn("s",y,"Save query"),h.jsxs("div",{className:ne.tableConfig,children:[h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Manage filters",onClick:()=>Ln("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:()=>Ln("joins"),className:se(ne.tableAction,ne.blue),children:[h.jsx("span",{children:"Join"}),h.jsx("span",{className:"hotkey",children:"J"})]}),h.jsx(l6,{}),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(Lu,{width:16,height:16,className:"rotate-90"})]}),h.jsxs(Mu,{id:"explorer-more-actions",className:"z-10 shadow-md flex flex-col",clickable:!0,variant:"light",opacity:1,children:[h.jsxs("button",{onClick:()=>Ln("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:()=>Ln("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:()=>Ln("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:hh,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"})]}),(s==null?void 0:s.allowInsert)===!0&&h.jsx("button",{onClick:m,className:se(ne.tableAction,ne.modal,ne.blue),children:"Insert new row"})]})]})]})}const t6=[5,10,20,50,100,200];function n6(){const{name:n}=b.useContext(oa),{state:l}=b.useContext(ht),{refetch:r,data:s}=b.useContext(Yn),{size:o,setSize:u}=V1(),d=(window==null?void 0:window.location.hostname)!=="localhost",m=()=>{pl(n,l,!0),Ud()},y=()=>{if(s!=null&&s.queryHistoryId){const p=new URL(window.location.href);p.pathname=Xe.share.path,p.searchParams.set("shareId",s.queryHistoryId),navigator.clipboard.writeText(p.toString()),zt.success("Share link copied to clipboard")}};return cn("e",hh,"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"}),d&&h.jsx("button",{"data-tooltip-id":"default","data-tooltip-content":"Share query",onClick:y,className:se(ne.tableAction,ne.blue),children:"Share"}),h.jsx("button",{"data-tooltip-id":"default","data-tooltip-content":"Clone in a new tab",onClick:m,className:se(ne.tableAction,ne.blue),children:"Clone"}),h.jsxs("button",{"data-tooltip-id":"rows-num",className:se(ne.tableAction,ne.size,ne.blue),children:[h.jsxs("span",{className:"whitespace-nowrap",children:[o," rows"]}),h.jsx(Lu,{width:16,height:16,className:"rotate-90"})]}),h.jsx(Mu,{id:"rows-num",className:"z-10 shadow-md flex",clickable:!0,variant:"light",opacity:1,children:t6.map(p=>h.jsx("button",{onClick:()=>u(p),className:se(ne.tableAction,ne.blue),children:h.jsx("span",{children:p})}))})]})}function a6(){const{page:n,size:l,setPage:r}=V1(),{data:s}=b.useContext(Yn),o=(s==null?void 0:s.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 l6(){const{state:n,setState:l}=b.useContext(ht),r=()=>{l(o=>({...o,searchAll:void 0}))},s=()=>{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 cn("k",s,"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:s,className:se(ne.tableAction,ne.blue),children:[h.jsx("span",{className:"whitespace-nowrap",children:"Search text"}),h.jsx("span",{className:"hotkey",children:"K"})]})}const s6="_drop-container_745yh_2",i6="_item_745yh_2",sv={dropContainer:s6,item:i6},Ld=({dataSourceId:n,focusId:l,placeholder:r="Column",onChange:s,value:o,autoFocus:u,allowTables:d})=>{const{data:m}=ei(n),y=b.useRef(null),p=b.useMemo(()=>{if(!m)return[];let _=m;return d&&(_=m.filter(R=>d.includes(R.tableName))),_.flatMap(R=>R.columns.map(D=>({value:R.tableName+"."+D.name,label:D.name,table:R.tableName,searchValue:D.name.toLowerCase()})))},[m,d]),g=b.useMemo(()=>{const _=o.toLowerCase()||"",R=[];for(let D=0;D<p.length&&R.length<10;D++)p[D].searchValue.includes(_)&&R.push(p[D]);return R},[p,o]),[S,w]=b.useState(!1),[C,E]=b.useState(0),A=_=>{var R;if(_.key==="ArrowDown")_.preventDefault(),E(D=>(D+1)%g.length);else if(_.key==="ArrowUp")_.preventDefault(),E(D=>(D-1+g.length)%g.length);else if(_.key==="Enter"&&C>=0&&C<g.length){_.preventDefault();const D=g[C].value;w(!1);const Y=p.findIndex(H=>H.value===D)>-1;s(((R=g[C])==null?void 0:R.value)||D,Y,!0)}};b.useEffect(()=>{var R;const _=(R=y.current)==null?void 0:R.querySelector('[data-is-active="true"]');_&&_.scrollIntoView({behavior:"smooth",block:"nearest"})},[C]);const j=_=>{const R=_.currentTarget.value,D=p.findIndex(Y=>Y.value===R)>-1;s(R,D,!1)};return h.jsxs("div",{className:"relative",onFocus:()=>w(!0),onBlur:()=>w(!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:sv.dropContainer,ref:y,tabIndex:-1,children:g.map((_,R)=>h.jsxs("div",{className:sv.item,"data-is-active":C===R,onMouseDownCapture:D=>{D.preventDefault(),w(!1),s(_.value,!0,!0)},children:[h.jsx("span",{className:"text-xs font-semibold truncate",children:_.table}),h.jsx("p",{className:"truncate text-sm",children:_.label})]},R))})]})},r6="_drop-container_a7zi8_2",o6="_item_a7zi8_2",iv={dropContainer:r6,item:o6};function u6(n){return c4.includes(n)?r4:f4.includes(n)?i4:d4.includes(n)?o4:Id}const c6=({value:n,onChange:l,autoFocus:r,focusId:s,colType:o})=>{const u=b.useMemo(()=>{const w=n.toLowerCase()||"";return u6(o||"").filter(C=>C.label.includes(w))},[n,o]),d=b.useRef(null),[m,y]=b.useState(!1),[p,g]=b.useState(0),S=w=>{var C;w.key==="ArrowDown"?(w.preventDefault(),g(E=>(E+1)%u.length)):w.key==="ArrowUp"?(w.preventDefault(),g(E=>(E-1+u.length)%u.length)):w.key==="Enter"&&(p>=0&&p<u.length?(w.preventDefault(),y(!1),l(((C=u[p])==null?void 0:C.label)||"",!0)):l(n,!0))};return b.useEffect(()=>{var C;const w=(C=d.current)==null?void 0:C.querySelector('[data-is-active="true"]');w&&w.scrollIntoView({behavior:"smooth",block:"nearest"})},[p]),h.jsxs("div",{className:"relative",children:[h.jsx("input",{onKeyDown:S,value:n,onChange:w=>l(w.target.value,!1),className:"input w-full",placeholder:"Operator",autoFocus:r,onFocus:()=>y(!0),onBlur:()=>y(!1),"data-focus":s}),m&&u.length>0&&h.jsx("ul",{className:iv.dropContainer,ref:d,tabIndex:-1,children:u.map((w,C)=>h.jsx("li",{className:iv.item,"data-is-active":p===C,onMouseDownCapture:E=>{E.preventDefault(),y(!1),l(w.label,!0)},children:w.label},C))})]})},f6="_actions_14av2_2",d6="_filter-actions_14av2_2",G1={actions:f6,filterActions:d6},h6=["=","<",">",">=","<>","!=","<="];function m6(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 zt.error(`Filter #${l+1} has invalid column value`),!1;const s=eh[r.operator];if(!s)return zt.error(`Filter #${l+1} has invalid operator`),!1;if(r.isColumnRef&&!h6.includes(s))return zt.error(`Filter #${l+1} cannot reference another column because it uses '${r.operator}' operator`),!1}return!0}function p6(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 s=eh[r.operator];l.push({id:r.id,value:r.isColumnRef?[{value:r.value,isColumn:!0}]:u4(s,r.value),operator:s,column:r.column,isEnabled:!0,connector:"AND"})}),l}function y6(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 v6=({filter:n,dataSourceId:l,allowedTables:r,inspections:s,autoFocus:o,onChangeColumn:u,onChangeOperator:d,onChangeValue:m,onRemoveFilter:y,onIsColumnChange:p})=>{const g=b.useMemo(()=>{if(!s)return"";let S=null;for(const w of s)for(const C of w.columns)w.tableName+"."+C.name===n.column&&(S=C);return S!=null&&S.type?S.type:""},[n.column,s]);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(c6,{onChange:S=>d(n.id,S),focusId:"operator",colType:g,value:n.operator})}),g1(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:G1.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 filter",className:"p-0.5 text-sm cursor-pointer",onClick:()=>y(n.id),children:h.jsx(kn,{width:20,height:20,className:"text-red-600"})})]})]})},g6=()=>{const{state:n}=b.useContext(ht),{setFilters:l}=k1(),r=zu(A=>A.filters),{data:s}=ei(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(R=>R.id===A?{...R,column:j}:R)])},y=(A,j)=>{d(_=>[..._.map(R=>R.id===A?{...R,operator:j}:R)])},p=(A,j)=>{d(_=>[..._.map(R=>R.id===A?{...R,value:j}:R)])},g=()=>{d(A=>[...A,{id:Ua(),value:"",column:"",operator:"",isColumnRef:!1}])},S=(A,j)=>{d(_=>[..._.map(R=>R.id===A?{...R,isColumnRef:j}:R)])},w=A=>{d(j=>j.filter(_=>_.id!==A))},C=()=>qu("filters"),E=()=>{m6(u)&&(l(p6(u)),C())};return b.useEffect(()=>{if(!r){d([]);return}d(()=>{const A=n.filters.map(j=>{var _,R;return{id:j.id,value:y6(j),column:j.column,operator:Wd[j.operator],isColumnRef:!!((R=(_=j.value)==null?void 0:_[0])!=null&&R.isColumn)}});return A.push({id:Ua(),value:"",column:"",operator:"",isColumnRef:!1}),A})},[r]),cn("f",()=>{mu("filters")},"Add new filter"),cn("ctrl+f",()=>{alert("Save filters")},"Save filters"),h.jsxs(It,{isVisible:r,onClose:C,portal:!0,children:[h.jsx(Qn,{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(v6,{filter:A,dataSourceId:n.dataSourceId,allowedTables:o,inspections:s||[],onChangeColumn:m,onChangeOperator:y,onChangeValue:p,onRemoveFilter:w,onIsColumnChange:S,autoFocus:j===u.length-1},A.id))]}),h.jsxs("div",{className:G1.actions,children:[h.jsx("button",{className:"button tertiary",onClick:g,children:"Add filter"}),h.jsx("button",{className:"button primary",onClick:E,children:"Apply filters"})]})]})},b6="_card_7tspz_2",x6="_cards-list_7tspz_2",S6="_join-modal_7tspz_2",w6="_close-button_7tspz_2",Qo={card:b6,cardsList:x6,joinModal:S6,closeButton:w6},E6=()=>{const{isFetching:n}=b.useContext(Yn),l=zu(p=>p.joins),{toggle:r,joins:s}=Q1(),{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=()=>qu("joins");return cn("j",()=>{o.length>0?Ln("joins"):zt.error("No available tables to join")},"Add new join"),h.jsxs(It,{isVisible:l,onClose:y,portal:!0,children:[h.jsx(Qn,{onClick:y}),h.jsxs("div",{className:Qo.joinModal,children:[h.jsx("h2",{className:"text-lg font-semibold mb-4",children:"Join table"}),s.length>0&&h.jsx("div",{className:Qo.cardsList,children:s.map((p,g)=>h.jsxs("div",{className:Qo.card,children:[h.jsxs("p",{className:"text-sm truncate",children:[p.table," on ",p.on]}),g===s.length-1&&h.jsx("button",{className:Qo.closeButton,onClick:()=>r(p),disabled:n,children:h.jsx(kn,{width:20,height:20})})]},p.table+p.on))}),o.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(H1,{hook:p,onClick:()=>{n||(r({table:p.on.toTable,type:"LEFT",on:p.where}),d(""))}},p.where))})]})]})};function C6(n){return n.reduce((l,r)=>(l[r]=!0,l),{})}function rv(n){return n.reduce((l,r)=>(l[r]=!0,l),{})}const _6="_container_18lan_2",N6="_column-label_18lan_2",j6="_not-active_18lan_2",Wo={container:_6,columnLabel:N6,notActive:j6};function A6(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}],h4[r.type]&&["YEAR","MONTH","DAY"].forEach(s=>{l[r.table].push({value:s+" "+r.full,ogColumn:r.column,label:s+" "+hl(r.column),type:"number",nested:!0})})}),Object.entries(l).reduce((r,[s,o])=>(r.push({name:hl(s),columns:o}),r),[])}function T6(n,l){const r=l.toLowerCase();return n.map(s=>{const o=s.columns.filter(u=>u.label.toLowerCase().includes(r)||u.ogColumn.toLowerCase().includes(r));return{...s,columns:o}}).filter(s=>s.columns.length>0)}const R6=({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),O6={columns:"c",groupBy:"g"},ov=({mode:n})=>{const l=zu(_=>_[n]),{allColumns:r}=b.useContext(oa),{state:s,setState:o}=b.useContext(ht),[u,d]=b.useState({}),[m,y]=b.useState(""),p=b.useMemo(()=>A6(r),[r]),g=s.aggregations.length>0||s.groupBy.length>0,S=b.useMemo(()=>m?T6(p,m):p,[m,p]),w=_=>{d(R=>({...R,[_.target.name]:_.target.checked}))},C=_=>{const R=_.target.checked;d(D=>{for(const Y of r)D[Y.full]=R;return{...D}})},E=()=>{qu(n)},A=()=>{const _=[];for(const[R,D]of Object.entries(u))if(D){const[Y,H]=R.split(" ");_.push({value:H||Y,fn:H?Y:void 0})}o(R=>({...R,[n]:_})),E()},j=b.useMemo(()=>{for(const _ of r)if(!u[_.full])return!1;return!0},[u,r]);return cn(O6[n],()=>{n==="columns"?g?zt.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(()=>C6(s[n].map(_=>_.fn?_.fn+" "+_.value:_.value)))},[l,d]),h.jsxs(It,{isVisible:l,onClose:E,portal:!0,children:[h.jsx(Qn,{onClick:E}),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(R=>h.jsx(R6,{column:R,selected:u,onCheck:w},R.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:E,children:"Cancel"}),h.jsx("button",{className:"button primary",onClick:A,children:"Apply"})]})]})]})},D6="_options-container_15aey_2",M6={optionsContainer:D6},cd="COUNT all",U6=n=>n.distinct?[n.fn,"DISTINCT",n.value].join(" "):[n.fn,n.value].join(" "),L6=()=>{const n=zu(E=>E.aggregate),{dataSourceId:l}=b.useContext(oa),{setState:r,state:s}=b.useContext(ht),{data:o}=b.useContext(Yn),[u,d]=b.useState({fn:"",col:""}),m=E=>d({...u,fn:E.currentTarget.value}),y=E=>d({...u,col:E}),p=()=>qu("aggregate"),g=()=>{const E=u.fn===cd?{value:"*",fn:"COUNT"}:{fn:u.fn,value:u.col,distinct:u.fn==="COUNT"};r(A=>({...A,aggregations:[...A.aggregations,E]}))},S=u.fn===cd,w=S?!1:!u.col||!u.fn,C=E=>{const A=ta(E);r(j=>({...j,aggregations:j.aggregations.filter(_=>_.fn!==E.fn||_.value!==E.value),orderBy:j.orderBy.filter(_=>_.column!==A)}))};return cn("a",()=>{mu("aggregate")},"Aggregate data"),h.jsxs(It,{isVisible:n,onClose:p,backdropClose:!0,portal:!0,children:[h.jsx(Qn,{onClick:p}),h.jsxs("div",{children:[h.jsx("h2",{className:"text-lg font-semibold",children:"Aggregate"}),Zl(s.aggregations.length,0)&&h.jsx("div",{className:"flex flex-col gap-1 mt-4",children:s.aggregations.map((E,A)=>h.jsxs("p",{className:"p-2 rounded-md bg-gray-50 flex items-center justify-between",children:[h.jsx("span",{children:U6(E)}),h.jsx("button",{tabIndex:-1,"data-tooltip-id":"default","data-tooltip-content":"Remove aggregation",className:"p-0.5 text-sm cursor-pointer",onClick:()=>C(E),children:h.jsx(kn,{width:20,height:20,className:"text-red-600"})})]},A))}),h.jsxs("div",{className:M6.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:w,onClick:g,children:"Add"})]})]})]})},F1=({options:n,updater:l,name:r,tabId:s})=>{const o=y4(n,l),{state:u}=o,d=iE({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=p4(d.data,n.dataSourceId,r,s);return h.jsx(oa,{value:m,children:h.jsx(ht,{value:o,children:h.jsxs(Yn,{value:d,children:[h.jsx(W_,{}),h.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[h.jsxs("div",{className:"m-2 flex-1 overflow-auto pb-24 lg:pb-12 no-scrollbar",children:[h.jsx("div",{className:"pb-0.5 sticky bottom-0"}),h.jsx(y_,{})]}),h.jsx(g6,{}),h.jsx(E6,{}),h.jsx(ov,{mode:"columns"}),h.jsx(ov,{mode:"groupBy"}),h.jsx(L6,{}),h.jsx(F_,{})]})]})})})},z6=({tab:n})=>{const l=b.useCallback(r=>{ju(s=>s.map(o=>o.id!==n.id?o:{...o,options:r(o.options)}))},[n]);return h.jsx(F1,{updater:l,options:n.options,name:n.label,tabId:n.id})},q6=({content:n,activeAnchor:l})=>{if(!l)return null;const r=l.getAttribute("data-tab-id"),s=Au.get().find(d=>d.id===r),o=UC(s==null?void 0:s.options.dataSourceId);if(!s)return n;const u=()=>{Pl("New tab name",s.label).then(d=>{d&&Tu(s.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:s.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:s.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})]}),s.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:s.options.joins.map(d=>d.table).join(", ")})]}),s.options.filters.length>0&&h.jsxs("div",{className:ea.tooltipInfoEntry,children:[h.jsx("p",{className:"text-sm",children:"filters"}),s.options.filters.map(d=>h.jsx("p",{className:"truncate font-semibold",children:eE(d)}))]})]})},B6=()=>{const n=g4(),l=b1(),r=dh(Uu.laptop),s=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&&Uy(y)},u=m=>{m.button===1&&Uy(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&&Tu(m,p)})};return l.length<1?h.jsx(a2,{to:"/"}):h.jsxs("div",{className:"h-screen max-h-screen bg-(--bg) flex flex-col",children:[r&&h.jsx(Mu,{id:"tab",render:q6,className:"z-10 shadow-md p-0!",offset:-1,noArrow:!0,opacity:1,variant:"light",clickable:!0,delayShow:500}),s&&h.jsx(z6,{tab:s}),h.jsx("div",{className:se(ea.tabs,"no-scrollbar",!r&&ea.mobile),children:l==null?void 0:l.map(m=>h.jsxs("div",{onClick:()=>x1(m.id),className:se(ea.tab,m.id===(s==null?void 0:s.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(kn,{width:20,height:20})})]},m.id))})]})},H6=()=>{const n=I_(),l=b.useCallback(r=>{K1(s=>s?{...s,options:r(s.options)}:(zt.error("Something went wrong."),s))},[]);return n?h.jsxs(It,{isVisible:!0,onClose:Ud,children:[h.jsx(Qn,{onClick:Ud}),h.jsx("div",{className:"border border-gray-200 bg-(--bg) flex flex-col",children:h.jsx(F1,{name:n.label,options:n.options,updater:l})})]}):null},k6="_root_11tnh_2",Q6="_down_11tnh_2",Y6="_chevron_11tnh_2",V6="_table-name-container_11tnh_2",K6="_link_11tnh_2",G6="_table-name_11tnh_2",F6="_ul_11tnh_2",$6="_column-type_11tnh_2",Ra={root:k6,down:Q6,chevron:Y6,tableNameContainer:V6,link:K6,tableName:G6,ul:F6,columnType:$6},[ij,X6]=Pt(!1),$1=()=>X6(!1),Z6=new Intl.DateTimeFormat("en",{dateStyle:"full",timeStyle:"long"});function J6(n,l){if(l&&n.toLowerCase().includes(l))return"bg-yellow-200"}const P6=({insp:n,filter:l,expanded:r})=>{const s=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:s.map(o=>h.jsx(h.Fragment,{children:h.jsxs("li",{children:[o.isPrimary?"🔐":"🏷️"," ",h.jsx("span",{className:J6(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 I6({id:n}){const{data:l}=Nu(n),{data:r}=ei(n),s=Jt(),{pathname:o}=Nt(),u=X3(),d=p1(),m=Z3(),y=b.useMemo(()=>l!=null&&l.lastInspected?Z6.format(new Date(l.lastInspected)):"--",[l]),[p,g]=b.useState({}),[S,w]=b.useState(""),[C,E]=b.useState("table"),A=Sr($t.EDITOR),j=S.toLowerCase(),_=b.useMemo(()=>{if(!j||!r)return r||[];const I=[];for(const re of r){if(re.tableName.toLowerCase().includes(j)){I.push(re);continue}C!=="table"&&re.columns.findIndex(pe=>pe.name.toLowerCase().includes(j))>=0&&I.push(re)}return I},[j,r,C]),R=I=>{g(re=>({...re,[I]:!re[I]}))},D=I=>{pl(I,{table:I,dataSourceId:n},!0),Ys(void 0),$1(),o!==Xe.workbench.path&&s(Xe.workbench.path)},Y=()=>{d.mutate(n)},H=async()=>{const I=await Pl("Enter name",l==null?void 0:l.name);I&&u.mutate({id:n,dataSource:{name:I}})},$=async()=>{await E1("Are you sure you want to delete this data source?")&&(m.mutate(n),Ys(void 0))},W=C==="column";return h.jsxs("div",{className:Ra.root,children:[h.jsxs("h3",{className:"page-head flex gap-2",children:[l&&h.jsx(nh,{size:32,type:l.dbType}),h.jsx("span",{className:"truncate",children:l==null?void 0:l.name})]}),h.jsx("p",{className:"mt-2 text-xs text-gray-800",children:"Last DB inspection"}),h.jsx("p",{className:"text-sm font-semibold",children: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-2 items-center mb-2 mt-4",children:[h.jsxs("select",{className:"input",value:C,onChange:I=>E(I.currentTarget.value),children:[h.jsx("option",{value:"table",children:"Table"}),h.jsx("option",{value:"column",children:"Column"})]}),h.jsx("input",{className:"input flex-1 bg-gray-50",placeholder:W?"Search column":"Search table",value:S,onChange:I=>w(I.target.value),autoFocus:!0})]}),h.jsx("div",{className:"overflow-y-auto",children:_==null?void 0:_.map(I=>h.jsxs("div",{children:[h.jsxs("div",{className:Ra.tableNameContainer,children:[h.jsx("button",{className:se(Ra.chevron,p[I.id]&&Ra.down),onClick:()=>R(I.id),children:h.jsx(Lu,{width:16,height:16})}),h.jsx("button",{className:se(Ra.tableName,"flex-1"),onClick:()=>R(I.id),children:I.tableName}),h.jsx("button",{className:Ra.link,onClick:()=>D(I.tableName),children:"↗️"})]}),(p[I.id]||S.length>0)&&h.jsx(P6,{insp:I,filter:W?j:"",expanded:p[I.id]})]},I.id))})]})}const W6=()=>{const n=G4(),[l,r]=b.useState(void 0);b.useEffect(()=>{n&&r(n)},[n]);const s=()=>Ys(void 0);return h.jsx(Y1,{isVisible:n!=null,onClose:s,onClosed:()=>r(void 0),backdropClose:!0,children:l&&h.jsx(I6,{id:l})})};function eN(n,l=500){const[r,s]=b.useState(n);return b.useEffect(()=>{const o=setTimeout(()=>s(n),l);return()=>clearTimeout(o)},[n,l]),r}const tN="_search_1vn45_2",nN="_entry_1vn45_2",aN="_ds_1vn45_2",lN="_ds-entry_1vn45_2",Yo={search:tN,entry:nN,ds:aN,dsEntry:lN},[sN,iN]=th({initialData:[],localStorageKey:"selected-data-sources-v1"}),rN=n=>iN(l=>{const r=l.indexOf(n);return r>-1?(l.splice(r,1),[...l]):[...l,n]}),oN={table:"📄",query:"📖"},uN=({onTable:n,onQuery:l,autoFocus:r})=>{const[s,o]=b.useState(""),[u,d]=b.useState(-1),m=eN(s,200),y=sN(),{data:p}=ia(),{data:g}=Pd({teamId:p==null?void 0:p.teamId}),S=b.useMemo(()=>{const _=[],R=rv(y);if(!g||g.length===0)return[];for(const D of g)R[D.id]&&_.push(D.id);return _},[y,g]),{data:w}=V3(m,{teamId:p==null?void 0:p.teamId,selectedDataSources:S}),C=_=>{_.type==="table"?n(_.name,_.dataSourceId):_.type==="query"&&l(_.id,_.dataSourceId)},E=_=>{var R;w&&(_.key==="ArrowDown"?(_.preventDefault(),d(D=>(D+1)%w.length)):_.key==="ArrowUp"?(_.preventDefault(),d(D=>(D-1+w.length)%w.length)):_.key==="Enter"&&u>=0&&(R=w[u])!=null&&R.name&&(_.preventDefault(),C(w[u])))},A=_=>{const R=_.currentTarget.dataset.tableId,D=w==null?void 0:w.find(Y=>Y.id===R);D&&C(D)},j=b.useMemo(()=>rv(y),[y]);return h.jsxs("div",{className:"overflow-hidden flex flex-col w-full lg:w-lg",children:[Zl(g==null?void 0:g.length,0)&&h.jsx("div",{className:"flex overflow-x-auto mb-2 gap-2 no-scrollbar",children:g.map(_=>h.jsxs("label",{className:Yo.dsEntry,children:[h.jsx("input",{type:"checkbox",checked:j[_.id]===!0,onChange:()=>rN(_.id)}),h.jsx("span",{children:_.name})]},_.id))}),h.jsx("input",{className:Yo.search,placeholder:"Search table or saved query to start from",value:s,onChange:_=>o(_.target.value),onKeyDown:E,autoFocus:r}),Zl(w==null?void 0:w.length,0)&&h.jsx("div",{className:"overflow-y-auto max-h-full mt-2",children:w.map((_,R)=>h.jsxs("button",{className:Yo.entry,"data-is-active":u===R,"data-table-id":_.id,onClick:A,children:[h.jsxs("p",{className:"font-semibold",children:[oN[_.type]," ",_.name]}),h.jsxs("p",{className:Yo.ds,children:["📦 ",_.dataSourceName]})]},_.id))})]})},cN=()=>{const n=E4(),l=(o,u)=>{n==null||n.onConfirm("table",o,u)},r=(o,u)=>{n==null||n.onConfirm("query",o,u)},s=()=>{n==null||n.onCancel()};return h.jsxs(It,{isVisible:!!n,onClose:s,children:[h.jsx(Qn,{onClick:s}),h.jsx(uN,{autoFocus:!0,onTable:l,onQuery:r})]})},fN=()=>{const n=Nt();b.useEffect(()=>{},[n.pathname])},[dN,X1]=Pt(!1),fd=()=>X1(!1),Z1=()=>X1(!0),hN=({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,mN=()=>{const n=dN(),{data:l}=ia(),{mutateAsync:r,isLoading:s}=J3(),o=Jt(),[{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(),zt.success("Password successfully updated!")})},w=u.length<8||u!==d||s,C=y.includes("password");return h.jsxs(It,{isVisible:n,onClose:fd,children:[h.jsx(Qn,{onClick:fd}),h.jsxs("div",{className:"w-full lg:w-lg flex flex-col gap-2",children:[h.jsx(w1,{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(hN,{password:u,repeatPassword:d}),h.jsxs("div",{className:"flex justify-end gap-2 mt-2",children:[h.jsx("button",{className:"button tertiary",disabled:w,onClick:S,children:"Update password"}),h.jsx("button",{className:"button danger",onClick:g,children:"Log out"})]})]})]})},[pN,J1]=Pt(!1),P1=()=>J1(!0),uv=()=>J1(!1),yN=n=>dn({queryKey:["team-users"],queryFn:async()=>{const{data:l}=await Ye.get("/teams/"+n+"/users");return l.data},enabled:!!n}),vN=()=>fn({mutationFn:async({role:n,teamId:l,userId:r})=>(await Ye.patch("/teams/"+l+"/user-role",{role:n,userId:r}),!0),onSuccess:()=>{yt.invalidateQueries({queryKey:["team-users"]})}}),gN=()=>fn({mutationFn:async({teamId:n,userId:l})=>(await Ye.delete("/teams/"+n,{params:{userId:l}}),!0),onSuccess:()=>{yt.invalidateQueries({queryKey:["team-users"]})}}),bN="_user-entry_jtuip_2",xN={userEntry:bN},SN=()=>{const n=pN(),{data:l}=ia(),{data:r}=yN(l==null?void 0:l.teamId),{mutate:s,isLoading:o}=P3(),{mutate:u,isLoading:d}=vN(),{mutate:m,isLoading:y}=gN(),[p,{change:g,reset:S}]=wr({password:"",username:""}),w=()=>{s({username:p.username,password:p.password,teamId:(l==null?void 0:l.teamId)||""}),S()},C=(_,R)=>{u({teamId:l.teamId,role:R,userId:_})},E=_=>{E1("Are you sure you want to remove this user?").then(R=>{R&&m({userId:_,teamId:l.teamId})})},A=Sr($t.ADMIN),j=o||d||y;return h.jsxs(It,{isVisible:n,onClose:uv,backdropClose:!0,children:[h.jsx(Qn,{onClick:uv}),h.jsxs("div",{className:"w-full lg:w-lg flex flex-col overflow-hidden",children:[h.jsx(w1,{children:"Manage users"}),Zl(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:xN.userEntry,children:[h.jsxs("select",{className:"input",value:_.role,disabled:!A||j,onChange:R=>C(_.id,R.currentTarget.value),children:[h.jsx("option",{value:$t.OWNER,children:"Owner"}),h.jsx("option",{value:$t.ADMIN,children:"Admin"}),h.jsx("option",{value:$t.EDITOR,children:"Editor"}),h.jsx("option",{value:$t.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:()=>E(_.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:w,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."})]})]})]})},wN=()=>{const[n,l]=b.useState(""),[r,s]=b.useState(""),[o,u]=b.useState(),[d,m]=b.useState(!1),y=Jt(),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=>s(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?"})]})})})},EN=()=>{const n=Jt(),{pathname:l}=Nt(),{data:r,isLoading:s}=y1();b.useEffect(()=>{!r&&!s&&l!==Xe.login.path&&n(Xe.login.path)},[r,s,n,l])},CN=()=>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..."})]}),_N=()=>{const[n]=L2(),l=Jt(),{data:r,isLoading:s,isError:o}=X_(n.get("shareId"));return b.useEffect(()=>{var u;r&&(pl(r.name,{...r.opts,dataSourceId:(u=r.dataSource)==null?void 0:u.id},!0),l(Xe.workbench.path,{replace:!0}))},[r]),h.jsxs("div",{className:"page-container flex items-center justify-center h-screen",children:[s&&h.jsxs("div",{className:"flex items-center flex-col gap-2",children:[h.jsx(CN,{}),h.jsx("p",{children:"Fetching query information"})]}),o&&h.jsx(Lt,{variant:"danger",children:"Failed to load query information"})]})};function NN(){return B_(),fN(),EN(),h.jsxs(h.Fragment,{children:[h.jsxs(s2,{children:[h.jsx(ir,{path:Xe.home.path,element:h.jsx(P4,{})}),h.jsx(ir,{path:Xe.workbench.path,element:h.jsx(B6,{})}),h.jsx(ir,{path:Xe.login.path,element:h.jsx(wN,{})}),h.jsx(ir,{path:Xe.share.path,element:h.jsx(_N,{})})]}),h.jsx(H6,{}),h.jsx(fE,{}),h.jsx(SE,{}),h.jsx(UE,{}),h.jsx(W6,{}),h.jsx(cN,{}),h.jsx(mN,{}),h.jsx(SN,{}),h.jsx(TE,{}),h.jsx(CE,{})]})}const jN="_desktop-layout_svwiu_2",AN="_mobile-layout_svwiu_2",TN="_nav_svwiu_2",RN="_main_svwiu_2",ON="_header_svwiu_2",Gs={desktopLayout:jN,mobileLayout:AN,nav:TN,main:RN,header:ON},DN="_container_1y5b4_2",MN="_menu_1y5b4_2",ph={container:DN,menu:MN},UN=({name:n,id:l,onRename:r,onDelete:s,onOpen:o})=>{const u=q1();return h.jsxs("button",{className:ph.menu,onContextMenu:u.open,onClick:()=>o(l),children:[h.jsx(B1,{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(),s(l)},className:"context-menu-item",children:"🗑️ Delete"})]})}),h.jsxs("span",{children:["📖 ",n]})]})},LN=({dataSource:n,index:l})=>{const r=()=>{Ys(n.id)};return cn(l.toString(),()=>{Ys(s=>{if(s!==n.id)return n.id})},n.name),h.jsxs("button",{className:ph.menu,onClick:r,children:[h.jsx(nh,{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})]})},zN=()=>{const n=Jt(),l=Nt(),{data:r}=ia(),{data:s}=k3(r==null?void 0:r.teamId),{data:o}=Q3(r==null?void 0:r.teamId),u=P_(),d=J_(),m=g=>{S1(g).then(S=>{var w;pl(S.name,fr({...S.opts,dataSourceId:(w=S.dataSource)==null?void 0:w.id}),!0),l.pathname!==Xe.workbench.path&&n(Xe.workbench.path)})},y=async g=>{const S=o==null?void 0:o.find(C=>C.id===g),w=await Pl("New name?",S==null?void 0:S.name);w&&u.mutate({id:g,payload:{name:w}})},p=g=>{var w;const S=(w=o==null?void 0:o.find(C=>C.id===g))==null?void 0:w.savedQueryId;S&&d.mutate(S)};return h.jsx("div",{className:ph.container,children:h.jsxs("div",{className:"flex-1 overflow-y-auto",children:[Zl(s==null?void 0:s.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"}),s.map((g,S)=>h.jsx(LN,{dataSource:g,index:S+1},g.id))]}),Zl(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(g=>h.jsx(UN,{onDelete:p,onRename:y,onOpen:m,name:g.name,id:g.id},g.savedQueryId))]})]})})},qN=()=>{const n=Jt(),{pathname:l}=Nt(),{data:r}=ia(),s=xr("Desktop nav"),o=()=>{$1(),l!==Xe.home.path&&n(Xe.home.path)};return h.jsxs("nav",{className:Gs.nav,children:[r&&h.jsxs("div",{className:Gs.header,children:[h.jsxs("button",{onClick:o,className:"flex justify-between items-center",children:[h.jsx("span",{children:"🏠 Home"}),h.jsx("span",{className:"hotkey",children:"H"})]}),h.jsxs("button",{onClick:s,className:"flex justify-between items-center",children:[h.jsx("span",{children:"🔎 New query"}),h.jsx("span",{className:"hotkey",children:"N"})]}),h.jsxs("button",{onClick:Z1,children:["🪪 ",r.username]}),h.jsx("button",{onClick:P1,children:"👥 Manage users"})]}),h.jsx(zN,{})]})},BN="_root_iws5j_2",HN={root:BN},kN=()=>{const{pathname:n}=Nt(),l=Jt(),r=xr("Mobile nav"),s=()=>{n!==Xe.home.path&&l(Xe.home.path)};return h.jsxs("div",{className:HN.root,children:[h.jsxs("button",{onClick:s,children:[h.jsx("p",{children:"🏠"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Home"})]}),h.jsxs("button",{onClick:r,children:[h.jsx("p",{children:"🔎"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"New query"})]}),h.jsxs("button",{onClick:Z1,children:[h.jsx("p",{children:"🪪"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Account"})]}),h.jsxs("button",{onClick:P1,children:[h.jsx("p",{children:"👥"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Users"})]})]})},QN=({children:n,isLogin:l})=>h.jsxs("div",{className:Gs.desktopLayout,children:[h.jsx(Mu,{id:"default",className:"z-100"}),!l&&h.jsx(qN,{}),h.jsx("main",{className:Gs.main,children:n})]}),YN=({children:n,isLogin:l})=>h.jsxs("div",{className:Gs.mobileLayout,children:[h.jsx("main",{className:Gs.main,children:n}),!l&&h.jsx(kN,{})]}),VN=({children:n})=>{const l=dh(Uu.laptop),{pathname:r}=Nt(),s=r===Xe.login.path;return l?h.jsx(QN,{isLogin:s,children:n}):h.jsx(YN,{isLogin:s,children:n})};hx.createRoot(document.getElementById("root")).render(h.jsxs(Ke.StrictMode,{children:[h.jsx(q3,{}),h.jsx(fS,{client:yt,children:h.jsx(R2,{children:h.jsx(VN,{children:h.jsx(NN,{})})})})]}));