import{b as o,e6 as R,d as B,e4 as D,L as E,B as y,f as p,J as L,K as k,w as g,u,aL as P,o as V,a as N,bM as w,az as I,da as h,cR as $,cF as S,Q as z}from"./index.b7bd503f.js";import{o as F,d as M}from"./object.f878dd27.js";import{G as A}from"./PhDownloadSimple.vue.27d2e18a.js";import{e as T}from"./toggleHighContrast.d8e8df4b.js";import"./gateway.6db311e2.js";import{P as G}from"./project.1a8e28e5.js";import"./columns.c99cb402.js";import{_ as H}from"./TablesTabs.vue_vue_type_script_setup_true_lang.8a3243e9.js";import"./popupNotifcation.bbf38424.js";import"./record.c86f39d9.js";import"./string.9a3a939b.js";import"./TabPane.3b3150c6.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]="958940f9-f3e4-435a-b6e5-7183ee7ba3f3",t._sentryDebugIdIdentifier="sentry-dbid-958940f9-f3e4-435a-b6e5-7183ee7ba3f3")}catch{}})();var J={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 U=J;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(R,O({},s,{icon:U}),null)};x.displayName="CaretRightOutlined";x.inheritAttrs=!1;const X=x,Y=B({__name:"Sql",setup(t){const e=D().params.projectId,s=new E(y.array(y.object({projectId:y.string(),lastQuery:y.string()})),"lastQueries"),d=p(null),f=p(""),v=p([]),_=p([]),C=p([]),b=p(!1),Q=async()=>{b.value=!0;const l=await G.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(i=>i.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:c}=l;C.value=c;for(const n of c)S.error({message:"SQL Execution Failed",description:n});c.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,i)=>F({key:`${i+1}`,...n}))},j=()=>{const l=_.value.map(i=>i.dataIndex),r=_.value.map(i=>i.title),m=v.value.map(i=>l.map(q=>i[q])),n=`data-${new Date().toISOString()}`;M({fileName:n,columns:r,rows:m})};return L(()=>{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 c=(m=r.find(n=>n.projectId===e))==null?void 0:m.lastQuery;c&&(f.value=c,l.setValue(c))}}),(l,r)=>(V(),k(P,null,[o(H),o(u(h),{gap:"large",class:"sql-container",align:"center"},{default:g(()=>[N("div",{ref_key:"sqlEditor",ref:d,class:"sql-editor"},null,512),o(u(w),{type:"primary",loading:b.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(A))]),_: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 ue=z(Y,[["__scopeId","data-v-71ca01e9"]]);export{ue as default};
//# sourceMappingURL=Sql.490b3310.js.map
