import{b as o,eE as R,d as k,eA as D,L as P,N as V,e as u,Z as j,o as B,et as L,w as d,u as c,a as N,bG as w,ar as x,cV as b,cE as Q,cu as S,R as A}from"./vue-router.637ad36e.js";import{d as $}from"./utils.85ed511a.js";import{G as z}from"./PhDownloadSimple.vue.8d040345.js";import{e as M}from"./toggleHighContrast.49c6baa3.js";import"./gateway.e1c89e24.js";import"./tables.0c659977.js";import{P as F}from"./project.83f082ba.js";import"./popupNotifcation.498cf509.js";import"./record.833ab838.js";import"./string.876500c9.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},t=new Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="f150fc81-2bce-479a-8e87-d8d20760b410",e._sentryDebugIdIdentifier="sentry-dbid-f150fc81-2bce-479a-8e87-d8d20760b410")}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(e){for(var t=1;t<arguments.length;t++){var a=arguments[t]!=null?Object(arguments[t]):{},s=Object.keys(a);typeof Object.getOwnPropertySymbols=="function"&&(s=s.concat(Object.getOwnPropertySymbols(a).filter(function(i){return Object.getOwnPropertyDescriptor(a,i).enumerable}))),s.forEach(function(i){H(e,i,a[i])})}return e}function H(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}var h=function(t,a){var s=O({},t,a.attrs);return o(R,O({},s,{icon:G}),null)};h.displayName="CaretRightOutlined";h.inheritAttrs=!1;const Z=h;function J(e){const t={};for(const a in e)e.hasOwnProperty(a)&&(t[a]=String(e[a]));return t}const U={class:"container"},W=k({__name:"Sql",setup(e){const a=D().params.projectId,s=new P(V.string(),"lastQuery"),i=u(null),f=u(""),g=u([]),v=u([]),C=u([]),_=u(!1),I=async()=>{_.value=!0;const n=await F.executeQuery(a,f.value,[]);if(_.value=!1,s.set(f.value),!n)return;const{returns:r,errors:m}=n;C.value=m;for(const l of m)S.error({message:"SQL Execution Failed",description:l});m.length||S.success({message:"SQL Execution Succeeded"}),v.value=r.fields.map(l=>({title:l.name,key:l.name,dataIndex:l.name})),g.value=r.result.map((l,y)=>J({key:`${y+1}`,...l}))},q=()=>{const n=v.value.map(p=>p.dataIndex),r=v.value.map(p=>p.title),m=g.value.map(p=>n.map(E=>p[E])),y=`data-${new Date().toISOString()}`;$({fileName:y,columns:r,rows:m})};return j(()=>{const n=M.create(i.value,{language:"sql",value:f.value,fontFamily:"monospace",lineNumbers:"on",minimap:{enabled:!1},scrollbar:{vertical:"hidden",horizontal:"visible"},fontSize:14,scrollBeyondLastLine:!1,lineHeight:20});n.onDidChangeModelContent(()=>{f.value=n.getValue()});const r=s.get();r&&(f.value=r,n.setValue(r))}),(n,r)=>(B(),L("div",U,[o(c(b),{gap:"large",class:"sql-container",align:"center"},{default:d(()=>[N("div",{ref_key:"sqlEditor",ref:i,class:"sql-editor"},null,512),o(c(w),{type:"primary",loading:_.value,onClick:I},{icon:d(()=>[o(c(Z))]),default:d(()=>[x(" Run ")]),_:1},8,["loading"])]),_:1}),o(c(b),{justify:"end",style:{margin:"30px 0 10px 0"}},{default:d(()=>[o(c(w),{disabled:!g.value.length,onClick:q},{default:d(()=>[o(c(b),{align:"center",gap:"small"},{default:d(()=>[x(" Export to CSV "),o(c(z))]),_:1})]),_:1},8,["disabled"])]),_:1}),o(c(Q),{style:{width:"100%"},scroll:{x:100},"data-source":g.value,columns:v.value},null,8,["data-source","columns"])]))}});const le=A(W,[["__scopeId","data-v-a13d7ced"]]);export{le as default};
//# sourceMappingURL=Sql.b1b4a405.js.map
