import{b as i,ee as k,d as D,ea as E,N,O as _,e as m,X as P,o as R,Y as B,w as g,u,a as V,bT as x,aG as O,dh as h,cY as L,cM as S,a0 as M}from"./index.0f630b70.js";import{d as $}from"./utils.65c8b3c8.js";import{G as z}from"./PhDownloadSimple.vue.e40cfd6e.js";import{e as A}from"./toggleHighContrast.2b784445.js";import"./gateway.50cd3949.js";import{P as T}from"./project.79269899.js";import"./tables.78c50568.js";import"./popupNotifcation.dd76a56c.js";import"./record.f729e500.js";import"./string.532e13bb.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]="77857200-84d0-4660-b977-6e4f01446480",t._sentryDebugIdIdentifier="sentry-dbid-77857200-84d0-4660-b977-6e4f01446480")}catch{}})();var F={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=F;function I(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){Y(t,d,e[d])})}return t}function Y(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=I({},a,e.attrs);return i(k,I({},s,{icon:G}),null)};w.displayName="CaretRightOutlined";w.inheritAttrs=!1;const H=w;function J(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 X={class:"container"},U=D({__name:"Sql",setup(t){const e=E().params.projectId,s=new N(_.array(_.object({projectId:_.string(),lastQuery:_.string()})),"lastQueries"),d=m(null),f=m(""),v=m([]),y=m([]),C=m([]),b=m(!1),Q=async()=>{b.value=!0;const o=await T.executeQuery(e,f.value,[]);b.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)S.error({message:"SQL Execution Failed",description:n});c.length||S.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)=>J({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()}`;$({fileName:n,columns:r,rows:p})};return P(()=>{var p;const o=A.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",X,[i(u(h),{gap:"large",class:"sql-container",align:"center"},{default:g(()=>[V("div",{ref_key:"sqlEditor",ref:d,class:"sql-editor"},null,512),i(u(x),{type:"primary",loading:b.value,onClick:Q},{icon:g(()=>[i(u(H))]),default:g(()=>[O(" Run ")]),_:1},8,["loading"])]),_:1}),i(u(h),{justify:"end",style:{margin:"30px 0 10px 0"}},{default:g(()=>[i(u(x),{disabled:!v.value.length,onClick:q},{default:g(()=>[i(u(h),{align:"center",gap:"small"},{default:g(()=>[O(" Export to CSV "),i(u(z))]),_:1})]),_:1},8,["disabled"])]),_:1}),i(u(L),{style:{width:"100%"},scroll:{x:100},"data-source":v.value,columns:y.value},null,8,["data-source","columns"])]))}});const le=M(U,[["__scopeId","data-v-a8dc12c0"]]);export{le as default};
//# sourceMappingURL=Sql.1b77527e.js.map
