import{b as i,ee as P,d as k,ea as D,L as E,N as _,e as m,W as N,o as R,X as B,w as g,u,a as L,bP as x,aF as S,dd as b,cU as V,cI as I,$}from"./vue-router.e3ef87f0.js";import{d as z}from"./utils.2789cdf5.js";import{G as A}from"./PhDownloadSimple.vue.c60d2774.js";import{e as F}from"./toggleHighContrast.e0066c61.js";import"./gateway.e3730daa.js";import{P as M}from"./project.1af02886.js";import"./tables.8b5b16f2.js";import"./popupNotifcation.bf248d47.js";import"./record.9f354c97.js";import"./string.5524ff61.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},a=new Error().stack;a&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[a]="496e7df9-58e8-4a5d-ad00-261ec19938e3",t._sentryDebugIdIdentifier="sentry-dbid-496e7df9-58e8-4a5d-ad00-261ec19938e3")}catch{}})();var T={icon:{tag:"svg",attrs:{viewBox:"0 0 1024 1024",focusable:"false"},children:[{tag:"path",attrs:{d:"M715.8 493.5L335 165.1c-14.2-12.2-35-1.2-35 18.5v656.8c0 19.7 20.8 30.7 35 18.5l380.8-328.4c10.9-9.4 10.9-27.6 0-37z"}}]},name:"caret-right",theme:"outlined"};const G=T;function O(t){for(var a=1;a<arguments.length;a++){var e=arguments[a]!=null?Object(arguments[a]):{},s=Object.keys(e);typeof Object.getOwnPropertySymbols=="function"&&(s=s.concat(Object.getOwnPropertySymbols(e).filter(function(d){return Object.getOwnPropertyDescriptor(e,d).enumerable}))),s.forEach(function(d){H(t,d,e[d])})}return t}function H(t,a,e){return a in t?Object.defineProperty(t,a,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[a]=e,t}var w=function(a,e){var s=O({},a,e.attrs);return i(P,O({},s,{icon:G}),null)};w.displayName="CaretRightOutlined";w.inheritAttrs=!1;const J=w;function U(t){const a={};for(const e in t)if(t.hasOwnProperty(e)){if(typeof t[e]=="object"&&t[e]!==null){a[e]=JSON.stringify(t[e]);continue}a[e]=String(t[e])}return a}const W={class:"container"},X=k({__name:"Sql",setup(t){const e=D().params.projectId,s=new E(_.array(_.object({projectId:_.string(),lastQuery:_.string()})),"lastQueries"),d=m(null),f=m(""),v=m([]),y=m([]),C=m([]),h=m(!1),Q=async()=>{h.value=!0;const o=await M.executeQuery(e,f.value,[]);h.value=!1;const r=s.get();if(!r)s.set([{projectId:e,lastQuery:f.value}]);else{const n=r.findIndex(l=>l.projectId===e);n===-1?r.push({projectId:e,lastQuery:f.value}):r[n].lastQuery=f.value,s.set(r)}if(!o)return;const{returns:p,errors:c}=o;C.value=c;for(const n of c)I.error({message:"SQL Execution Failed",description:n});c.length||I.success({message:"SQL Execution Succeeded"}),y.value=p.fields.map(n=>({title:n.name,key:n.name,dataIndex:n.name})),v.value=p.result.map((n,l)=>U({key:`${l+1}`,...n}))},q=()=>{const o=y.value.map(l=>l.dataIndex),r=y.value.map(l=>l.title),p=v.value.map(l=>o.map(j=>l[j])),n=`data-${new Date().toISOString()}`;z({fileName:n,columns:r,rows:p})};return N(()=>{var p;const o=F.create(d.value,{language:"sql",value:f.value,fontFamily:"monospace",lineNumbers:"on",minimap:{enabled:!1},scrollbar:{vertical:"hidden",horizontal:"visible"},fontSize:14,scrollBeyondLastLine:!1,lineHeight:20});o.onDidChangeModelContent(()=>{f.value=o.getValue()});const r=s.get();if(r){const c=(p=r.find(n=>n.projectId===e))==null?void 0:p.lastQuery;c&&(f.value=c,o.setValue(c))}}),(o,r)=>(R(),B("div",W,[i(u(b),{gap:"large",class:"sql-container",align:"center"},{default:g(()=>[L("div",{ref_key:"sqlEditor",ref:d,class:"sql-editor"},null,512),i(u(x),{type:"primary",loading:h.value,onClick:Q},{icon:g(()=>[i(u(J))]),default:g(()=>[S(" Run ")]),_:1},8,["loading"])]),_:1}),i(u(b),{justify:"end",style:{margin:"30px 0 10px 0"}},{default:g(()=>[i(u(x),{disabled:!v.value.length,onClick:q},{default:g(()=>[i(u(b),{align:"center",gap:"small"},{default:g(()=>[S(" Export to CSV "),i(u(A))]),_:1})]),_:1},8,["disabled"])]),_:1}),i(u(V),{style:{width:"100%"},scroll:{x:100},"data-source":v.value,columns:y.value},null,8,["data-source","columns"])]))}});const le=$(X,[["__scopeId","data-v-a8dc12c0"]]);export{le as default};
//# sourceMappingURL=Sql.65aa56fb.js.map
