semaphor 0.0.32 → 0.0.33

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.
@@ -51137,7 +51137,7 @@ function mP() {
51137
51137
  ]
51138
51138
  }
51139
51139
  ),
51140
- t ? e.type === "kpi" ? /* @__PURE__ */ w.jsx("div", { className: "grow flex items-center justify-center ", children: /* @__PURE__ */ w.jsx("div", { className: " border rounded-md", children: /* @__PURE__ */ w.jsx(yD, { isLoading: n, card: e }) }) }) : /* @__PURE__ */ w.jsx(iA, { className: "grow border-none shadow-none " }) : /* @__PURE__ */ w.jsx("div", { className: "w-full mt-4 px-6 bg-red-x00 grow border-none shadow-none overflow-y-auto ", children: e.data && e.data.length > 0 && /* @__PURE__ */ w.jsx(r1, { data: e.data }) })
51140
+ t ? e.type === "kpi" ? /* @__PURE__ */ w.jsx("div", { className: "grow flex items-center justify-center ", children: /* @__PURE__ */ w.jsx("div", { className: " w-1/2 border rounded-md", children: /* @__PURE__ */ w.jsx(yD, { isLoading: n, card: e }) }) }) : /* @__PURE__ */ w.jsx(iA, { className: "grow border-none shadow-none " }) : /* @__PURE__ */ w.jsx("div", { className: "w-full mt-4 px-6 bg-red-x00 grow border-none shadow-none overflow-y-auto ", children: e.data && e.data.length > 0 && /* @__PURE__ */ w.jsx(r1, { data: e.data }) })
51141
51141
  ] }) : /* @__PURE__ */ w.jsx(w.Fragment, { children: "No Active Card" });
51142
51142
  }
