import{f as o,e6 as k,d as D,ec as E,L as R,N as b,r as p,k as B,a4 as L,b as g,u,aQ as N,o as P,e as V,bQ as w,g as I,db as h,cU as $,cI as S,_ as z}from"./jwt-decode.esm.4aed0432.js";import{o as A,d as F}from"./object.7eca8a34.js";import{G as M}from"./PhDownloadSimple.vue.3da187b1.js";import{e as T}from"./toggleHighContrast.51799ad6.js";import"./router.8e8ef823.js";import{P as G}from"./project.84023183.js";import"./tables.1494ceeb.js";import{_ as H}from"./TablesTabs.vue_vue_type_script_setup_true_lang.8933951b.js";import"./record.c1a2f873.js";import"./string.8136e838.js";import"./Card.d2b6a792.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]="d5a340bc-fe6a-408c-8da0-bcb9280ce6e6",t._sentryDebugIdIdentifier="sentry-dbid-d5a340bc-fe6a-408c-8da0-bcb9280ce6e6")}catch{}})();var U={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 J=U;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){W(t,d,e[d])})}return t}function W(t,a,e){return a in t?Object.defineProperty(t,a,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[a]=e,t}var x=function(a,e){var s=O({},a,e.attrs);return o(k,O({},s,{icon:J}),null)};x.displayName="CaretRightOutlined";x.inheritAttrs=!1;const X=x,Y=D({__name:"Sql",setup(t){const e=E().params.projectId,s=new R(b.array(b.object({projectId:b.string(),lastQuery:b.string()})),"lastQueries"),d=p(null),f=p(""),v=p([]),_=p([]),C=p([]),y=p(!1),Q=async()=>{y.value=!0;const l=await G.executeQuery(e,f.value,[]);y.value=!1;const r=s.get();if(!r)s.set([{projectId:e,lastQuery:f.value}]);else{const n=r.findIndex(c=>c.projectId===e);n===-1?r.push({projectId:e,lastQuery:f.value}):r[n].lastQuery=f.value,s.set(r)}if(!l)return;const{returns:m,errors:i}=l;C.value=i;for(const n of i)S.error({message:"SQL Execution Failed",description:n});i.length||S.success({message:"SQL Execution Succeeded"}),_.value=m.fields.map(n=>({title:n.name,key:n.name,dataIndex:n.name})),v.value=m.result.map((n,c)=>A({key:`${c+1}`,...n}))},j=()=>{const l=_.value.map(c=>c.dataIndex),r=_.value.map(c=>c.title),m=v.value.map(c=>l.map(q=>c[q])),n=`data-${new Date().toISOString()}`;F({fileName:n,columns:r,rows:m})};return B(()=>{var m;const l=T.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});l.onDidChangeModelContent(()=>{f.value=l.getValue()});const r=s.get();if(r){const i=(m=r.find(n=>n.projectId===e))==null?void 0:m.lastQuery;i&&(f.value=i,l.setValue(i))}}),(l,r)=>(P(),L(N,null,[o(H),o(u(h),{gap:"large",class:"sql-container",align:"center"},{default:g(()=>[V("div",{ref_key:"sqlEditor",ref:d,class:"sql-editor"},null,512),o(u(w),{type:"primary",loading:y.value,onClick:Q},{icon:g(()=>[o(u(X))]),default:g(()=>[I(" Run ")]),_:1},8,["loading"])]),_:1}),o(u(h),{justify:"end",style:{margin:"30px 0 10px 0"}},{default:g(()=>[o(u(w),{disabled:!v.value.length,onClick:j},{default:g(()=>[o(u(h),{align:"center",gap:"small"},{default:g(()=>[I(" Export to CSV "),o(u(M))]),_:1})]),_:1},8,["disabled"])]),_:1}),o(u($),{style:{width:"100%"},scroll:{x:100},"data-source":v.value,columns:_.value},null,8,["data-source","columns"])],64))}});const ie=z(Y,[["__scopeId","data-v-71ca01e9"]]);export{ie as default};
//# sourceMappingURL=Sql.cc74e359.js.map