51143
51143
  function Ade() {
@@ -497,4 +497,4 @@ SELECT label, measure FROM table
497
497
  Table Columns: ${g==null?void 0:g.map(G=>`${G.column_name} | ${G.data_type}`).join(", ")}
498
498
  User SQL: ${p}
499
499
  `,x=` When the user asks for a specific chart please use the following query structure to generate the chart query. Do not make up the column names. Use only the table columns provided above for the query. Replace x-axis, y-axis, and lables with the appropriate column names.
500
- Visual Query Syntax: ${dre}`,{data:w,isLoading:S,isFetching:C,isError:P,refetch:O}=vi({queryKey:["ai-query"],queryFn:()=>al("https://semaphor.cloud/api/v1/ai",(s==null?void 0:s.accessToken)||"",{user_content:`userContent: ${y} ${a?x:""}`}),enabled:!1});function k(G){if(G.toLowerCase().includes("bar"))f("bar");else if(G.toLowerCase().includes("line"))f("line");else if(G.toLowerCase().includes("bubble"))f("bubble");else if(G.toLowerCase().includes("scatter"))f("scatter");else if(G.toLowerCase().includes("stacked"))f("stackedBar");else if(G.toLowerCase().includes("pie"))f("pie");else if(G.toLowerCase().includes("donut")||G.toLowerCase().includes("doughnut"))f("doughnut");else if(G.toLowerCase().includes("radar"))f("radar");else return f("bar"),!1;return!0}function M(){n&&(k(n)&&l(!0),O())}m.useEffect(()=>{i&&(M(),o(!1))},[i,o]);const N={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"5px",width:"100%"},F={fontFamily:"monospace",fontSize:14,lineHeight:1.6},j={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},B={p:({node:G,...te})=>_.jsx("p",{style:N,...te}),pre:({node:G,...te})=>_.jsxs("pre",{className:" bg-muted/50 space-y-2 p-3 rounded-sm",style:F,children:[_.jsx("code",{className:" whitespace-normal",children:te.children}),_.jsxs("div",{className:" flex justify-start gap-2",children:[_.jsx(ot,{onClick:V,size:"sm",variant:"outline",children:_.jsx(x2,{})}),_.jsx(ot,{onClick:$=>{const Z=V($);Z&&(t(!1),c(Z),d(!0))},size:"sm",variant:"outline",children:_.jsx(Cz,{})})]})]}),li:({node:G,...te})=>_.jsx("li",{style:j,...te})};function V(G){const te=G.currentTarget.closest("pre");if(!te)return;const $=te.textContent||te.innerText;return navigator.clipboard.writeText($).then(()=>console.log("Text copied to clipboard")).catch(Z=>console.error("Error in copying text: ",Z)),$}return _.jsxs(Ay,{open:e,onOpenChange:t,children:[_.jsx(Iy,{asChild:!0,children:_.jsx(ot,{size:"sm",className:"",variant:"outline",children:_.jsx(iH,{strokeWidth:1,size:16})})}),_.jsxs(Lp,{className:" sm:max-w-[425px] md:min-w-[625px] md:max-h-[625px] flex flex-col justify-between overflow-auto",children:[_.jsxs(Fp,{children:[_.jsx($p,{children:"Ask"}),_.jsx(jp,{children:"Need assistance? Feel free to ask me any question!"})]}),_.jsx(Tl,{className:"h-[625px] w-full border-t border-t-muted ",children:(!S||!C)&&_.jsx(cre,{className:" pl-1 pr-3 py-1 w-full xbg-red-100 overflow-auto ",components:B,children:w==null?void 0:w.response})}),_.jsxs("div",{children:[_.jsx(wf,{className:ke(" invisible h-1 w-full animate-pulse",{visible:S||C})}),_.jsxs("div",{className:" border rounded-md flex items-center w-full",children:[_.jsx(Zy,{onKeyDown:G=>{G.key==="Enter"&&!G.shiftKey&&(G.preventDefault(),r(""),M())},placeholder:"Type something...",onFocus:G=>{const te=G.target,$=te.value.length;te.setSelectionRange($,$)},className:" border-none resize-none min-h-7 max-h-10 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",value:n,onChange:G=>r(G.target.value)})," ",_.jsx(ot,{className:"h-8",size:"sm",variant:"ghost",onClick:M,children:!S&&!C?_.jsx(_z,{}):_.jsx(Al,{className:" w-4 h-4 animate-spin mr-2 text-foreground/50"})})]})]})]})]})}function hre(){const{theme:e}=$m(),t=m.useRef(),n=m.useRef(),[r,i]=m.useState(!1),[o,s]=m.useState(!1),[a,l]=m.useState(""),[c,d]=m.useState(!1);m.useState("");const{authToken:f}=oo();ge(le=>le.selectedSheetId);const g=ve(le=>le.card),p=ge(le=>le.theme),v=ve(le=>le.isShowingVisual),y=ve(le=>le.selectedConnectionId),x=ve(le=>le.selectedDatabaseName),w=ve(le=>le.selectedSchemaName);ge(le=>le.actions.updateFrameCard);const S=ve(le=>le.selectedTableName),C=ve(le=>le.actions.setCardSql),P=ve(le=>le.card.sql),O=ve(le=>le.selectedConnectionId),k=ve(le=>le.frame),M=ve(le=>le.filterValues),N=ve(le=>le.applyFilters),F=ve(le=>le.actions.setCardCustomCfg),j=ve(le=>le.actions.setFilterValues),B=ve(le=>le.onSave),V=ve(le=>le.actions.setApplyFilters),G=ve(le=>le.onClose),te=ve(le=>le.actions.setCardData),$=ve(le=>le.actions.setSqlGen),Z=ve(le=>le.runSql),q=ve(le=>le.actions.setRunSql),X=ve(le=>le.actions.setIsSqlRunning),{data:ae,isLoading:A,isFetching:H,isSuccess:ie,isError:R,error:ue,status:ye,refetch:pe}=vi({queryKey:[P],queryFn:()=>zc("https://semaphor.cloud/api/v1/query",(f==null?void 0:f.accessToken)||"",{connection_id:O,sql:P,active_filters:N?M:[]}),enabled:!1,retry:!1});m.useEffect(()=>{ae&&(console.log("queryData",ae),te(ae.records))},[ae,te]),m.useEffect(()=>{Z&&(pe(),q(!1))},[Z,pe,q]),m.useEffect(()=>{(A||H)&&X(!0),(R||ie)&&X(!1)},[A,H,R,ie,X]);function he(){C(""),te([]),$({}),F("")}const ne=le=>{n.current=le};function J(){let le=P;P&&!P.includes("{{")&&(le=AZ(P),C(le));const je={...g,lastSelectedSchema:w,lastSelectedDatabase:x,lastSelectedTable:S,connectionId:y,type:v?g.type:"table",sql:le,customCfg:v?g.customCfg:null},Ue=k.cards.map(tt=>tt.id===g.id?je:tt);B==null||B({...k,cards:Ue})}function re(){G==null||G()}function we(le){const je=getComputedStyle(document.documentElement).getPropertyValue(le);return U(je)}function U(le){const[je,Ue,tt]=le.split(" "),qe=parseFloat(je),gt=parseFloat(Ue),Gt=parseFloat(tt),Bt=gt/100,gn=Gt/100,Rt=(1-Math.abs(2*gn-1))*Bt,mr=Rt*(1-Math.abs(qe/60%2-1)),fe=gn-Rt/2;let Ce=0,Ae=0,We=0;0<=qe&&qe<60?(Ce=Rt,Ae=mr,We=0):60<=qe&&qe<120?(Ce=mr,Ae=Rt,We=0):120<=qe&&qe<180?(Ce=0,Ae=Rt,We=mr):180<=qe&&qe<240?(Ce=0,Ae=mr,We=Rt):240<=qe&&qe<300?(Ce=mr,Ae=0,We=Rt):300<=qe&&qe<360&&(Ce=Rt,Ae=0,We=mr),Ce=Math.round((Ce+fe)*255),Ae=Math.round((Ae+fe)*255),We=Math.round((We+fe)*255);const lt=ln=>{const cn=ln.toString(16);return cn.length==1?"0"+cn:cn};return`#${lt(Ce)}${lt(Ae)}${lt(We)}`}m.useEffect(()=>{const le=t.current,je=n.current;if(le){const Ue=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",tt=p==="system"?Ue:p;le.editor.defineTheme("default",{base:tt==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":tt==="light"?"#ffffff":we("--background")}}),le.editor.setTheme("default")}return je&&le&&je.addCommand(le.KeyMod.Shift|le.KeyCode.Enter,function(){return console.log("Executing query..."),pe(),!1}),()=>{}},[e,p,t.current]);function Ne(le){t.current=le}return _.jsxs("section",{role:"editor-section",className:"grow flex flex-col justify-end pt-3 p-1 ",children:[_.jsxs("div",{className:" grow flex relative overflow-y-scroll justify-between ",children:[_.jsx("div",{role:"editor-container",className:`flex ${r?"w-2/3":"w-[95%]"} xbg-red-100 p-1`,children:_.jsx(qy,{theme:"default",onChange:le=>{C(le),console.log(le)},value:P,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",defaultValue:"SELECT * FROM table",beforeMount:Ne,onMount:ne})}),r&&_.jsx("div",{className:" w-1/3 text-xs relative overflow-hidden xbg-yellow-100 p-1 ",children:_.jsxs("div",{className:"min-h-0 ",children:[_.jsxs("div",{className:"flex gap-2 items-center",children:[_.jsx(UZ,{checked:N,onCheckedChange:()=>V(!N),text:"Apply Filters"}),_.jsx(qZ,{})]}),_.jsx(qy,{theme:"default",onChange:le=>{if(le)try{JSON.parse(le),j(JSON.parse(le))}catch{}},defaultLanguage:"json",className:"min-h-[220px] mt-1",value:JSON.stringify(M,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}),M&&r&&_.jsx(ua,{onClick:()=>i(!1),className:"absolute right-6 top-1 w-3 h-3 text-foreground/50 hover:text-foreground hover:cursor-pointer"}),M&&!r&&_.jsx(IO,{onClick:()=>i(!0),className:ke("absolute right-6 top-1 w-3 h-3 text-foreground/50 hover:text-foreground hover:cursor-pointer",{"text-red-800 font-bold":N})})]}),_.jsxs("div",{className:" flex grow px-6 pt-3 pb-4 gap-2 justify-between item-center",children:[_.jsxs("div",{className:"flex grow gap-2 items-center",children:[_.jsxs(ot,{disabled:A||H,onClick:()=>{pe()},className:" shrink-0",size:"sm",variant:"outline",children:[(A||H)&&_.jsx(Al,{className:"w-4 h-4 mr-2 animate-spin text-foreground/50"}),"Run"]}),R&&_.jsx(WZ,{error:ue.message}),_.jsx(ot,{onClick:he,className:"",size:"sm",variant:"outline",children:"Clear"}),_.jsx(Oo,{value:a,placeholder:"Type something...",onChange:le=>{l(le.target.value)},onKeyDown:le=>{le.key==="Enter"&&(le.preventDefault(),console.log("enter pressed"),d(!0),s(!0))},className:" bg-muted border-none h-9 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"}),_.jsx(fre,{open:o,setOpen:s,userInput:a,triggerAIRun:c,setTriggerAIRun:d,setUserInput:le=>l(le)})]}),_.jsxs("div",{className:"flex gap-2 items-end ",children:[_.jsx(ot,{onClick:J,size:"sm",variant:"outline",children:_.jsx(tp,{size:16,strokeWidth:2,className:"text-green-600 font-bold"})}),_.jsx(ot,{onClick:re,className:" w-full",size:"sm",variant:"outline",children:_.jsx(ua,{})})]})]})]})}const o5="Switch",[pre,Yfe]=kn(o5),[gre,mre]=pre(o5),vre=m.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:i,defaultChecked:o,required:s,disabled:a,value:l="on",onCheckedChange:c,...d}=e,[f,g]=m.useState(null),p=rt(t,S=>g(S)),v=m.useRef(!1),y=f?!!f.closest("form"):!0,[x=!1,w]=Qn({prop:i,defaultProp:o,onChange:c});return m.createElement(gre,{scope:n,checked:x,disabled:a},m.createElement(He.button,se({type:"button",role:"switch","aria-checked":x,"aria-required":s,"data-state":s5(x),"data-disabled":a?"":void 0,disabled:a,value:l},d,{ref:p,onClick:Oe(e.onClick,S=>{w(C=>!C),y&&(v.current=S.isPropagationStopped(),v.current||S.stopPropagation())})})),y&&m.createElement(xre,{control:f,bubbles:!v.current,name:r,value:l,checked:x,required:s,disabled:a,style:{transform:"translateX(-100%)"}}))}),bre="SwitchThumb",yre=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,i=mre(bre,n);return m.createElement(He.span,se({"data-state":s5(i.checked),"data-disabled":i.disabled?"":void 0},r,{ref:t}))}),xre=e=>{const{control:t,checked:n,bubbles:r=!0,...i}=e,o=m.useRef(null),s=zp(n),a=Vh(t);return m.useEffect(()=>{const l=o.current,c=window.HTMLInputElement.prototype,f=Object.getOwnPropertyDescriptor(c,"checked").set;if(s!==n&&f){const g=new Event("click",{bubbles:r});f.call(l,n),l.dispatchEvent(g)}},[s,n,r]),m.createElement("input",se({type:"checkbox","aria-hidden":!0,defaultChecked:n},i,{tabIndex:-1,ref:o,style:{...e.style,...a,position:"absolute",pointerEvents:"none",opacity:0,margin:0}}))};function s5(e){return e?"checked":"unchecked"}const a5=vre,wre=yre,l5=de.forwardRef(({className:e,...t},n)=>_.jsx(a5,{className:ke("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:_.jsx(wre,{className:ke("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));l5.displayName=a5.displayName;function c5({className:e,...t}){const[n,r]=m.useState(0),i=ge(l=>l.themeStyle),o=ve(l=>l.card),s=ve(l=>l.actions.setCard);if(m.useEffect(()=>{r(n+1)},[o.data,o.type,o.cfg,o.customCfg,i]),!o.id)return null;let a;return o.data&&o.data.length>0&&(a=w0({data:o.data,cardType:o.type,cfg:o.cfg,customCfg:o.customCfg})),_.jsxs(Vv,{role:"editor-visual-card",className:ke(" relative h-full flex flex-col rounded-none",e),...t,children:[_.jsxs(Gf,{children:[_.jsx(Xo,{text:o.title,onSave:l=>s({...o,title:l}),children:_.jsx(Yf,{className:"text-base",children:o.title})}),_.jsx(Xo,{text:o.description||"",onSave:l=>s({...o,description:l}),children:_.jsxs(Hv,{children:[" ",o.description]})})]}),_.jsxs(Kf,{className:"flex flex-col pb-3 grow",children:[o.type!=="table"&&a&&_.jsx(b2,{cfg:a},n),o.type==="table"&&o.data&&o.data.length>0&&_.jsx(yO,{children:_.jsx(h0,{data:o==null?void 0:o.data})})]})]})}function _re(){const[e,t]=m.useState(!1),[n,r]=m.useState(""),[i,o]=m.useState(""),[s,a]=m.useState(""),l=ve(x=>x.card),c=ve(x=>x.card.customCfg),d=ve(x=>x.actions.setCardCustomCfg);function f(x){var C,P;const w={...x,data:{...x==null?void 0:x.data,datasets:(P=(C=x==null?void 0:x.data)==null?void 0:C.datasets)==null?void 0:P.map(O=>({...O,data:[]}))}};return JSON.stringify(w,null,1)}function g(){if(!l.data||l.data.length===0)return;const x=w0({data:l.data,cardType:l.type,cfg:l.cfg});x&&(r(JSON.stringify(x,null,1)),c&&o(JSON.stringify(c,null,1)))}function p(){if(i)try{const x=JSON.parse(i);return x?(d(x),a(""),o(""),x):void 0}catch(x){console.log(x),a("Invalid JSON")}}function v(){o(""),d(null)}function y(){let x;if(c){const w=Hs.cloneDeep(l.cfg),S=Hs.merge(w,c);return x=f(S),x}return n?(x=f(JSON.parse(n)),x):""}return _.jsxs(Ay,{open:e,onOpenChange:t,children:[_.jsx(Iy,{asChild:!0,children:_.jsx(ot,{onClick:g,className:`h-7 ${c&&"border-foreground/50 dark:border-foreground/70"}`,size:"sm",variant:"outline",children:c?"Custom Config":"Customize"})}),_.jsxs(Lp,{className:" min-h-[70vh] max-h-[70vh] overflow-auto min-w-[900px] ",children:[_.jsxs(Fp,{className:"",children:[_.jsx($p,{children:"Customize Chart"}),_.jsxs(jp,{children:["See the configuration options and documentation",_.jsx("a",{target:"_blank",className:"ml-1 underline text-blue-500 ",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),_.jsxs("div",{className:"flex grow gap-2 ",children:[_.jsx(c5,{className:" w-1/2 rounded shadow-none"}),_.jsxs(P_,{defaultValue:"custom-config",className:" w-1/2 flex flex-col ",children:[_.jsxs(k_,{className:" justify-start border rounded-sm rounded-b-none border-b-0 ",children:[_.jsxs(qm,{value:"custom-config",children:[c&&_.jsx(y2,{className:"w-5 h-5 mr-1 text-green-600"}),c?"Custom Config":"Default Config"]}),_.jsx(qm,{className:"",value:"output",children:"Output"})]}),_.jsx(Ef,{className:" grow mt-0 bg-red-x p-2 border border-t-0 rounded-b ",value:"output",children:_.jsx(Zy,{disabled:!0,value:n,className:" border-none resize-none font-mono h-full focus-visible:ring-0 focus-visible:ring-offset-0"})}),_.jsx(Ef,{className:"grow mt-0 border border-t-0 rounded-b ",value:"custom-config",children:_.jsx(qy,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"json",value:y(),onChange:x=>o(x)})})]})]}),_.jsxs(Ny,{className:"flex items-center",children:[_.jsx(ti,{className:"text-red-500 mr-2",children:s}),_.jsx(ot,{disabled:!c,onClick:v,variant:"outline",children:"Reset"}),_.jsx(ot,{onClick:p,variant:"outline",children:"Apply"}),_.jsx(ot,{onClick:()=>t(!1),variant:"outline",children:"Close"})]})]})]})}var u5={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},d5=m.createContext&&m.createContext(u5),Sre=["attr","size","title"];function Cre(e,t){if(e==null)return{};var n=Ere(e,t),r,i;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(i=0;i<o.length;i++)r=o[i],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function Ere(e,t){if(e==null)return{};var n={},r=Object.keys(e),i,o;for(o=0;o<r.length;o++)i=r[o],!(t.indexOf(i)>=0)&&(n[i]=e[i]);return n}function hg(){return hg=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},hg.apply(this,arguments)}function f5(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function pg(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?f5(Object(n),!0).forEach(function(r){Ore(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):f5(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function Ore(e,t,n){return t=Pre(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Pre(e){var t=kre(e,"string");return typeof t=="symbol"?t:String(t)}function kre(e,t){if(typeof e!="object"||e===null)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function h5(e){return e&&e.map((t,n)=>m.createElement(t.tag,pg({key:n},t.attr),h5(t.child)))}function ic(e){return t=>m.createElement(Dre,hg({attr:pg({},e.attr)},t),h5(e.child))}function Dre(e){var t=n=>{var{attr:r,size:i,title:o}=e,s=Cre(e,Sre),a=i||n.size||"1em",l;return n.className&&(l=n.className),e.className&&(l=(l?l+" ":"")+e.className),m.createElement("svg",hg({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,r,s,{className:l,style:pg(pg({color:e.color||n.color},n.style),e.style),height:a,width:a,xmlns:"http://www.w3.org/2000/svg"}),o&&m.createElement("title",null,o),e.children)};return d5!==void 0?m.createElement(d5.Consumer,null,n=>t(n)):t(u5)}function p5(e){return ic({tag:"svg",attr:{viewBox:"0 0 1024 1024"},child:[{tag:"path",attr:{d:"M926.8 397.1l-396-288a31.81 31.81 0 0 0-37.6 0l-396 288a31.99 31.99 0 0 0-11.6 35.8l151.3 466a32 32 0 0 0 30.4 22.1h489.5c13.9 0 26.1-8.9 30.4-22.1l151.3-466c4.2-13.2-.5-27.6-11.7-35.8zM838.6 417l-98.5 32-200-144.7V199.9L838.6 417zM466 567.2l-89.1 122.3-55.2-169.2L466 567.2zm-116.3-96.8L484 373.3v140.8l-134.3-43.7zM512 599.2l93.9 128.9H418.1L512 599.2zm28.1-225.9l134.2 97.1L540.1 514V373.3zM558 567.2l144.3-46.9-55.2 169.2L558 567.2zm-74-367.3v104.4L283.9 449l-98.5-32L484 199.9zM169.3 470.8l86.5 28.1 80.4 246.4-53.8 73.9-113.1-348.4zM327.1 853l50.3-69h269.3l50.3 69H327.1zm414.5-33.8l-53.8-73.9 80.4-246.4 86.5-28.1-113.1 348.4z"},child:[]}]})(e)}function g5(e){return ic({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm87.63,96H191.48A64.1,64.1,0,0,0,136,64.52V40.37A88.13,88.13,0,0,1,215.63,120ZM120,120H80.68A48.09,48.09,0,0,1,120,80.68Zm0,16v39.32A48.09,48.09,0,0,1,80.68,136Zm16,0h39.32A48.09,48.09,0,0,1,136,175.32Zm0-16V80.68A48.09,48.09,0,0,1,175.32,120ZM120,40.37V64.52A64.1,64.1,0,0,0,64.52,120H40.37A88.13,88.13,0,0,1,120,40.37ZM40.37,136H64.52A64.1,64.1,0,0,0,120,191.48v24.15A88.13,88.13,0,0,1,40.37,136ZM136,215.63V191.48A64.1,64.1,0,0,0,191.48,136h24.15A88.13,88.13,0,0,1,136,215.63Z"},child:[]}]})(e)}function m5(e){return ic({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M137,28.05a11.94,11.94,0,0,0-9.12,3.08A12.09,12.09,0,0,0,124,40V80.67a11.88,11.88,0,0,0,9.9,11.81,36,36,0,1,1-41.85,37.4c-.47-9.14,1.47-16.8,5.75-22.79h0a11.89,11.89,0,0,0-1.3-15.35L68.87,63.51a12,12,0,0,0-17.74.83A99.6,99.6,0,0,0,57.79,199.2,99.24,99.24,0,0,0,128,228h1.43A100.29,100.29,0,0,0,228,129.42C228.72,77.21,188.76,32.68,137,28.05ZM57.28,69.46A4,4,0,0,1,60.2,68h.19a3.91,3.91,0,0,1,2.79,1.14L90.81,97.36a3.93,3.93,0,0,1,.48,5.08A40.47,40.47,0,0,0,84.08,124h-48A90.36,90.36,0,0,1,57.28,69.46ZM36.09,132H84.18A44,44,0,0,0,124,171.81V219.9A92,92,0,0,1,36.09,132ZM193,193a91.43,91.43,0,0,1-61,26.92V171.82a43.51,43.51,0,0,0,26-11.63,44,44,0,0,0-22.79-75.6A4,4,0,0,1,132,80.67V40a4,4,0,0,1,1.31-3,3.89,3.89,0,0,1,3-1c47.59,4.26,84.34,45.24,83.67,93.29A91.42,91.42,0,0,1,193,193Z"},child:[]}]})(e)}function v5(e){return ic({tag:"svg",attr:{viewBox:"0 0 24 24",strokeWidth:"2",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},child:[]},{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(e)}function b5(e){return ic({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M4 9h4v11H4zM4 4h4v4H4zM10 7h4v4h-4zM16 10h4v4h-4zM16 15h4v5h-4zM10 12h4v8h-4z"},child:[]}]})(e)}function y5(e){return ic({tag:"svg",attr:{version:"1.2",baseProfile:"tiny",viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M4 18c-.552 0-1-.448-1-1v-6.382l-.553.276c-.495.248-1.095.046-1.342-.447-.247-.494-.046-1.094.448-1.342l2-1c.31-.155.678-.139.973.044.294.183.474.504.474.851v8c0 .552-.448 1-1 1zM13 18h-5c-.404 0-.769-.244-.924-.617-.155-.374-.069-.804.217-1.09l4-4c.254-.254.394-.591.394-.95 0-.358-.14-.695-.394-.949-.508-.508-1.39-.508-1.9.001-.253.252-.393.589-.393.948 0 .552-.448 1-1 1s-1-.448-1-1c0-.894.348-1.733.98-2.364 1.265-1.263 3.464-1.263 4.727.001.632.631.979 1.471.979 2.363 0 .893-.348 1.733-.979 2.364l-2.293 2.293h2.586c.552 0 1 .448 1 1s-.448 1-1 1zM20.955 12.377c.338-.457.545-1.016.545-1.627 0-1.517-1.234-2.75-2.75-2.75-1.031 0-1.966.569-2.44 1.484-.254.49-.063 1.094.428 1.348.49.254 1.094.062 1.348-.428.128-.249.383-.404.664-.404.414 0 .75.336.75.75s-.336.75-.75.75c-.552 0-1 .448-1 1s.448 1 1 1c.689 0 1.25.561 1.25 1.25s-.561 1.25-1.25 1.25-1.25-.561-1.25-1.25c0-.552-.448-1-1-1s-1 .448-1 1c0 1.792 1.458 3.25 3.25 3.25s3.25-1.458 3.25-3.25c0-.939-.406-1.779-1.045-2.373z"},child:[]}]})(e)}function Mre(){const[e,t]=m.useState(!1),n=ve(s=>s.card.type),r=ve(s=>s.actions.setCardType),i=ve(s=>s.actions.setCardCustomCfg);function o(s){r(s),i(null),t(!1)}return _.jsxs(Vu,{open:e,onOpenChange:t,children:[_.jsx(Hu,{asChild:!0,children:_.jsx(ot,{className:"h-7 px-2",variant:"outline",children:_.jsx(Tre,{className:"h-4 w-4",chartType:n})})}),_.jsx(zl,{className:"w-50",children:_.jsxs("div",{className:"grid grid-cols-3 place-items-center ",children:[_.jsx(ot,{onClick:()=>o("bar"),className:"font-normal",variant:"ghost",children:_.jsx(MO,{strokeWidth:1})}),_.jsx(ot,{onClick:()=>o("line"),variant:"ghost",children:_.jsx(NO,{strokeWidth:1})}),_.jsx(ot,{onClick:()=>o("stackedBar"),variant:"ghost",children:_.jsx(b5,{className:"h-6 w-6 text-foreground/50 ",strokeWidth:0})}),_.jsx(ot,{onClick:()=>o("scatter"),variant:"ghost",children:_.jsx(FO,{strokeWidth:1})}),_.jsx(ot,{onClick:()=>o("bubble"),variant:"ghost",children:_.jsx(v5,{strokeWidth:2})}),_.jsx(ot,{onClick:()=>o("pie"),variant:"ghost",children:_.jsx(RO,{strokeWidth:1})}),_.jsx(ot,{onClick:()=>o("doughnut"),variant:"ghost",children:_.jsx(m5,{className:"h-7 w-7",strokeWidth:.5})}),_.jsx(ot,{onClick:()=>o("radar"),variant:"ghost",children:_.jsx(p5,{className:"h-6 w-6 text-foreground/50 font-extralight",strokeWidth:.5})}),_.jsx(ot,{onClick:()=>o("polarArea"),variant:"ghost",children:_.jsx(g5,{className:"h-6 w-6 text-foreground/50",strokeWidth:1})}),_.jsx(ot,{onClick:()=>o("table"),variant:"ghost",children:_.jsx(b0,{className:"h-6 w-6 text-foreground/90",strokeWidth:1})}),_.jsx(ot,{onClick:()=>o("kpi"),variant:"ghost",children:_.jsx(y5,{className:"h-6 w-6 text-foreground/70",strokeWidth:0})})]})})]})}function Tre({chartType:e,className:t}){switch(e){case"bar":return _.jsx(MO,{className:t});case"line":return _.jsx(NO,{className:t});case"pie":return _.jsx(RO,{className:t});case"radar":return _.jsx(p5,{className:t});case"scatter":return _.jsx(FO,{className:t});case"bubble":return _.jsx(v5,{className:t});case"doughnut":return _.jsx(m5,{className:t});case"stackedBar":return _.jsx(b5,{className:"h-5 w-5 text-foreground/50 ",strokeWidth:0});case"polarArea":return _.jsx(g5,{className:t});case"kpi":return _.jsx(y5,{className:t});default:return _.jsx(b0,{className:t})}}function Are(){const e=ve(n=>n.card.refreshInterval),t=ve(n=>n.actions.setCardRefreshInterval);return _.jsxs(Vu,{children:[_.jsx(Hu,{asChild:!0,children:_.jsx(ot,{className:"h-7",variant:"outline",children:"Realtime"})}),_.jsx(zl,{className:"w-[200px]",children:_.jsx("div",{className:"grid gap-4",children:_.jsx("div",{className:"grid gap-2",children:_.jsxs("div",{className:"grid grid-cols-5 items-center gap-1",children:[_.jsx(ti,{className:"col-span-3",htmlFor:"width",children:"Refresh Every"}),_.jsx(Oo,{value:e||"",onChange:n=>t(n.target.value),id:"width",placeholder:"30s",className:"col-span-2 h-7 focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0"})]})})})})]})}function x5(){ve(r=>r.frame);const e=ve(r=>r.card),t=ve(r=>r.isShowingVisual),n=ve(r=>r.isSqlRunning);return ve(r=>r.onSave),ve(r=>r.onClose),ve(r=>r.actions.setCardSql),ve(r=>r.actions.setCardType),ve(r=>r.actions.setSqlGen),e?_.jsxs("div",{className:" h-full relative flex flex-col",children:[n&&_.jsx(Al,{className:" w-10 h-10 z-10 absolute m-auto left-0 right-0 top-0 bottom-0 animate-spin text-foreground/10 "}),_.jsxs("div",{className:" h-10 px-6 pt-6 bg-red-x100 mb-0 z-10 right-0 flex justify-end items-center gap-2",children:[t&&_.jsxs("div",{className:"bg-red-x00 flex grow gap-2",children:[_.jsx(Mre,{}),_.jsx(_re,{}),_.jsx(Are,{})]}),_.jsx(Ire,{})]}),t?e.type==="kpi"?_.jsx("div",{className:"grow flex items-center justify-center ",children:_.jsx("div",{className:" border rounded-md",children:_.jsx(jO,{isLoading:n,card:e})})}):_.jsx(c5,{className:"grow border-none shadow-none "}):_.jsx("div",{className:"w-full mt-4 px-6 bg-red-x00 grow border-none shadow-none overflow-y-auto ",children:e.data&&e.data.length>0&&_.jsx(h0,{data:e.data})})]}):_.jsx(_.Fragment,{children:"No Active Card"})}function Ire(){const e=ve(n=>n.isShowingVisual),t=ve(n=>n.actions.setIsShowingVisual);return _.jsxs("div",{className:" flex items-center space-x-2",children:[_.jsx(ti,{htmlFor:"visualize",children:"Chart"}),_.jsx(l5,{checked:e,onCheckedChange:()=>t(!e),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}const w5="Collapsible",[Nre,_5]=kn(w5),[Rre,Ix]=Nre(w5),Lre=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:i,disabled:o,onOpenChange:s,...a}=e,[l=!1,c]=Qn({prop:r,defaultProp:i,onChange:s});return m.createElement(Rre,{scope:n,disabled:o,contentId:or(),open:l,onOpenToggle:m.useCallback(()=>c(d=>!d),[c])},m.createElement(He.div,se({"data-state":Nx(l),"data-disabled":o?"":void 0},a,{ref:t})))}),Fre="CollapsibleTrigger",$re=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,i=Ix(Fre,n);return m.createElement(He.button,se({type:"button","aria-controls":i.contentId,"aria-expanded":i.open||!1,"data-state":Nx(i.open),"data-disabled":i.disabled?"":void 0,disabled:i.disabled},r,{ref:t,onClick:Oe(e.onClick,i.onOpenToggle)}))}),S5="CollapsibleContent",jre=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,i=Ix(S5,e.__scopeCollapsible);return m.createElement(yn,{present:n||i.open},({present:o})=>m.createElement(zre,se({},r,{ref:t,present:o})))}),zre=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:i,...o}=e,s=Ix(S5,n),[a,l]=m.useState(r),c=m.useRef(null),d=rt(t,c),f=m.useRef(0),g=f.current,p=m.useRef(0),v=p.current,y=s.open||a,x=m.useRef(y),w=m.useRef();return m.useEffect(()=>{const S=requestAnimationFrame(()=>x.current=!1);return()=>cancelAnimationFrame(S)},[]),Vn(()=>{const S=c.current;if(S){w.current=w.current||{transitionDuration:S.style.transitionDuration,animationName:S.style.animationName},S.style.transitionDuration="0s",S.style.animationName="none";const C=S.getBoundingClientRect();f.current=C.height,p.current=C.width,x.current||(S.style.transitionDuration=w.current.transitionDuration,S.style.animationName=w.current.animationName),l(r)}},[s.open,r]),m.createElement(He.div,se({"data-state":Nx(s.open),"data-disabled":s.disabled?"":void 0,id:s.contentId,hidden:!y},o,{ref:d,style:{"--radix-collapsible-content-height":g?`${g}px`:void 0,"--radix-collapsible-content-width":v?`${v}px`:void 0,...e.style}}),y&&i)});function Nx(e){return e?"open":"closed"}const Bre=Lre,Vre=$re,Hre=jre,xs="Accordion",Wre=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[Rx,Ure,qre]=Sf(xs),[gg,Kfe]=kn(xs,[qre,_5]),Lx=_5(),C5=m.forwardRef((e,t)=>{const{type:n,...r}=e,i=r,o=r;return m.createElement(Rx.Provider,{scope:e.__scopeAccordion},n==="multiple"?m.createElement(Xre,se({},o,{ref:t})):m.createElement(Kre,se({},i,{ref:t})))});C5.propTypes={type(e){const t=e.value||e.defaultValue;return e.type&&!["single","multiple"].includes(e.type)?new Error("Invalid prop `type` supplied to `Accordion`. Expected one of `single | multiple`."):e.type==="multiple"&&typeof t=="string"?new Error("Invalid prop `type` supplied to `Accordion`. Expected `single` when `defaultValue` or `value` is type `string`."):e.type==="single"&&Array.isArray(t)?new Error("Invalid prop `type` supplied to `Accordion`. Expected `multiple` when `defaultValue` or `value` is type `string[]`."):null}};const[E5,Gre]=gg(xs),[O5,Yre]=gg(xs,{collapsible:!1}),Kre=m.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:i=()=>{},collapsible:o=!1,...s}=e,[a,l]=Qn({prop:n,defaultProp:r,onChange:i});return m.createElement(E5,{scope:e.__scopeAccordion,value:a?[a]:[],onItemOpen:l,onItemClose:m.useCallback(()=>o&&l(""),[o,l])},m.createElement(O5,{scope:e.__scopeAccordion,collapsible:o},m.createElement(P5,se({},s,{ref:t}))))}),Xre=m.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:i=()=>{},...o}=e,[s=[],a]=Qn({prop:n,defaultProp:r,onChange:i}),l=m.useCallback(d=>a((f=[])=>[...f,d]),[a]),c=m.useCallback(d=>a((f=[])=>f.filter(g=>g!==d)),[a]);return m.createElement(E5,{scope:e.__scopeAccordion,value:s,onItemOpen:l,onItemClose:c},m.createElement(O5,{scope:e.__scopeAccordion,collapsible:!0},m.createElement(P5,se({},o,{ref:t}))))}),[Qre,mg]=gg(xs),P5=m.forwardRef((e,t)=>{const{__scopeAccordion:n,disabled:r,dir:i,orientation:o="vertical",...s}=e,a=m.useRef(null),l=rt(a,t),c=Ure(n),f=Ws(i)==="ltr",g=Oe(e.onKeyDown,p=>{var v;if(!Wre.includes(p.key))return;const y=p.target,x=c().filter(F=>{var j;return!((j=F.ref.current)!==null&&j!==void 0&&j.disabled)}),w=x.findIndex(F=>F.ref.current===y),S=x.length;if(w===-1)return;p.preventDefault();let C=w;const P=0,O=S-1,k=()=>{C=w+1,C>O&&(C=P)},M=()=>{C=w-1,C<P&&(C=O)};switch(p.key){case"Home":C=P;break;case"End":C=O;break;case"ArrowRight":o==="horizontal"&&(f?k():M());break;case"ArrowDown":o==="vertical"&&k();break;case"ArrowLeft":o==="horizontal"&&(f?M():k());break;case"ArrowUp":o==="vertical"&&M();break}const N=C%S;(v=x[N].ref.current)===null||v===void 0||v.focus()});return m.createElement(Qre,{scope:n,disabled:r,direction:i,orientation:o},m.createElement(Rx.Slot,{scope:n},m.createElement(He.div,se({},s,{"data-orientation":o,ref:l,onKeyDown:r?void 0:g}))))}),Fx="AccordionItem",[Zre,$x]=gg(Fx),Jre=m.forwardRef((e,t)=>{const{__scopeAccordion:n,value:r,...i}=e,o=mg(Fx,n),s=Gre(Fx,n),a=Lx(n),l=or(),c=r&&s.value.includes(r)||!1,d=o.disabled||e.disabled;return m.createElement(Zre,{scope:n,open:c,disabled:d,triggerId:l},m.createElement(Bre,se({"data-orientation":o.orientation,"data-state":D5(c)},a,i,{ref:t,disabled:d,open:c,onOpenChange:f=>{f?s.onItemOpen(r):s.onItemClose(r)}})))}),eie="AccordionHeader",tie=m.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,i=mg(xs,n),o=$x(eie,n);return m.createElement(He.h3,se({"data-orientation":i.orientation,"data-state":D5(o.open),"data-disabled":o.disabled?"":void 0},r,{ref:t}))}),k5="AccordionTrigger",nie=m.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,i=mg(xs,n),o=$x(k5,n),s=Yre(k5,n),a=Lx(n);return m.createElement(Rx.ItemSlot,{scope:n},m.createElement(Vre,se({"aria-disabled":o.open&&!s.collapsible||void 0,"data-orientation":i.orientation,id:o.triggerId},a,r,{ref:t})))}),rie="AccordionContent",iie=m.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,i=mg(xs,n),o=$x(rie,n),s=Lx(n);return m.createElement(Hre,se({role:"region","aria-labelledby":o.triggerId,"data-orientation":i.orientation},s,r,{ref:t,style:{"--radix-accordion-content-height":"var(--radix-collapsible-content-height)","--radix-accordion-content-width":"var(--radix-collapsible-content-width)",...e.style}}))});function D5(e){return e?"open":"closed"}const oie=C5,sie=Jre,aie=tie,M5=nie,T5=iie,jx=oie,ko=de.forwardRef(({className:e,...t},n)=>_.jsx(sie,{ref:n,className:ke("border-b",e),...t}));ko.displayName="AccordionItem";const Do=de.forwardRef(({className:e,children:t,...n},r)=>_.jsx(aie,{className:"flex",children:_.jsxs(M5,{ref:r,className:ke("flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",e),...n,children:[t,_.jsx(v0,{className:"h-4 w-4 shrink-0 transition-transform duration-200"})]})}));Do.displayName=M5.displayName;const Mo=de.forwardRef(({className:e,children:t,...n},r)=>_.jsx(T5,{ref:r,className:"overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...n,children:_.jsx("div",{className:ke("pb-4 pt-0",e),children:t})}));Mo.displayName=T5.displayName;const A5="Radio",[lie,I5]=kn(A5),[cie,uie]=lie(A5),die=m.forwardRef((e,t)=>{const{__scopeRadio:n,name:r,checked:i=!1,required:o,disabled:s,value:a="on",onCheck:l,...c}=e,[d,f]=m.useState(null),g=rt(t,y=>f(y)),p=m.useRef(!1),v=d?!!d.closest("form"):!0;return m.createElement(cie,{scope:n,checked:i,disabled:s},m.createElement(He.button,se({type:"button",role:"radio","aria-checked":i,"data-state":N5(i),"data-disabled":s?"":void 0,disabled:s,value:a},c,{ref:g,onClick:Oe(e.onClick,y=>{i||l==null||l(),v&&(p.current=y.isPropagationStopped(),p.current||y.stopPropagation())})})),v&&m.createElement(pie,{control:d,bubbles:!p.current,name:r,value:a,checked:i,required:o,disabled:s,style:{transform:"translateX(-100%)"}}))}),fie="RadioIndicator",hie=m.forwardRef((e,t)=>{const{__scopeRadio:n,forceMount:r,...i}=e,o=uie(fie,n);return m.createElement(yn,{present:r||o.checked},m.createElement(He.span,se({"data-state":N5(o.checked),"data-disabled":o.disabled?"":void 0},i,{ref:t})))}),pie=e=>{const{control:t,checked:n,bubbles:r=!0,...i}=e,o=m.useRef(null),s=zp(n),a=Vh(t);return m.useEffect(()=>{const l=o.current,c=window.HTMLInputElement.prototype,f=Object.getOwnPropertyDescriptor(c,"checked").set;if(s!==n&&f){const g=new Event("click",{bubbles:r});f.call(l,n),l.dispatchEvent(g)}},[s,n,r]),m.createElement("input",se({type:"radio","aria-hidden":!0,defaultChecked:n},i,{tabIndex:-1,ref:o,style:{...e.style,...a,position:"absolute",pointerEvents:"none",opacity:0,margin:0}}))};function N5(e){return e?"checked":"unchecked"}const gie=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],R5="RadioGroup",[mie,Xfe]=kn(R5,[dl,I5]),L5=dl(),F5=I5(),[vie,bie]=mie(R5),yie=m.forwardRef((e,t)=>{const{__scopeRadioGroup:n,name:r,defaultValue:i,value:o,required:s=!1,disabled:a=!1,orientation:l,dir:c,loop:d=!0,onValueChange:f,...g}=e,p=L5(n),v=Ws(c),[y,x]=Qn({prop:o,defaultProp:i,onChange:f});return m.createElement(vie,{scope:n,name:r,required:s,disabled:a,value:y,onValueChange:x},m.createElement(Hm,se({asChild:!0},p,{orientation:l,dir:v,loop:d}),m.createElement(He.div,se({role:"radiogroup","aria-required":s,"aria-orientation":l,"data-disabled":a?"":void 0,dir:v},g,{ref:t}))))}),xie="RadioGroupItem",wie=m.forwardRef((e,t)=>{const{__scopeRadioGroup:n,disabled:r,...i}=e,o=bie(xie,n),s=o.disabled||r,a=L5(n),l=F5(n),c=m.useRef(null),d=rt(t,c),f=o.value===i.value,g=m.useRef(!1);return m.useEffect(()=>{const p=y=>{gie.includes(y.key)&&(g.current=!0)},v=()=>g.current=!1;return document.addEventListener("keydown",p),document.addEventListener("keyup",v),()=>{document.removeEventListener("keydown",p),document.removeEventListener("keyup",v)}},[]),m.createElement(Wm,se({asChild:!0},a,{focusable:!s,active:f}),m.createElement(die,se({disabled:s,required:o.required,checked:f},l,i,{name:o.name,ref:d,onCheck:()=>o.onValueChange(i.value),onKeyDown:Oe(p=>{p.key==="Enter"&&p.preventDefault()}),onFocus:Oe(i.onFocus,()=>{var p;g.current&&((p=c.current)===null||p===void 0||p.click())})})))}),_ie=m.forwardRef((e,t)=>{const{__scopeRadioGroup:n,...r}=e,i=F5(n);return m.createElement(hie,se({},i,r,{ref:t}))}),$5=yie,j5=wie,Sie=_ie,z5=de.forwardRef(({className:e,...t},n)=>_.jsx($5,{className:ke("grid gap-2",e),...t,ref:n}));z5.displayName=$5.displayName;const zx=de.forwardRef(({className:e,...t},n)=>_.jsx(j5,{ref:n,className:ke("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:_.jsx(Sie,{className:"flex items-center justify-center",children:_.jsx(AO,{className:"h-2.5 w-2.5 fill-current text-current"})})}));zx.displayName=j5.displayName;function B5(){var i;const e=ve(o=>o.card.cfg),t=ve(o=>o.actions.setCardCfg),n=(i=e==null?void 0:e.options)==null?void 0:i.indexAxis;function r(o){const s={...e,options:{...e==null?void 0:e.options,indexAxis:o}};t(s)}return _.jsxs("div",{children:[_.jsx("p",{className:"font-semibold",children:"Orientation"}),_.jsxs(z5,{value:n,onValueChange:r,className:"flex gap-3 mt-2 ",defaultValue:"x",children:[_.jsxs("div",{className:"flex items-center space-x-2",children:[_.jsx(zx,{value:"x",id:"r1"}),_.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),_.jsxs("div",{className:"flex items-center space-x-2",children:[_.jsx(zx,{value:"y",id:"r2"}),_.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})]})}function V5(){var r,i,o;const e=ve(s=>s.card.cfg),t=ve(s=>s.actions.setCardCfg);function n(s){var c;const a={datalabels:{display:s!=="none",align:s,anchor:s,clamp:!0}},l={...e,options:{...e==null?void 0:e.options,plugins:{...(c=e==null?void 0:e.options)==null?void 0:c.plugins,...a}}};t(l),console.log(s)}return _.jsxs(_.Fragment,{children:[_.jsx("label",{className:"font-medium",children:"Data Labels"}),_.jsxs(MD,{value:(o=(i=(r=e==null?void 0:e.options)==null?void 0:r.plugins)==null?void 0:i.datalabels)==null?void 0:o.anchor,onValueChange:n,defaultValue:"none",children:[_.jsx($y,{className:"w-[180px] mt-2 focus:ring-1 focus:ring-offset-0 h-7",children:_.jsx(AD,{placeholder:"Select position"})}),_.jsx(jy,{children:_.jsxs(TD,{children:[_.jsx(Up,{children:"Data Labels"}),_.jsx(Da,{value:"none",children:"None"}),_.jsx(Da,{value:"start",children:"Start"}),_.jsx(Da,{value:"center",children:"Center"}),_.jsx(Da,{value:"end",children:"End"})]})})]})]})}function H5(){const e=ve(i=>i.card.preferences),t=ve(i=>i.actions.setCardPreferences),n=ve(i=>{var o;return(o=i.card.preferences)==null?void 0:o.filterOnClickField}),r=ve(i=>i.actions.setFilterOnClickField);return _.jsxs("div",{children:[_.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[_.jsx(ad,{checked:!!(e!=null&&e.filterOnClick),onCheckedChange:i=>{t({...e,filterOnClick:!!i})}}),_.jsx(ti,{children:"Filter on click"})]}),(e==null?void 0:e.filterOnClick)===!0&&_.jsxs("div",{className:"flex gap-2 items-center",children:[_.jsx(Oo,{value:n||"",className:" h-7 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"expression (optional)",onChange:i=>r(i.target.value)}),_.jsxs(qh,{children:[_.jsx(Xb,{children:_.jsx(Lb,{className:"h-4 w-4 opacity-70"})}),_.jsx($u,{children:_.jsxs("div",{className:"max-w-[200px]",children:["The x-axis expression of your query. Example:",_.jsx("div",{className:" mt-1 text-xs font-mono",children:"TO_CHAR(order_date, 'YYYY-MM')"})]})})]})]})]})}const Cie={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Eie={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Oie(){const e=ve(t=>t.card.type);return _.jsxs("div",{className:"p-6 space-y-6",children:[_.jsx(jx,{className:" ",type:"single",collapsible:!0,children:Pie(e)}),_.jsx("section",{className:"",children:["line","bar"].includes(e)&&_.jsx(B5,{})}),_.jsx("div",{children:!["kpi"].includes(e)&&_.jsx(V5,{})}),_.jsx("div",{children:!["kpi"].includes(e)&&_.jsx(H5,{})})]})}function Pie(e){if(["line","bar"].includes(e))return _.jsxs(_.Fragment,{children:[_.jsxs(ko,{value:"item-1",children:[_.jsx(Do,{className:" font-normal",children:_.jsx("p",{children:"Chart Query"})}),_.jsxs(Mo,{className:" ",children:[_.jsx("div",{className:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),_.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[_.jsx("li",{children:"X-axis - Category (ex. city)"}),_.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),_.jsxs(ko,{value:"item-2",children:[_.jsx(Do,{className:" font-normal",children:"Mixed Chart"}),_.jsxs(Mo,{className:" text-xs space-y-2",children:[_.jsxs("p",{children:["Click ",_.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),_.jsx("pre",{children:JSON.stringify(Cie,null,2)})]})]}),_.jsxs(ko,{value:"item-3",children:[_.jsx(Do,{className:" font-normal",children:"Area Chart"}),_.jsxs(Mo,{className:" text-xs space-y-2",children:[_.jsxs("p",{children:["Click ",_.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",_.jsx("a",{className:"text-blue-500 hover:underline mx-1",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),_.jsx("pre",{children:JSON.stringify(Eie,null,2)})]})]})]});if(e==="bubble")return _.jsx(_.Fragment,{children:_.jsxs(ko,{value:"item-1",children:[_.jsx(Do,{className:" font-normal",children:_.jsxs("p",{children:["How to create a ",_.jsx("span",{children:e})," chart query?"]})}),_.jsxs(Mo,{className:" ",children:[_.jsx("div",{className:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT label, x-axis, y-axis, radius FROM table"}),_.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[_.jsx("li",{children:"Label - Category (ex. city)"}),_.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),_.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),_.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),_.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(e==="scatter")return _.jsx(_.Fragment,{children:_.jsxs(ko,{value:"item-1",children:[_.jsx(Do,{className:" font-normal",children:_.jsxs("p",{children:["How to create a ",_.jsx("span",{children:e})," chart query?"]})}),_.jsxs(Mo,{className:" ",children:[_.jsx("div",{className:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT label, x-axis, y-axis FROM table"}),_.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[_.jsx("li",{children:"Label - Category (ex. city)"}),_.jsx("li",{children:"Group (opt) - Category (ex. state)"}),_.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),_.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(e))return _.jsx(_.Fragment,{children:_.jsxs(ko,{value:"item-1",children:[_.jsx(Do,{className:" font-normal",children:_.jsxs("p",{children:[_.jsx("span",{children:e==="polarArea"?"Polar":e.charAt(0).toUpperCase()+e.slice(1)})," ","chart query"]})}),_.jsxs(Mo,{className:" ",children:[_.jsx("div",{className:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT label, measure FROM table"}),_.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[_.jsx("li",{children:"Label - Category (ex. city)"}),_.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function kie(){var s,a,l;const e=ve(c=>c.card.preferences),t=ve(c=>c.actions.setCardPreferences),n=ve(c=>c.actions.setNumberFormat),r=ve(c=>{var d,f;return(f=(d=c.card.preferences)==null?void 0:d.formatNumber)==null?void 0:f.format}),i=ve(c=>{var d,f;return(f=(d=c.card.preferences)==null?void 0:d.formatNumber)==null?void 0:f.locale}),o=ve(c=>{var d,f;return(f=(d=c.card.preferences)==null?void 0:d.formatNumber)==null?void 0:f.currency});return ve(c=>c.actions.setFilterOnClickField),_.jsxs("div",{children:[_.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[_.jsx(ad,{checked:!!((s=e==null?void 0:e.formatNumber)!=null&&s.enabled),onCheckedChange:c=>{t({...e,formatNumber:{...e==null?void 0:e.formatNumber,enabled:c}})}}),_.jsx(ti,{children:"Format Number"})]}),((a=e==null?void 0:e.formatNumber)==null?void 0:a.enabled)===!0&&_.jsxs("div",{className:"flex flex-col gap-2 ",children:[_.jsxs("div",{children:[_.jsx(ti,{className:"text-xs",children:"Currency"}),_.jsxs("div",{className:"flex gap-1",children:[_.jsx(Oo,{value:o||"",className:" h-7 w-20 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"USD",onChange:c=>{var d,f,g;return n(((d=e==null?void 0:e.formatNumber)==null?void 0:d.format)||"",c.target.value,((f=e==null?void 0:e.formatNumber)==null?void 0:f.locale)||"",((g=e==null?void 0:e.formatNumber)==null?void 0:g.suffix)||"")}}),_.jsx(Oo,{value:i||"",className:" h-7 w-20 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"en-US",onChange:c=>{var d,f,g;return n(((d=e==null?void 0:e.formatNumber)==null?void 0:d.format)||"",((f=e==null?void 0:e.formatNumber)==null?void 0:f.currency)||"",c.target.value,((g=e==null?void 0:e.formatNumber)==null?void 0:g.suffix)||"")}})]})]}),_.jsxs("div",{children:[_.jsxs("div",{className:" flex gap-1",children:[_.jsx(ti,{className:"text-xs",children:"Format"}),_.jsxs(qh,{children:[_.jsx(Xb,{children:_.jsx(Lb,{strokeWidth:1,className:"h-3 w-3 opacity-70"})}),_.jsx($u,{children:_.jsxs("div",{className:"max-w-[200px]",children:["Format number",_.jsx("div",{className:" mt-1 text-xs font-mono",children:"#.## for 123.43"})]})})]})]}),_.jsx("div",{children:_.jsx(Oo,{value:r||"",className:" h-7 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"###,###.##",onChange:c=>{var d,f,g;return n(c.target.value,((d=e==null?void 0:e.formatNumber)==null?void 0:d.currency)||"",((f=e==null?void 0:e.formatNumber)==null?void 0:f.locale)||"",((g=e==null?void 0:e.formatNumber)==null?void 0:g.suffix)||"")}})})]}),_.jsxs("div",{children:[_.jsx(ti,{className:"text-xs",children:"Suffix"}),_.jsx(Oo,{value:((l=e==null?void 0:e.formatNumber)==null?void 0:l.suffix)||"",className:" h-7 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B",onChange:c=>{var d,f,g;return n(((d=e==null?void 0:e.formatNumber)==null?void 0:d.format)||"",((f=e==null?void 0:e.formatNumber)==null?void 0:f.currency)||"",((g=e==null?void 0:e.formatNumber)==null?void 0:g.locale)||"",c.target.value)}})]})]})]})}function Die(){return _.jsxs("div",{className:"px-6 py-2 space-y-6",children:[_.jsx(jx,{className:" ",type:"single",collapsible:!0,children:_.jsxs(ko,{value:"item-1",children:[_.jsx(Do,{className:" font-normal",children:"KPI query"}),_.jsxs(Mo,{className:" ",children:[_.jsx("div",{className:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT current, previous FROM table"}),_.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[_.jsx("li",{children:"Current - Number (ex. Revenue)"}),_.jsx("li",{children:"Previous - Number (ex. Revenue)"})]})]})]})}),_.jsx("section",{className:"",children:_.jsx(kie,{})}),_.jsx("div",{}),_.jsx("div",{})]})}function Mie(){return _.jsxs("div",{className:"px-6 py-2 space-y-6",children:[_.jsx(jx,{className:" ",type:"single",collapsible:!0,children:_.jsxs(ko,{value:"item-1",children:[_.jsx(Do,{className:" font-normal",children:"Stacked chart query?"}),_.jsxs(Mo,{className:" ",children:[_.jsx("div",{className:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),_.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[_.jsx("li",{children:"X-axis - Category (ex. country)"}),_.jsx("li",{children:"Stack by - Category (ex. city)"}),_.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]})}),_.jsx("section",{className:"",children:_.jsx(B5,{})}),_.jsx("div",{children:_.jsx(V5,{})}),_.jsx("div",{children:_.jsx(H5,{})})]})}function Tie(){const e=ve(n=>n.card.type);function t(n){switch(n){case"stackedBar":return _.jsx(Mie,{});case"kpi":return _.jsx(Die,{});default:return _.jsx(Oie,{})}}return _.jsx(Tl,{className:" text-sm h-full w-full ",children:t(e)})}function Aie(){const e=ve(t=>t.isShowingVisual);return _.jsxs(lM,{direction:"vertical",className:"min-w-full max-w-lg min-h-[250px]",children:[_.jsx(Xp,{className:"flex",minSize:20,defaultSize:40,children:_.jsx(hre,{})}),_.jsx(cM,{className:"border-[1.5px] "}),_.jsx(Xp,{minSize:20,defaultSize:60,children:e?_.jsxs(lM,{direction:"horizontal",children:[_.jsx(_.Fragment,{children:_.jsx(Xp,{className:"flex min-w-[275px]",minSize:20,defaultSize:25,maxSize:30,children:_.jsx(Tie,{})})}),_.jsx(cM,{className:"border-[1.5px] "}),_.jsx(Xp,{minSize:40,defaultSize:75,maxSize:100,children:_.jsx(x5,{})})]}):_.jsx(x5,{})})]})}function Iie({authToken:e,onSave:t,onClose:n}){ve(s=>s.actions.setCard);const r=ve(s=>s.actions.setOnSave),i=ve(s=>s.actions.setOnClose),o=ge(s=>s.actions.setAuthToken);return m.useEffect(()=>{t&&r(t),n&&i(n)},[t,r,n,i]),m.useEffect(()=>{e&&e.accessToken&&o(e)},[e,o]),_.jsxs(cD,{className:"rounded-none",children:[_.jsx(uD,{className:" rounded-none border-r-[3px] ",children:_.jsx(LD,{})}),_.jsx(dD,{children:_.jsx(Aie,{})})]})}function Nie(){ge(s=>s.selectedCardId);const e=ge(s=>s.selectedSheetId),{setIsVisualEditing:t}=ge(s=>s.actions),n=ge(s=>s.isVisualEditing),r=ge(s=>s.actions.updateFrame);function i(s){e&&(r(e,s),t(!1))}function o(){t(!1)}return _.jsx("div",{role:"editor-container",className:ke("grow flex",{block:n,hidden:!n}),children:_.jsx(Iie,{onSave:i,onClose:o})})}function Rie({columns:e,tableName:t}){const n=ve(f=>f.selectedConnectionId),r=ve(f=>f.selectedDatabaseName),i=ve(f=>f.selectedSchemaName),o=ve(f=>f.selectedTableName),s=ge(f=>f.dashboard.filters)||[],a=ge(f=>f.actions.addFilter),l=ge(f=>f.actions.removeFilter),c=ge(f=>f.actions.removeFilterValue);function d(f){const g=_i(f.column_name),p=_i(r||""),v=_i(i||""),y=_i(t),x=s==null?void 0:s.find(w=>w.column===g&&w.table===y&&w.database===p);if(x)c(x.id),l(x.id);else{const w=Ep(v,y),S=`SELECT ${g}, COUNT(*) FROM ${w} GROUP BY ${g} ORDER BY ${g} ASC LIMIT 50`,C=`SELECT min(${g}) as min, max(${g}) as max FROM ${w}`;if(t==="api"&&n){a({id:qo(),column:`${w}.${g}`,title:f.column_name,dataType:f.data_type,table:"api",database:"NA",connectionId:n,sql:xa.includes(f.data_type)?C:S});return}if(!n||!r||!o)throw new Error("missing connectionId, database, or table");a({id:qo(),column:`${w}.${g}`,title:f.column_name,dataType:f.data_type,table:o,database:r,connectionId:n,sql:xa.includes(f.data_type)?C:S})}}return _.jsx(Tl,{className:" h-[70vh] mt-2 xbg-red-100 px-3",children:e==null?void 0:e.map(f=>{const g=s==null?void 0:s.find(p=>p.column===_i(f.column_name)&&p.table===o&&p.database===r);return _.jsx("div",{onClick:()=>d(f),className:ke(" group flex text-sm items-center justify-between px-3 py-[6px] transition-colors hover:bg-muted/50 cursor-pointer border border-background border-dashed",{"bg-muted ":g}),children:_.jsxs("div",{className:"flex items-center gap-2 ",children:[_.jsx(RD,{column:f}),_.jsx("span",{children:f.column_name})]})},f.column_name)})})}function Lie(){ge(t=>t.showFilters);const e=ge(t=>t.actions.setShowFilters);return _.jsxs("section",{className:" relative space-y-4 py-0 px-4 ",children:[_.jsx(ot,{onClick:()=>e(!1),className:" p-0 h-7 w-7 absolute top-0 right-4",variant:"outline",children:_.jsx(ua,{})}),_.jsx("p",{className:"text-md px-2",children:"Data Columns"}),_.jsx("div",{children:_.jsx(LD,{ColumnsComponent:(t,n,r)=>_.jsx(Rie,{schemaName:t,tableName:n,columns:r})})})]})}function Fie(){ge(n=>n.dashboard);const e=ge(n=>n.showFilters),t=ge(n=>n.isVisualEditing);return ge(n=>n.bookmarkKey),_.jsxs("div",{role:"dashboard-plus-main",className:ke(" grow",{hidden:t,flex:!t}),children:[_.jsx(yk,{}),e&&_.jsx("div",{role:"filter-aside-container",children:_.jsx(Lie,{})})]})}function $ie(){const e=ge(r=>r.dashboard),t=ge(r=>r.actions.setDashboard),n=ge(r=>r.showDashboardJSON);return ge(r=>r.actions.setShowDashboardJSON),_.jsx("div",{className:ke(" p-2",{hidden:!n}),children:_.jsx(CM,{onChange:r=>{if(r)try{JSON.parse(r),t(JSON.parse(r))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto ",value:JSON.stringify(e,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})})}function jie({showControls:e=!1,showFooter:t=!0,...n}){return ge(r=>r.isVisualEditing),_.jsx(l_,{dashboardProps:n,children:_.jsxs(vy,{children:[_.jsx($ie,{}),_.jsxs(g_,{...n,children:[e&&_.jsx(yX,{}),_.jsx(Nie,{}),_.jsx(Fie,{})]})]})})}function zie(){const e=ge(t=>t.actions);return{getStyle:e.getStyle,getDashboard:e.getDashboard,setOnSaveFunction:e.setOnSaveFunction,setOnAddCard:e.setOnAddCard,setOnUpateCard:e.setOnUpdateCard,setOnRemoveCard:e.setOnRemoveCard}}$e.BOOLEAN_DATA_TYPES=Sp,$e.DATE_DATA_TYPES=xa,$e.Dashboard=wk,$e.DashboardPlus=jie,$e.DashboardProvider=vy,$e.DashboardWC=vY,$e.NUMBER_DATA_TYPES=hs,$e.SelectComponent=ld,$e.SemaphorQueryClient=xk,$e.TEXT_DATA_TYPES=Gu,$e.cleanCard=Kk,$e.createSqlGenConfig=G0,$e.fmt=_i,$e.getBookmarkKey=ms,$e.getColumnDataType=fU,$e.getDashbaordStateWithoutData=Dy,$e.getFilterValueType=Cp,$e.getQualifiedTableName=Ep,$e.getSql=q0,$e.isColumnInSqlGen=FP,$e.resolveDataType=Fm,$e.useActions=zie,$e.useCard=kH,$e.useDashboard=p_,$e.useDashboardActions=Yc,$e.useDashboardStore=ge,$e.useEditorActions=v4,$e.useEditorAside=c_,$e.useEditorStore=ve,Object.defineProperty($e,Symbol.toStringTag,{value:"Module"})});
500
+ Visual Query Syntax: ${dre}`,{data:w,isLoading:S,isFetching:C,isError:P,refetch:O}=vi({queryKey:["ai-query"],queryFn:()=>al("https://semaphor.cloud/api/v1/ai",(s==null?void 0:s.accessToken)||"",{user_content:`userContent: ${y} ${a?x:""}`}),enabled:!1});function k(G){if(G.toLowerCase().includes("bar"))f("bar");else if(G.toLowerCase().includes("line"))f("line");else if(G.toLowerCase().includes("bubble"))f("bubble");else if(G.toLowerCase().includes("scatter"))f("scatter");else if(G.toLowerCase().includes("stacked"))f("stackedBar");else if(G.toLowerCase().includes("pie"))f("pie");else if(G.toLowerCase().includes("donut")||G.toLowerCase().includes("doughnut"))f("doughnut");else if(G.toLowerCase().includes("radar"))f("radar");else return f("bar"),!1;return!0}function M(){n&&(k(n)&&l(!0),O())}m.useEffect(()=>{i&&(M(),o(!1))},[i,o]);const N={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"5px",width:"100%"},F={fontFamily:"monospace",fontSize:14,lineHeight:1.6},j={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},B={p:({node:G,...te})=>_.jsx("p",{style:N,...te}),pre:({node:G,...te})=>_.jsxs("pre",{className:" bg-muted/50 space-y-2 p-3 rounded-sm",style:F,children:[_.jsx("code",{className:" whitespace-normal",children:te.children}),_.jsxs("div",{className:" flex justify-start gap-2",children:[_.jsx(ot,{onClick:V,size:"sm",variant:"outline",children:_.jsx(x2,{})}),_.jsx(ot,{onClick:$=>{const Z=V($);Z&&(t(!1),c(Z),d(!0))},size:"sm",variant:"outline",children:_.jsx(Cz,{})})]})]}),li:({node:G,...te})=>_.jsx("li",{style:j,...te})};function V(G){const te=G.currentTarget.closest("pre");if(!te)return;const $=te.textContent||te.innerText;return navigator.clipboard.writeText($).then(()=>console.log("Text copied to clipboard")).catch(Z=>console.error("Error in copying text: ",Z)),$}return _.jsxs(Ay,{open:e,onOpenChange:t,children:[_.jsx(Iy,{asChild:!0,children:_.jsx(ot,{size:"sm",className:"",variant:"outline",children:_.jsx(iH,{strokeWidth:1,size:16})})}),_.jsxs(Lp,{className:" sm:max-w-[425px] md:min-w-[625px] md:max-h-[625px] flex flex-col justify-between overflow-auto",children:[_.jsxs(Fp,{children:[_.jsx($p,{children:"Ask"}),_.jsx(jp,{children:"Need assistance? Feel free to ask me any question!"})]}),_.jsx(Tl,{className:"h-[625px] w-full border-t border-t-muted ",children:(!S||!C)&&_.jsx(cre,{className:" pl-1 pr-3 py-1 w-full xbg-red-100 overflow-auto ",components:B,children:w==null?void 0:w.response})}),_.jsxs("div",{children:[_.jsx(wf,{className:ke(" invisible h-1 w-full animate-pulse",{visible:S||C})}),_.jsxs("div",{className:" border rounded-md flex items-center w-full",children:[_.jsx(Zy,{onKeyDown:G=>{G.key==="Enter"&&!G.shiftKey&&(G.preventDefault(),r(""),M())},placeholder:"Type something...",onFocus:G=>{const te=G.target,$=te.value.length;te.setSelectionRange($,$)},className:" border-none resize-none min-h-7 max-h-10 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",value:n,onChange:G=>r(G.target.value)})," ",_.jsx(ot,{className:"h-8",size:"sm",variant:"ghost",onClick:M,children:!S&&!C?_.jsx(_z,{}):_.jsx(Al,{className:" w-4 h-4 animate-spin mr-2 text-foreground/50"})})]})]})]})]})}function hre(){const{theme:e}=$m(),t=m.useRef(),n=m.useRef(),[r,i]=m.useState(!1),[o,s]=m.useState(!1),[a,l]=m.useState(""),[c,d]=m.useState(!1);m.useState("");const{authToken:f}=oo();ge(le=>le.selectedSheetId);const g=ve(le=>le.card),p=ge(le=>le.theme),v=ve(le=>le.isShowingVisual),y=ve(le=>le.selectedConnectionId),x=ve(le=>le.selectedDatabaseName),w=ve(le=>le.selectedSchemaName);ge(le=>le.actions.updateFrameCard);const S=ve(le=>le.selectedTableName),C=ve(le=>le.actions.setCardSql),P=ve(le=>le.card.sql),O=ve(le=>le.selectedConnectionId),k=ve(le=>le.frame),M=ve(le=>le.filterValues),N=ve(le=>le.applyFilters),F=ve(le=>le.actions.setCardCustomCfg),j=ve(le=>le.actions.setFilterValues),B=ve(le=>le.onSave),V=ve(le=>le.actions.setApplyFilters),G=ve(le=>le.onClose),te=ve(le=>le.actions.setCardData),$=ve(le=>le.actions.setSqlGen),Z=ve(le=>le.runSql),q=ve(le=>le.actions.setRunSql),X=ve(le=>le.actions.setIsSqlRunning),{data:ae,isLoading:A,isFetching:H,isSuccess:ie,isError:R,error:ue,status:ye,refetch:pe}=vi({queryKey:[P],queryFn:()=>zc("https://semaphor.cloud/api/v1/query",(f==null?void 0:f.accessToken)||"",{connection_id:O,sql:P,active_filters:N?M:[]}),enabled:!1,retry:!1});m.useEffect(()=>{ae&&(console.log("queryData",ae),te(ae.records))},[ae,te]),m.useEffect(()=>{Z&&(pe(),q(!1))},[Z,pe,q]),m.useEffect(()=>{(A||H)&&X(!0),(R||ie)&&X(!1)},[A,H,R,ie,X]);function he(){C(""),te([]),$({}),F("")}const ne=le=>{n.current=le};function J(){let le=P;P&&!P.includes("{{")&&(le=AZ(P),C(le));const je={...g,lastSelectedSchema:w,lastSelectedDatabase:x,lastSelectedTable:S,connectionId:y,type:v?g.type:"table",sql:le,customCfg:v?g.customCfg:null},Ue=k.cards.map(tt=>tt.id===g.id?je:tt);B==null||B({...k,cards:Ue})}function re(){G==null||G()}function we(le){const je=getComputedStyle(document.documentElement).getPropertyValue(le);return U(je)}function U(le){const[je,Ue,tt]=le.split(" "),qe=parseFloat(je),gt=parseFloat(Ue),Gt=parseFloat(tt),Bt=gt/100,gn=Gt/100,Rt=(1-Math.abs(2*gn-1))*Bt,mr=Rt*(1-Math.abs(qe/60%2-1)),fe=gn-Rt/2;let Ce=0,Ae=0,We=0;0<=qe&&qe<60?(Ce=Rt,Ae=mr,We=0):60<=qe&&qe<120?(Ce=mr,Ae=Rt,We=0):120<=qe&&qe<180?(Ce=0,Ae=Rt,We=mr):180<=qe&&qe<240?(Ce=0,Ae=mr,We=Rt):240<=qe&&qe<300?(Ce=mr,Ae=0,We=Rt):300<=qe&&qe<360&&(Ce=Rt,Ae=0,We=mr),Ce=Math.round((Ce+fe)*255),Ae=Math.round((Ae+fe)*255),We=Math.round((We+fe)*255);const lt=ln=>{const cn=ln.toString(16);return cn.length==1?"0"+cn:cn};return`#${lt(Ce)}${lt(Ae)}${lt(We)}`}m.useEffect(()=>{const le=t.current,je=n.current;if(le){const Ue=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",tt=p==="system"?Ue:p;le.editor.defineTheme("default",{base:tt==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":tt==="light"?"#ffffff":we("--background")}}),le.editor.setTheme("default")}return je&&le&&je.addCommand(le.KeyMod.Shift|le.KeyCode.Enter,function(){return console.log("Executing query..."),pe(),!1}),()=>{}},[e,p,t.current]);function Ne(le){t.current=le}return _.jsxs("section",{role:"editor-section",className:"grow flex flex-col justify-end pt-3 p-1 ",children:[_.jsxs("div",{className:" grow flex relative overflow-y-scroll justify-between ",children:[_.jsx("div",{role:"editor-container",className:`flex ${r?"w-2/3":"w-[95%]"} xbg-red-100 p-1`,children:_.jsx(qy,{theme:"default",onChange:le=>{C(le),console.log(le)},value:P,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",defaultValue:"SELECT * FROM table",beforeMount:Ne,onMount:ne})}),r&&_.jsx("div",{className:" w-1/3 text-xs relative overflow-hidden xbg-yellow-100 p-1 ",children:_.jsxs("div",{className:"min-h-0 ",children:[_.jsxs("div",{className:"flex gap-2 items-center",children:[_.jsx(UZ,{checked:N,onCheckedChange:()=>V(!N),text:"Apply Filters"}),_.jsx(qZ,{})]}),_.jsx(qy,{theme:"default",onChange:le=>{if(le)try{JSON.parse(le),j(JSON.parse(le))}catch{}},defaultLanguage:"json",className:"min-h-[220px] mt-1",value:JSON.stringify(M,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}),M&&r&&_.jsx(ua,{onClick:()=>i(!1),className:"absolute right-6 top-1 w-3 h-3 text-foreground/50 hover:text-foreground hover:cursor-pointer"}),M&&!r&&_.jsx(IO,{onClick:()=>i(!0),className:ke("absolute right-6 top-1 w-3 h-3 text-foreground/50 hover:text-foreground hover:cursor-pointer",{"text-red-800 font-bold":N})})]}),_.jsxs("div",{className:" flex grow px-6 pt-3 pb-4 gap-2 justify-between item-center",children:[_.jsxs("div",{className:"flex grow gap-2 items-center",children:[_.jsxs(ot,{disabled:A||H,onClick:()=>{pe()},className:" shrink-0",size:"sm",variant:"outline",children:[(A||H)&&_.jsx(Al,{className:"w-4 h-4 mr-2 animate-spin text-foreground/50"}),"Run"]}),R&&_.jsx(WZ,{error:ue.message}),_.jsx(ot,{onClick:he,className:"",size:"sm",variant:"outline",children:"Clear"}),_.jsx(Oo,{value:a,placeholder:"Type something...",onChange:le=>{l(le.target.value)},onKeyDown:le=>{le.key==="Enter"&&(le.preventDefault(),console.log("enter pressed"),d(!0),s(!0))},className:" bg-muted border-none h-9 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"}),_.jsx(fre,{open:o,setOpen:s,userInput:a,triggerAIRun:c,setTriggerAIRun:d,setUserInput:le=>l(le)})]}),_.jsxs("div",{className:"flex gap-2 items-end ",children:[_.jsx(ot,{onClick:J,size:"sm",variant:"outline",children:_.jsx(tp,{size:16,strokeWidth:2,className:"text-green-600 font-bold"})}),_.jsx(ot,{onClick:re,className:" w-full",size:"sm",variant:"outline",children:_.jsx(ua,{})})]})]})]})}const o5="Switch",[pre,Yfe]=kn(o5),[gre,mre]=pre(o5),vre=m.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:i,defaultChecked:o,required:s,disabled:a,value:l="on",onCheckedChange:c,...d}=e,[f,g]=m.useState(null),p=rt(t,S=>g(S)),v=m.useRef(!1),y=f?!!f.closest("form"):!0,[x=!1,w]=Qn({prop:i,defaultProp:o,onChange:c});return m.createElement(gre,{scope:n,checked:x,disabled:a},m.createElement(He.button,se({type:"button",role:"switch","aria-checked":x,"aria-required":s,"data-state":s5(x),"data-disabled":a?"":void 0,disabled:a,value:l},d,{ref:p,onClick:Oe(e.onClick,S=>{w(C=>!C),y&&(v.current=S.isPropagationStopped(),v.current||S.stopPropagation())})})),y&&m.createElement(xre,{control:f,bubbles:!v.current,name:r,value:l,checked:x,required:s,disabled:a,style:{transform:"translateX(-100%)"}}))}),bre="SwitchThumb",yre=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,i=mre(bre,n);return m.createElement(He.span,se({"data-state":s5(i.checked),"data-disabled":i.disabled?"":void 0},r,{ref:t}))}),xre=e=>{const{control:t,checked:n,bubbles:r=!0,...i}=e,o=m.useRef(null),s=zp(n),a=Vh(t);return m.useEffect(()=>{const l=o.current,c=window.HTMLInputElement.prototype,f=Object.getOwnPropertyDescriptor(c,"checked").set;if(s!==n&&f){const g=new Event("click",{bubbles:r});f.call(l,n),l.dispatchEvent(g)}},[s,n,r]),m.createElement("input",se({type:"checkbox","aria-hidden":!0,defaultChecked:n},i,{tabIndex:-1,ref:o,style:{...e.style,...a,position:"absolute",pointerEvents:"none",opacity:0,margin:0}}))};function s5(e){return e?"checked":"unchecked"}const a5=vre,wre=yre,l5=de.forwardRef(({className:e,...t},n)=>_.jsx(a5,{className:ke("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:_.jsx(wre,{className:ke("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));l5.displayName=a5.displayName;function c5({className:e,...t}){const[n,r]=m.useState(0),i=ge(l=>l.themeStyle),o=ve(l=>l.card),s=ve(l=>l.actions.setCard);if(m.useEffect(()=>{r(n+1)},[o.data,o.type,o.cfg,o.customCfg,i]),!o.id)return null;let a;return o.data&&o.data.length>0&&(a=w0({data:o.data,cardType:o.type,cfg:o.cfg,customCfg:o.customCfg})),_.jsxs(Vv,{role:"editor-visual-card",className:ke(" relative h-full flex flex-col rounded-none",e),...t,children:[_.jsxs(Gf,{children:[_.jsx(Xo,{text:o.title,onSave:l=>s({...o,title:l}),children:_.jsx(Yf,{className:"text-base",children:o.title})}),_.jsx(Xo,{text:o.description||"",onSave:l=>s({...o,description:l}),children:_.jsxs(Hv,{children:[" ",o.description]})})]}),_.jsxs(Kf,{className:"flex flex-col pb-3 grow",children:[o.type!=="table"&&a&&_.jsx(b2,{cfg:a},n),o.type==="table"&&o.data&&o.data.length>0&&_.jsx(yO,{children:_.jsx(h0,{data:o==null?void 0:o.data})})]})]})}function _re(){const[e,t]=m.useState(!1),[n,r]=m.useState(""),[i,o]=m.useState(""),[s,a]=m.useState(""),l=ve(x=>x.card),c=ve(x=>x.card.customCfg),d=ve(x=>x.actions.setCardCustomCfg);function f(x){var C,P;const w={...x,data:{...x==null?void 0:x.data,datasets:(P=(C=x==null?void 0:x.data)==null?void 0:C.datasets)==null?void 0:P.map(O=>({...O,data:[]}))}};return JSON.stringify(w,null,1)}function g(){if(!l.data||l.data.length===0)return;const x=w0({data:l.data,cardType:l.type,cfg:l.cfg});x&&(r(JSON.stringify(x,null,1)),c&&o(JSON.stringify(c,null,1)))}function p(){if(i)try{const x=JSON.parse(i);return x?(d(x),a(""),o(""),x):void 0}catch(x){console.log(x),a("Invalid JSON")}}function v(){o(""),d(null)}function y(){let x;if(c){const w=Hs.cloneDeep(l.cfg),S=Hs.merge(w,c);return x=f(S),x}return n?(x=f(JSON.parse(n)),x):""}return _.jsxs(Ay,{open:e,onOpenChange:t,children:[_.jsx(Iy,{asChild:!0,children:_.jsx(ot,{onClick:g,className:`h-7 ${c&&"border-foreground/50 dark:border-foreground/70"}`,size:"sm",variant:"outline",children:c?"Custom Config":"Customize"})}),_.jsxs(Lp,{className:" min-h-[70vh] max-h-[70vh] overflow-auto min-w-[900px] ",children:[_.jsxs(Fp,{className:"",children:[_.jsx($p,{children:"Customize Chart"}),_.jsxs(jp,{children:["See the configuration options and documentation",_.jsx("a",{target:"_blank",className:"ml-1 underline text-blue-500 ",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),_.jsxs("div",{className:"flex grow gap-2 ",children:[_.jsx(c5,{className:" w-1/2 rounded shadow-none"}),_.jsxs(P_,{defaultValue:"custom-config",className:" w-1/2 flex flex-col ",children:[_.jsxs(k_,{className:" justify-start border rounded-sm rounded-b-none border-b-0 ",children:[_.jsxs(qm,{value:"custom-config",children:[c&&_.jsx(y2,{className:"w-5 h-5 mr-1 text-green-600"}),c?"Custom Config":"Default Config"]}),_.jsx(qm,{className:"",value:"output",children:"Output"})]}),_.jsx(Ef,{className:" grow mt-0 bg-red-x p-2 border border-t-0 rounded-b ",value:"output",children:_.jsx(Zy,{disabled:!0,value:n,className:" border-none resize-none font-mono h-full focus-visible:ring-0 focus-visible:ring-offset-0"})}),_.jsx(Ef,{className:"grow mt-0 border border-t-0 rounded-b ",value:"custom-config",children:_.jsx(qy,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"json",value:y(),onChange:x=>o(x)})})]})]}),_.jsxs(Ny,{className:"flex items-center",children:[_.jsx(ti,{className:"text-red-500 mr-2",children:s}),_.jsx(ot,{disabled:!c,onClick:v,variant:"outline",children:"Reset"}),_.jsx(ot,{onClick:p,variant:"outline",children:"Apply"}),_.jsx(ot,{onClick:()=>t(!1),variant:"outline",children:"Close"})]})]})]})}var u5={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},d5=m.createContext&&m.createContext(u5),Sre=["attr","size","title"];function Cre(e,t){if(e==null)return{};var n=Ere(e,t),r,i;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(i=0;i<o.length;i++)r=o[i],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function Ere(e,t){if(e==null)return{};var n={},r=Object.keys(e),i,o;for(o=0;o<r.length;o++)i=r[o],!(t.indexOf(i)>=0)&&(n[i]=e[i]);return n}function hg(){return hg=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},hg.apply(this,arguments)}function f5(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function pg(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?f5(Object(n),!0).forEach(function(r){Ore(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):f5(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function Ore(e,t,n){return t=Pre(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Pre(e){var t=kre(e,"string");return typeof t=="symbol"?t:String(t)}function kre(e,t){if(typeof e!="object"||e===null)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function h5(e){return e&&e.map((t,n)=>m.createElement(t.tag,pg({key:n},t.attr),h5(t.child)))}function ic(e){return t=>m.createElement(Dre,hg({attr:pg({},e.attr)},t),h5(e.child))}function Dre(e){var t=n=>{var{attr:r,size:i,title:o}=e,s=Cre(e,Sre),a=i||n.size||"1em",l;return n.className&&(l=n.className),e.className&&(l=(l?l+" ":"")+e.className),m.createElement("svg",hg({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,r,s,{className:l,style:pg(pg({color:e.color||n.color},n.style),e.style),height:a,width:a,xmlns:"http://www.w3.org/2000/svg"}),o&&m.createElement("title",null,o),e.children)};return d5!==void 0?m.createElement(d5.Consumer,null,n=>t(n)):t(u5)}function p5(e){return ic({tag:"svg",attr:{viewBox:"0 0 1024 1024"},child:[{tag:"path",attr:{d:"M926.8 397.1l-396-288a31.81 31.81 0 0 0-37.6 0l-396 288a31.99 31.99 0 0 0-11.6 35.8l151.3 466a32 32 0 0 0 30.4 22.1h489.5c13.9 0 26.1-8.9 30.4-22.1l151.3-466c4.2-13.2-.5-27.6-11.7-35.8zM838.6 417l-98.5 32-200-144.7V199.9L838.6 417zM466 567.2l-89.1 122.3-55.2-169.2L466 567.2zm-116.3-96.8L484 373.3v140.8l-134.3-43.7zM512 599.2l93.9 128.9H418.1L512 599.2zm28.1-225.9l134.2 97.1L540.1 514V373.3zM558 567.2l144.3-46.9-55.2 169.2L558 567.2zm-74-367.3v104.4L283.9 449l-98.5-32L484 199.9zM169.3 470.8l86.5 28.1 80.4 246.4-53.8 73.9-113.1-348.4zM327.1 853l50.3-69h269.3l50.3 69H327.1zm414.5-33.8l-53.8-73.9 80.4-246.4 86.5-28.1-113.1 348.4z"},child:[]}]})(e)}function g5(e){return ic({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm87.63,96H191.48A64.1,64.1,0,0,0,136,64.52V40.37A88.13,88.13,0,0,1,215.63,120ZM120,120H80.68A48.09,48.09,0,0,1,120,80.68Zm0,16v39.32A48.09,48.09,0,0,1,80.68,136Zm16,0h39.32A48.09,48.09,0,0,1,136,175.32Zm0-16V80.68A48.09,48.09,0,0,1,175.32,120ZM120,40.37V64.52A64.1,64.1,0,0,0,64.52,120H40.37A88.13,88.13,0,0,1,120,40.37ZM40.37,136H64.52A64.1,64.1,0,0,0,120,191.48v24.15A88.13,88.13,0,0,1,40.37,136ZM136,215.63V191.48A64.1,64.1,0,0,0,191.48,136h24.15A88.13,88.13,0,0,1,136,215.63Z"},child:[]}]})(e)}function m5(e){return ic({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M137,28.05a11.94,11.94,0,0,0-9.12,3.08A12.09,12.09,0,0,0,124,40V80.67a11.88,11.88,0,0,0,9.9,11.81,36,36,0,1,1-41.85,37.4c-.47-9.14,1.47-16.8,5.75-22.79h0a11.89,11.89,0,0,0-1.3-15.35L68.87,63.51a12,12,0,0,0-17.74.83A99.6,99.6,0,0,0,57.79,199.2,99.24,99.24,0,0,0,128,228h1.43A100.29,100.29,0,0,0,228,129.42C228.72,77.21,188.76,32.68,137,28.05ZM57.28,69.46A4,4,0,0,1,60.2,68h.19a3.91,3.91,0,0,1,2.79,1.14L90.81,97.36a3.93,3.93,0,0,1,.48,5.08A40.47,40.47,0,0,0,84.08,124h-48A90.36,90.36,0,0,1,57.28,69.46ZM36.09,132H84.18A44,44,0,0,0,124,171.81V219.9A92,92,0,0,1,36.09,132ZM193,193a91.43,91.43,0,0,1-61,26.92V171.82a43.51,43.51,0,0,0,26-11.63,44,44,0,0,0-22.79-75.6A4,4,0,0,1,132,80.67V40a4,4,0,0,1,1.31-3,3.89,3.89,0,0,1,3-1c47.59,4.26,84.34,45.24,83.67,93.29A91.42,91.42,0,0,1,193,193Z"},child:[]}]})(e)}function v5(e){return ic({tag:"svg",attr:{viewBox:"0 0 24 24",strokeWidth:"2",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},child:[]},{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(e)}function b5(e){return ic({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M4 9h4v11H4zM4 4h4v4H4zM10 7h4v4h-4zM16 10h4v4h-4zM16 15h4v5h-4zM10 12h4v8h-4z"},child:[]}]})(e)}function y5(e){return ic({tag:"svg",attr:{version:"1.2",baseProfile:"tiny",viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M4 18c-.552 0-1-.448-1-1v-6.382l-.553.276c-.495.248-1.095.046-1.342-.447-.247-.494-.046-1.094.448-1.342l2-1c.31-.155.678-.139.973.044.294.183.474.504.474.851v8c0 .552-.448 1-1 1zM13 18h-5c-.404 0-.769-.244-.924-.617-.155-.374-.069-.804.217-1.09l4-4c.254-.254.394-.591.394-.95 0-.358-.14-.695-.394-.949-.508-.508-1.39-.508-1.9.001-.253.252-.393.589-.393.948 0 .552-.448 1-1 1s-1-.448-1-1c0-.894.348-1.733.98-2.364 1.265-1.263 3.464-1.263 4.727.001.632.631.979 1.471.979 2.363 0 .893-.348 1.733-.979 2.364l-2.293 2.293h2.586c.552 0 1 .448 1 1s-.448 1-1 1zM20.955 12.377c.338-.457.545-1.016.545-1.627 0-1.517-1.234-2.75-2.75-2.75-1.031 0-1.966.569-2.44 1.484-.254.49-.063 1.094.428 1.348.49.254 1.094.062 1.348-.428.128-.249.383-.404.664-.404.414 0 .75.336.75.75s-.336.75-.75.75c-.552 0-1 .448-1 1s.448 1 1 1c.689 0 1.25.561 1.25 1.25s-.561 1.25-1.25 1.25-1.25-.561-1.25-1.25c0-.552-.448-1-1-1s-1 .448-1 1c0 1.792 1.458 3.25 3.25 3.25s3.25-1.458 3.25-3.25c0-.939-.406-1.779-1.045-2.373z"},child:[]}]})(e)}function Mre(){const[e,t]=m.useState(!1),n=ve(s=>s.card.type),r=ve(s=>s.actions.setCardType),i=ve(s=>s.actions.setCardCustomCfg);function o(s){r(s),i(null),t(!1)}return _.jsxs(Vu,{open:e,onOpenChange:t,children:[_.jsx(Hu,{asChild:!0,children:_.jsx(ot,{className:"h-7 px-2",variant:"outline",children:_.jsx(Tre,{className:"h-4 w-4",chartType:n})})}),_.jsx(zl,{className:"w-50",children:_.jsxs("div",{className:"grid grid-cols-3 place-items-center ",children:[_.jsx(ot,{onClick:()=>o("bar"),className:"font-normal",variant:"ghost",children:_.jsx(MO,{strokeWidth:1})}),_.jsx(ot,{onClick:()=>o("line"),variant:"ghost",children:_.jsx(NO,{strokeWidth:1})}),_.jsx(ot,{onClick:()=>o("stackedBar"),variant:"ghost",children:_.jsx(b5,{className:"h-6 w-6 text-foreground/50 ",strokeWidth:0})}),_.jsx(ot,{onClick:()=>o("scatter"),variant:"ghost",children:_.jsx(FO,{strokeWidth:1})}),_.jsx(ot,{onClick:()=>o("bubble"),variant:"ghost",children:_.jsx(v5,{strokeWidth:2})}),_.jsx(ot,{onClick:()=>o("pie"),variant:"ghost",children:_.jsx(RO,{strokeWidth:1})}),_.jsx(ot,{onClick:()=>o("doughnut"),variant:"ghost",children:_.jsx(m5,{className:"h-7 w-7",strokeWidth:.5})}),_.jsx(ot,{onClick:()=>o("radar"),variant:"ghost",children:_.jsx(p5,{className:"h-6 w-6 text-foreground/50 font-extralight",strokeWidth:.5})}),_.jsx(ot,{onClick:()=>o("polarArea"),variant:"ghost",children:_.jsx(g5,{className:"h-6 w-6 text-foreground/50",strokeWidth:1})}),_.jsx(ot,{onClick:()=>o("table"),variant:"ghost",children:_.jsx(b0,{className:"h-6 w-6 text-foreground/90",strokeWidth:1})}),_.jsx(ot,{onClick:()=>o("kpi"),variant:"ghost",children:_.jsx(y5,{className:"h-6 w-6 text-foreground/70",strokeWidth:0})})]})})]})}function Tre({chartType:e,className:t}){switch(e){case"bar":return _.jsx(MO,{className:t});case"line":return _.jsx(NO,{className:t});case"pie":return _.jsx(RO,{className:t});case"radar":return _.jsx(p5,{className:t});case"scatter":return _.jsx(FO,{className:t});case"bubble":return _.jsx(v5,{className:t});case"doughnut":return _.jsx(m5,{className:t});case"stackedBar":return _.jsx(b5,{className:"h-5 w-5 text-foreground/50 ",strokeWidth:0});case"polarArea":return _.jsx(g5,{className:t});case"kpi":return _.jsx(y5,{className:t});default:return _.jsx(b0,{className:t})}}function Are(){const e=ve(n=>n.card.refreshInterval),t=ve(n=>n.actions.setCardRefreshInterval);return _.jsxs(Vu,{children:[_.jsx(Hu,{asChild:!0,children:_.jsx(ot,{className:"h-7",variant:"outline",children:"Realtime"})}),_.jsx(zl,{className:"w-[200px]",children:_.jsx("div",{className:"grid gap-4",children:_.jsx("div",{className:"grid gap-2",children:_.jsxs("div",{className:"grid grid-cols-5 items-center gap-1",children:[_.jsx(ti,{className:"col-span-3",htmlFor:"width",children:"Refresh Every"}),_.jsx(Oo,{value:e||"",onChange:n=>t(n.target.value),id:"width",placeholder:"30s",className:"col-span-2 h-7 focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0"})]})})})})]})}function x5(){ve(r=>r.frame);const e=ve(r=>r.card),t=ve(r=>r.isShowingVisual),n=ve(r=>r.isSqlRunning);return ve(r=>r.onSave),ve(r=>r.onClose),ve(r=>r.actions.setCardSql),ve(r=>r.actions.setCardType),ve(r=>r.actions.setSqlGen),e?_.jsxs("div",{className:" h-full relative flex flex-col",children:[n&&_.jsx(Al,{className:" w-10 h-10 z-10 absolute m-auto left-0 right-0 top-0 bottom-0 animate-spin text-foreground/10 "}),_.jsxs("div",{className:" h-10 px-6 pt-6 bg-red-x100 mb-0 z-10 right-0 flex justify-end items-center gap-2",children:[t&&_.jsxs("div",{className:"bg-red-x00 flex grow gap-2",children:[_.jsx(Mre,{}),_.jsx(_re,{}),_.jsx(Are,{})]}),_.jsx(Ire,{})]}),t?e.type==="kpi"?_.jsx("div",{className:"grow flex items-center justify-center ",children:_.jsx("div",{className:" w-1/2 border rounded-md",children:_.jsx(jO,{isLoading:n,card:e})})}):_.jsx(c5,{className:"grow border-none shadow-none "}):_.jsx("div",{className:"w-full mt-4 px-6 bg-red-x00 grow border-none shadow-none overflow-y-auto ",children:e.data&&e.data.length>0&&_.jsx(h0,{data:e.data})})]}):_.jsx(_.Fragment,{children:"No Active Card"})}function Ire(){const e=ve(n=>n.isShowingVisual),t=ve(n=>n.actions.setIsShowingVisual);return _.jsxs("div",{className:" flex items-center space-x-2",children:[_.jsx(ti,{htmlFor:"visualize",children:"Chart"}),_.jsx(l5,{checked:e,onCheckedChange:()=>t(!e),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}const w5="Collapsible",[Nre,_5]=kn(w5),[Rre,Ix]=Nre(w5),Lre=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:i,disabled:o,onOpenChange:s,...a}=e,[l=!1,c]=Qn({prop:r,defaultProp:i,onChange:s});return m.createElement(Rre,{scope:n,disabled:o,contentId:or(),open:l,onOpenToggle:m.useCallback(()=>c(d=>!d),[c])},m.createElement(He.div,se({"data-state":Nx(l),"data-disabled":o?"":void 0},a,{ref:t})))}),Fre="CollapsibleTrigger",$re=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,i=Ix(Fre,n);return m.createElement(He.button,se({type:"button","aria-controls":i.contentId,"aria-expanded":i.open||!1,"data-state":Nx(i.open),"data-disabled":i.disabled?"":void 0,disabled:i.disabled},r,{ref:t,onClick:Oe(e.onClick,i.onOpenToggle)}))}),S5="CollapsibleContent",jre=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,i=Ix(S5,e.__scopeCollapsible);return m.createElement(yn,{present:n||i.open},({present:o})=>m.createElement(zre,se({},r,{ref:t,present:o})))}),zre=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:i,...o}=e,s=Ix(S5,n),[a,l]=m.useState(r),c=m.useRef(null),d=rt(t,c),f=m.useRef(0),g=f.current,p=m.useRef(0),v=p.current,y=s.open||a,x=m.useRef(y),w=m.useRef();return m.useEffect(()=>{const S=requestAnimationFrame(()=>x.current=!1);return()=>cancelAnimationFrame(S)},[]),Vn(()=>{const S=c.current;if(S){w.current=w.current||{transitionDuration:S.style.transitionDuration,animationName:S.style.animationName},S.style.transitionDuration="0s",S.style.animationName="none";const C=S.getBoundingClientRect();f.current=C.height,p.current=C.width,x.current||(S.style.transitionDuration=w.current.transitionDuration,S.style.animationName=w.current.animationName),l(r)}},[s.open,r]),m.createElement(He.div,se({"data-state":Nx(s.open),"data-disabled":s.disabled?"":void 0,id:s.contentId,hidden:!y},o,{ref:d,style:{"--radix-collapsible-content-height":g?`${g}px`:void 0,"--radix-collapsible-content-width":v?`${v}px`:void 0,...e.style}}),y&&i)});function Nx(e){return e?"open":"closed"}const Bre=Lre,Vre=$re,Hre=jre,xs="Accordion",Wre=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[Rx,Ure,qre]=Sf(xs),[gg,Kfe]=kn(xs,[qre,_5]),Lx=_5(),C5=m.forwardRef((e,t)=>{const{type:n,...r}=e,i=r,o=r;return m.createElement(Rx.Provider,{scope:e.__scopeAccordion},n==="multiple"?m.createElement(Xre,se({},o,{ref:t})):m.createElement(Kre,se({},i,{ref:t})))});C5.propTypes={type(e){const t=e.value||e.defaultValue;return e.type&&!["single","multiple"].includes(e.type)?new Error("Invalid prop `type` supplied to `Accordion`. Expected one of `single | multiple`."):e.type==="multiple"&&typeof t=="string"?new Error("Invalid prop `type` supplied to `Accordion`. Expected `single` when `defaultValue` or `value` is type `string`."):e.type==="single"&&Array.isArray(t)?new Error("Invalid prop `type` supplied to `Accordion`. Expected `multiple` when `defaultValue` or `value` is type `string[]`."):null}};const[E5,Gre]=gg(xs),[O5,Yre]=gg(xs,{collapsible:!1}),Kre=m.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:i=()=>{},collapsible:o=!1,...s}=e,[a,l]=Qn({prop:n,defaultProp:r,onChange:i});return m.createElement(E5,{scope:e.__scopeAccordion,value:a?[a]:[],onItemOpen:l,onItemClose:m.useCallback(()=>o&&l(""),[o,l])},m.createElement(O5,{scope:e.__scopeAccordion,collapsible:o},m.createElement(P5,se({},s,{ref:t}))))}),Xre=m.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:i=()=>{},...o}=e,[s=[],a]=Qn({prop:n,defaultProp:r,onChange:i}),l=m.useCallback(d=>a((f=[])=>[...f,d]),[a]),c=m.useCallback(d=>a((f=[])=>f.filter(g=>g!==d)),[a]);return m.createElement(E5,{scope:e.__scopeAccordion,value:s,onItemOpen:l,onItemClose:c},m.createElement(O5,{scope:e.__scopeAccordion,collapsible:!0},m.createElement(P5,se({},o,{ref:t}))))}),[Qre,mg]=gg(xs),P5=m.forwardRef((e,t)=>{const{__scopeAccordion:n,disabled:r,dir:i,orientation:o="vertical",...s}=e,a=m.useRef(null),l=rt(a,t),c=Ure(n),f=Ws(i)==="ltr",g=Oe(e.onKeyDown,p=>{var v;if(!Wre.includes(p.key))return;const y=p.target,x=c().filter(F=>{var j;return!((j=F.ref.current)!==null&&j!==void 0&&j.disabled)}),w=x.findIndex(F=>F.ref.current===y),S=x.length;if(w===-1)return;p.preventDefault();let C=w;const P=0,O=S-1,k=()=>{C=w+1,C>O&&(C=P)},M=()=>{C=w-1,C<P&&(C=O)};switch(p.key){case"Home":C=P;break;case"End":C=O;break;case"ArrowRight":o==="horizontal"&&(f?k():M());break;case"ArrowDown":o==="vertical"&&k();break;case"ArrowLeft":o==="horizontal"&&(f?M():k());break;case"ArrowUp":o==="vertical"&&M();break}const N=C%S;(v=x[N].ref.current)===null||v===void 0||v.focus()});return m.createElement(Qre,{scope:n,disabled:r,direction:i,orientation:o},m.createElement(Rx.Slot,{scope:n},m.createElement(He.div,se({},s,{"data-orientation":o,ref:l,onKeyDown:r?void 0:g}))))}),Fx="AccordionItem",[Zre,$x]=gg(Fx),Jre=m.forwardRef((e,t)=>{const{__scopeAccordion:n,value:r,...i}=e,o=mg(Fx,n),s=Gre(Fx,n),a=Lx(n),l=or(),c=r&&s.value.includes(r)||!1,d=o.disabled||e.disabled;return m.createElement(Zre,{scope:n,open:c,disabled:d,triggerId:l},m.createElement(Bre,se({"data-orientation":o.orientation,"data-state":D5(c)},a,i,{ref:t,disabled:d,open:c,onOpenChange:f=>{f?s.onItemOpen(r):s.onItemClose(r)}})))}),eie="AccordionHeader",tie=m.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,i=mg(xs,n),o=$x(eie,n);return m.createElement(He.h3,se({"data-orientation":i.orientation,"data-state":D5(o.open),"data-disabled":o.disabled?"":void 0},r,{ref:t}))}),k5="AccordionTrigger",nie=m.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,i=mg(xs,n),o=$x(k5,n),s=Yre(k5,n),a=Lx(n);return m.createElement(Rx.ItemSlot,{scope:n},m.createElement(Vre,se({"aria-disabled":o.open&&!s.collapsible||void 0,"data-orientation":i.orientation,id:o.triggerId},a,r,{ref:t})))}),rie="AccordionContent",iie=m.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,i=mg(xs,n),o=$x(rie,n),s=Lx(n);return m.createElement(Hre,se({role:"region","aria-labelledby":o.triggerId,"data-orientation":i.orientation},s,r,{ref:t,style:{"--radix-accordion-content-height":"var(--radix-collapsible-content-height)","--radix-accordion-content-width":"var(--radix-collapsible-content-width)",...e.style}}))});function D5(e){return e?"open":"closed"}const oie=C5,sie=Jre,aie=tie,M5=nie,T5=iie,jx=oie,ko=de.forwardRef(({className:e,...t},n)=>_.jsx(sie,{ref:n,className:ke("border-b",e),...t}));ko.displayName="AccordionItem";const Do=de.forwardRef(({className:e,children:t,...n},r)=>_.jsx(aie,{className:"flex",children:_.jsxs(M5,{ref:r,className:ke("flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",e),...n,children:[t,_.jsx(v0,{className:"h-4 w-4 shrink-0 transition-transform duration-200"})]})}));Do.displayName=M5.displayName;const Mo=de.forwardRef(({className:e,children:t,...n},r)=>_.jsx(T5,{ref:r,className:"overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...n,children:_.jsx("div",{className:ke("pb-4 pt-0",e),children:t})}));Mo.displayName=T5.displayName;const A5="Radio",[lie,I5]=kn(A5),[cie,uie]=lie(A5),die=m.forwardRef((e,t)=>{const{__scopeRadio:n,name:r,checked:i=!1,required:o,disabled:s,value:a="on",onCheck:l,...c}=e,[d,f]=m.useState(null),g=rt(t,y=>f(y)),p=m.useRef(!1),v=d?!!d.closest("form"):!0;return m.createElement(cie,{scope:n,checked:i,disabled:s},m.createElement(He.button,se({type:"button",role:"radio","aria-checked":i,"data-state":N5(i),"data-disabled":s?"":void 0,disabled:s,value:a},c,{ref:g,onClick:Oe(e.onClick,y=>{i||l==null||l(),v&&(p.current=y.isPropagationStopped(),p.current||y.stopPropagation())})})),v&&m.createElement(pie,{control:d,bubbles:!p.current,name:r,value:a,checked:i,required:o,disabled:s,style:{transform:"translateX(-100%)"}}))}),fie="RadioIndicator",hie=m.forwardRef((e,t)=>{const{__scopeRadio:n,forceMount:r,...i}=e,o=uie(fie,n);return m.createElement(yn,{present:r||o.checked},m.createElement(He.span,se({"data-state":N5(o.checked),"data-disabled":o.disabled?"":void 0},i,{ref:t})))}),pie=e=>{const{control:t,checked:n,bubbles:r=!0,...i}=e,o=m.useRef(null),s=zp(n),a=Vh(t);return m.useEffect(()=>{const l=o.current,c=window.HTMLInputElement.prototype,f=Object.getOwnPropertyDescriptor(c,"checked").set;if(s!==n&&f){const g=new Event("click",{bubbles:r});f.call(l,n),l.dispatchEvent(g)}},[s,n,r]),m.createElement("input",se({type:"radio","aria-hidden":!0,defaultChecked:n},i,{tabIndex:-1,ref:o,style:{...e.style,...a,position:"absolute",pointerEvents:"none",opacity:0,margin:0}}))};function N5(e){return e?"checked":"unchecked"}const gie=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],R5="RadioGroup",[mie,Xfe]=kn(R5,[dl,I5]),L5=dl(),F5=I5(),[vie,bie]=mie(R5),yie=m.forwardRef((e,t)=>{const{__scopeRadioGroup:n,name:r,defaultValue:i,value:o,required:s=!1,disabled:a=!1,orientation:l,dir:c,loop:d=!0,onValueChange:f,...g}=e,p=L5(n),v=Ws(c),[y,x]=Qn({prop:o,defaultProp:i,onChange:f});return m.createElement(vie,{scope:n,name:r,required:s,disabled:a,value:y,onValueChange:x},m.createElement(Hm,se({asChild:!0},p,{orientation:l,dir:v,loop:d}),m.createElement(He.div,se({role:"radiogroup","aria-required":s,"aria-orientation":l,"data-disabled":a?"":void 0,dir:v},g,{ref:t}))))}),xie="RadioGroupItem",wie=m.forwardRef((e,t)=>{const{__scopeRadioGroup:n,disabled:r,...i}=e,o=bie(xie,n),s=o.disabled||r,a=L5(n),l=F5(n),c=m.useRef(null),d=rt(t,c),f=o.value===i.value,g=m.useRef(!1);return m.useEffect(()=>{const p=y=>{gie.includes(y.key)&&(g.current=!0)},v=()=>g.current=!1;return document.addEventListener("keydown",p),document.addEventListener("keyup",v),()=>{document.removeEventListener("keydown",p),document.removeEventListener("keyup",v)}},[]),m.createElement(Wm,se({asChild:!0},a,{focusable:!s,active:f}),m.createElement(die,se({disabled:s,required:o.required,checked:f},l,i,{name:o.name,ref:d,onCheck:()=>o.onValueChange(i.value),onKeyDown:Oe(p=>{p.key==="Enter"&&p.preventDefault()}),onFocus:Oe(i.onFocus,()=>{var p;g.current&&((p=c.current)===null||p===void 0||p.click())})})))}),_ie=m.forwardRef((e,t)=>{const{__scopeRadioGroup:n,...r}=e,i=F5(n);return m.createElement(hie,se({},i,r,{ref:t}))}),$5=yie,j5=wie,Sie=_ie,z5=de.forwardRef(({className:e,...t},n)=>_.jsx($5,{className:ke("grid gap-2",e),...t,ref:n}));z5.displayName=$5.displayName;const zx=de.forwardRef(({className:e,...t},n)=>_.jsx(j5,{ref:n,className:ke("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:_.jsx(Sie,{className:"flex items-center justify-center",children:_.jsx(AO,{className:"h-2.5 w-2.5 fill-current text-current"})})}));zx.displayName=j5.displayName;function B5(){var i;const e=ve(o=>o.card.cfg),t=ve(o=>o.actions.setCardCfg),n=(i=e==null?void 0:e.options)==null?void 0:i.indexAxis;function r(o){const s={...e,options:{...e==null?void 0:e.options,indexAxis:o}};t(s)}return _.jsxs("div",{children:[_.jsx("p",{className:"font-semibold",children:"Orientation"}),_.jsxs(z5,{value:n,onValueChange:r,className:"flex gap-3 mt-2 ",defaultValue:"x",children:[_.jsxs("div",{className:"flex items-center space-x-2",children:[_.jsx(zx,{value:"x",id:"r1"}),_.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),_.jsxs("div",{className:"flex items-center space-x-2",children:[_.jsx(zx,{value:"y",id:"r2"}),_.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})]})}function V5(){var r,i,o;const e=ve(s=>s.card.cfg),t=ve(s=>s.actions.setCardCfg);function n(s){var c;const a={datalabels:{display:s!=="none",align:s,anchor:s,clamp:!0}},l={...e,options:{...e==null?void 0:e.options,plugins:{...(c=e==null?void 0:e.options)==null?void 0:c.plugins,...a}}};t(l),console.log(s)}return _.jsxs(_.Fragment,{children:[_.jsx("label",{className:"font-medium",children:"Data Labels"}),_.jsxs(MD,{value:(o=(i=(r=e==null?void 0:e.options)==null?void 0:r.plugins)==null?void 0:i.datalabels)==null?void 0:o.anchor,onValueChange:n,defaultValue:"none",children:[_.jsx($y,{className:"w-[180px] mt-2 focus:ring-1 focus:ring-offset-0 h-7",children:_.jsx(AD,{placeholder:"Select position"})}),_.jsx(jy,{children:_.jsxs(TD,{children:[_.jsx(Up,{children:"Data Labels"}),_.jsx(Da,{value:"none",children:"None"}),_.jsx(Da,{value:"start",children:"Start"}),_.jsx(Da,{value:"center",children:"Center"}),_.jsx(Da,{value:"end",children:"End"})]})})]})]})}function H5(){const e=ve(i=>i.card.preferences),t=ve(i=>i.actions.setCardPreferences),n=ve(i=>{var o;return(o=i.card.preferences)==null?void 0:o.filterOnClickField}),r=ve(i=>i.actions.setFilterOnClickField);return _.jsxs("div",{children:[_.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[_.jsx(ad,{checked:!!(e!=null&&e.filterOnClick),onCheckedChange:i=>{t({...e,filterOnClick:!!i})}}),_.jsx(ti,{children:"Filter on click"})]}),(e==null?void 0:e.filterOnClick)===!0&&_.jsxs("div",{className:"flex gap-2 items-center",children:[_.jsx(Oo,{value:n||"",className:" h-7 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"expression (optional)",onChange:i=>r(i.target.value)}),_.jsxs(qh,{children:[_.jsx(Xb,{children:_.jsx(Lb,{className:"h-4 w-4 opacity-70"})}),_.jsx($u,{children:_.jsxs("div",{className:"max-w-[200px]",children:["The x-axis expression of your query. Example:",_.jsx("div",{className:" mt-1 text-xs font-mono",children:"TO_CHAR(order_date, 'YYYY-MM')"})]})})]})]})]})}const Cie={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Eie={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Oie(){const e=ve(t=>t.card.type);return _.jsxs("div",{className:"p-6 space-y-6",children:[_.jsx(jx,{className:" ",type:"single",collapsible:!0,children:Pie(e)}),_.jsx("section",{className:"",children:["line","bar"].includes(e)&&_.jsx(B5,{})}),_.jsx("div",{children:!["kpi"].includes(e)&&_.jsx(V5,{})}),_.jsx("div",{children:!["kpi"].includes(e)&&_.jsx(H5,{})})]})}function Pie(e){if(["line","bar"].includes(e))return _.jsxs(_.Fragment,{children:[_.jsxs(ko,{value:"item-1",children:[_.jsx(Do,{className:" font-normal",children:_.jsx("p",{children:"Chart Query"})}),_.jsxs(Mo,{className:" ",children:[_.jsx("div",{className:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),_.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[_.jsx("li",{children:"X-axis - Category (ex. city)"}),_.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),_.jsxs(ko,{value:"item-2",children:[_.jsx(Do,{className:" font-normal",children:"Mixed Chart"}),_.jsxs(Mo,{className:" text-xs space-y-2",children:[_.jsxs("p",{children:["Click ",_.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),_.jsx("pre",{children:JSON.stringify(Cie,null,2)})]})]}),_.jsxs(ko,{value:"item-3",children:[_.jsx(Do,{className:" font-normal",children:"Area Chart"}),_.jsxs(Mo,{className:" text-xs space-y-2",children:[_.jsxs("p",{children:["Click ",_.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",_.jsx("a",{className:"text-blue-500 hover:underline mx-1",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),_.jsx("pre",{children:JSON.stringify(Eie,null,2)})]})]})]});if(e==="bubble")return _.jsx(_.Fragment,{children:_.jsxs(ko,{value:"item-1",children:[_.jsx(Do,{className:" font-normal",children:_.jsxs("p",{children:["How to create a ",_.jsx("span",{children:e})," chart query?"]})}),_.jsxs(Mo,{className:" ",children:[_.jsx("div",{className:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT label, x-axis, y-axis, radius FROM table"}),_.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[_.jsx("li",{children:"Label - Category (ex. city)"}),_.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),_.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),_.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),_.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(e==="scatter")return _.jsx(_.Fragment,{children:_.jsxs(ko,{value:"item-1",children:[_.jsx(Do,{className:" font-normal",children:_.jsxs("p",{children:["How to create a ",_.jsx("span",{children:e})," chart query?"]})}),_.jsxs(Mo,{className:" ",children:[_.jsx("div",{className:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT label, x-axis, y-axis FROM table"}),_.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[_.jsx("li",{children:"Label - Category (ex. city)"}),_.jsx("li",{children:"Group (opt) - Category (ex. state)"}),_.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),_.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(e))return _.jsx(_.Fragment,{children:_.jsxs(ko,{value:"item-1",children:[_.jsx(Do,{className:" font-normal",children:_.jsxs("p",{children:[_.jsx("span",{children:e==="polarArea"?"Polar":e.charAt(0).toUpperCase()+e.slice(1)})," ","chart query"]})}),_.jsxs(Mo,{className:" ",children:[_.jsx("div",{className:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT label, measure FROM table"}),_.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[_.jsx("li",{children:"Label - Category (ex. city)"}),_.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function kie(){var s,a,l;const e=ve(c=>c.card.preferences),t=ve(c=>c.actions.setCardPreferences),n=ve(c=>c.actions.setNumberFormat),r=ve(c=>{var d,f;return(f=(d=c.card.preferences)==null?void 0:d.formatNumber)==null?void 0:f.format}),i=ve(c=>{var d,f;return(f=(d=c.card.preferences)==null?void 0:d.formatNumber)==null?void 0:f.locale}),o=ve(c=>{var d,f;return(f=(d=c.card.preferences)==null?void 0:d.formatNumber)==null?void 0:f.currency});return ve(c=>c.actions.setFilterOnClickField),_.jsxs("div",{children:[_.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[_.jsx(ad,{checked:!!((s=e==null?void 0:e.formatNumber)!=null&&s.enabled),onCheckedChange:c=>{t({...e,formatNumber:{...e==null?void 0:e.formatNumber,enabled:c}})}}),_.jsx(ti,{children:"Format Number"})]}),((a=e==null?void 0:e.formatNumber)==null?void 0:a.enabled)===!0&&_.jsxs("div",{className:"flex flex-col gap-2 ",children:[_.jsxs("div",{children:[_.jsx(ti,{className:"text-xs",children:"Currency"}),_.jsxs("div",{className:"flex gap-1",children:[_.jsx(Oo,{value:o||"",className:" h-7 w-20 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"USD",onChange:c=>{var d,f,g;return n(((d=e==null?void 0:e.formatNumber)==null?void 0:d.format)||"",c.target.value,((f=e==null?void 0:e.formatNumber)==null?void 0:f.locale)||"",((g=e==null?void 0:e.formatNumber)==null?void 0:g.suffix)||"")}}),_.jsx(Oo,{value:i||"",className:" h-7 w-20 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"en-US",onChange:c=>{var d,f,g;return n(((d=e==null?void 0:e.formatNumber)==null?void 0:d.format)||"",((f=e==null?void 0:e.formatNumber)==null?void 0:f.currency)||"",c.target.value,((g=e==null?void 0:e.formatNumber)==null?void 0:g.suffix)||"")}})]})]}),_.jsxs("div",{children:[_.jsxs("div",{className:" flex gap-1",children:[_.jsx(ti,{className:"text-xs",children:"Format"}),_.jsxs(qh,{children:[_.jsx(Xb,{children:_.jsx(Lb,{strokeWidth:1,className:"h-3 w-3 opacity-70"})}),_.jsx($u,{children:_.jsxs("div",{className:"max-w-[200px]",children:["Format number",_.jsx("div",{className:" mt-1 text-xs font-mono",children:"#.## for 123.43"})]})})]})]}),_.jsx("div",{children:_.jsx(Oo,{value:r||"",className:" h-7 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"###,###.##",onChange:c=>{var d,f,g;return n(c.target.value,((d=e==null?void 0:e.formatNumber)==null?void 0:d.currency)||"",((f=e==null?void 0:e.formatNumber)==null?void 0:f.locale)||"",((g=e==null?void 0:e.formatNumber)==null?void 0:g.suffix)||"")}})})]}),_.jsxs("div",{children:[_.jsx(ti,{className:"text-xs",children:"Suffix"}),_.jsx(Oo,{value:((l=e==null?void 0:e.formatNumber)==null?void 0:l.suffix)||"",className:" h-7 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B",onChange:c=>{var d,f,g;return n(((d=e==null?void 0:e.formatNumber)==null?void 0:d.format)||"",((f=e==null?void 0:e.formatNumber)==null?void 0:f.currency)||"",((g=e==null?void 0:e.formatNumber)==null?void 0:g.locale)||"",c.target.value)}})]})]})]})}function Die(){return _.jsxs("div",{className:"px-6 py-2 space-y-6",children:[_.jsx(jx,{className:" ",type:"single",collapsible:!0,children:_.jsxs(ko,{value:"item-1",children:[_.jsx(Do,{className:" font-normal",children:"KPI query"}),_.jsxs(Mo,{className:" ",children:[_.jsx("div",{className:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT current, previous FROM table"}),_.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[_.jsx("li",{children:"Current - Number (ex. Revenue)"}),_.jsx("li",{children:"Previous - Number (ex. Revenue)"})]})]})]})}),_.jsx("section",{className:"",children:_.jsx(kie,{})}),_.jsx("div",{}),_.jsx("div",{})]})}function Mie(){return _.jsxs("div",{className:"px-6 py-2 space-y-6",children:[_.jsx(jx,{className:" ",type:"single",collapsible:!0,children:_.jsxs(ko,{value:"item-1",children:[_.jsx(Do,{className:" font-normal",children:"Stacked chart query?"}),_.jsxs(Mo,{className:" ",children:[_.jsx("div",{className:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),_.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[_.jsx("li",{children:"X-axis - Category (ex. country)"}),_.jsx("li",{children:"Stack by - Category (ex. city)"}),_.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]})}),_.jsx("section",{className:"",children:_.jsx(B5,{})}),_.jsx("div",{children:_.jsx(V5,{})}),_.jsx("div",{children:_.jsx(H5,{})})]})}function Tie(){const e=ve(n=>n.card.type);function t(n){switch(n){case"stackedBar":return _.jsx(Mie,{});case"kpi":return _.jsx(Die,{});default:return _.jsx(Oie,{})}}return _.jsx(Tl,{className:" text-sm h-full w-full ",children:t(e)})}function Aie(){const e=ve(t=>t.isShowingVisual);return _.jsxs(lM,{direction:"vertical",className:"min-w-full max-w-lg min-h-[250px]",children:[_.jsx(Xp,{className:"flex",minSize:20,defaultSize:40,children:_.jsx(hre,{})}),_.jsx(cM,{className:"border-[1.5px] "}),_.jsx(Xp,{minSize:20,defaultSize:60,children:e?_.jsxs(lM,{direction:"horizontal",children:[_.jsx(_.Fragment,{children:_.jsx(Xp,{className:"flex min-w-[275px]",minSize:20,defaultSize:25,maxSize:30,children:_.jsx(Tie,{})})}),_.jsx(cM,{className:"border-[1.5px] "}),_.jsx(Xp,{minSize:40,defaultSize:75,maxSize:100,children:_.jsx(x5,{})})]}):_.jsx(x5,{})})]})}function Iie({authToken:e,onSave:t,onClose:n}){ve(s=>s.actions.setCard);const r=ve(s=>s.actions.setOnSave),i=ve(s=>s.actions.setOnClose),o=ge(s=>s.actions.setAuthToken);return m.useEffect(()=>{t&&r(t),n&&i(n)},[t,r,n,i]),m.useEffect(()=>{e&&e.accessToken&&o(e)},[e,o]),_.jsxs(cD,{className:"rounded-none",children:[_.jsx(uD,{className:" rounded-none border-r-[3px] ",children:_.jsx(LD,{})}),_.jsx(dD,{children:_.jsx(Aie,{})})]})}function Nie(){ge(s=>s.selectedCardId);const e=ge(s=>s.selectedSheetId),{setIsVisualEditing:t}=ge(s=>s.actions),n=ge(s=>s.isVisualEditing),r=ge(s=>s.actions.updateFrame);function i(s){e&&(r(e,s),t(!1))}function o(){t(!1)}return _.jsx("div",{role:"editor-container",className:ke("grow flex",{block:n,hidden:!n}),children:_.jsx(Iie,{onSave:i,onClose:o})})}function Rie({columns:e,tableName:t}){const n=ve(f=>f.selectedConnectionId),r=ve(f=>f.selectedDatabaseName),i=ve(f=>f.selectedSchemaName),o=ve(f=>f.selectedTableName),s=ge(f=>f.dashboard.filters)||[],a=ge(f=>f.actions.addFilter),l=ge(f=>f.actions.removeFilter),c=ge(f=>f.actions.removeFilterValue);function d(f){const g=_i(f.column_name),p=_i(r||""),v=_i(i||""),y=_i(t),x=s==null?void 0:s.find(w=>w.column===g&&w.table===y&&w.database===p);if(x)c(x.id),l(x.id);else{const w=Ep(v,y),S=`SELECT ${g}, COUNT(*) FROM ${w} GROUP BY ${g} ORDER BY ${g} ASC LIMIT 50`,C=`SELECT min(${g}) as min, max(${g}) as max FROM ${w}`;if(t==="api"&&n){a({id:qo(),column:`${w}.${g}`,title:f.column_name,dataType:f.data_type,table:"api",database:"NA",connectionId:n,sql:xa.includes(f.data_type)?C:S});return}if(!n||!r||!o)throw new Error("missing connectionId, database, or table");a({id:qo(),column:`${w}.${g}`,title:f.column_name,dataType:f.data_type,table:o,database:r,connectionId:n,sql:xa.includes(f.data_type)?C:S})}}return _.jsx(Tl,{className:" h-[70vh] mt-2 xbg-red-100 px-3",children:e==null?void 0:e.map(f=>{const g=s==null?void 0:s.find(p=>p.column===_i(f.column_name)&&p.table===o&&p.database===r);return _.jsx("div",{onClick:()=>d(f),className:ke(" group flex text-sm items-center justify-between px-3 py-[6px] transition-colors hover:bg-muted/50 cursor-pointer border border-background border-dashed",{"bg-muted ":g}),children:_.jsxs("div",{className:"flex items-center gap-2 ",children:[_.jsx(RD,{column:f}),_.jsx("span",{children:f.column_name})]})},f.column_name)})})}function Lie(){ge(t=>t.showFilters);const e=ge(t=>t.actions.setShowFilters);return _.jsxs("section",{className:" relative space-y-4 py-0 px-4 ",children:[_.jsx(ot,{onClick:()=>e(!1),className:" p-0 h-7 w-7 absolute top-0 right-4",variant:"outline",children:_.jsx(ua,{})}),_.jsx("p",{className:"text-md px-2",children:"Data Columns"}),_.jsx("div",{children:_.jsx(LD,{ColumnsComponent:(t,n,r)=>_.jsx(Rie,{schemaName:t,tableName:n,columns:r})})})]})}function Fie(){ge(n=>n.dashboard);const e=ge(n=>n.showFilters),t=ge(n=>n.isVisualEditing);return ge(n=>n.bookmarkKey),_.jsxs("div",{role:"dashboard-plus-main",className:ke(" grow",{hidden:t,flex:!t}),children:[_.jsx(yk,{}),e&&_.jsx("div",{role:"filter-aside-container",children:_.jsx(Lie,{})})]})}function $ie(){const e=ge(r=>r.dashboard),t=ge(r=>r.actions.setDashboard),n=ge(r=>r.showDashboardJSON);return ge(r=>r.actions.setShowDashboardJSON),_.jsx("div",{className:ke(" p-2",{hidden:!n}),children:_.jsx(CM,{onChange:r=>{if(r)try{JSON.parse(r),t(JSON.parse(r))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto ",value:JSON.stringify(e,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})})}function jie({showControls:e=!1,showFooter:t=!0,...n}){return ge(r=>r.isVisualEditing),_.jsx(l_,{dashboardProps:n,children:_.jsxs(vy,{children:[_.jsx($ie,{}),_.jsxs(g_,{...n,children:[e&&_.jsx(yX,{}),_.jsx(Nie,{}),_.jsx(Fie,{})]})]})})}function zie(){const e=ge(t=>t.actions);return{getStyle:e.getStyle,getDashboard:e.getDashboard,setOnSaveFunction:e.setOnSaveFunction,setOnAddCard:e.setOnAddCard,setOnUpateCard:e.setOnUpdateCard,setOnRemoveCard:e.setOnRemoveCard}}$e.BOOLEAN_DATA_TYPES=Sp,$e.DATE_DATA_TYPES=xa,$e.Dashboard=wk,$e.DashboardPlus=jie,$e.DashboardProvider=vy,$e.DashboardWC=vY,$e.NUMBER_DATA_TYPES=hs,$e.SelectComponent=ld,$e.SemaphorQueryClient=xk,$e.TEXT_DATA_TYPES=Gu,$e.cleanCard=Kk,$e.createSqlGenConfig=G0,$e.fmt=_i,$e.getBookmarkKey=ms,$e.getColumnDataType=fU,$e.getDashbaordStateWithoutData=Dy,$e.getFilterValueType=Cp,$e.getQualifiedTableName=Ep,$e.getSql=q0,$e.isColumnInSqlGen=FP,$e.resolveDataType=Fm,$e.useActions=zie,$e.useCard=kH,$e.useDashboard=p_,$e.useDashboardActions=Yc,$e.useDashboardStore=ge,$e.useEditorActions=v4,$e.useEditorAside=c_,$e.useEditorStore=ve,Object.defineProperty($e,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "email": "support@semaphor.cloud"
6
6
  },
7
7
  "license": "MIT",
8
- "version": "0.0.32",
8
+ "version": "0.0.33",
9
9
  "description": "Fully interactive and customizable dashboards for your apps.",
10
10
  "keywords": [
11
11
  "react",