import{b as o,eh as k,d as D,ed as E,L as N,N as R,e as u,W as B,X as L,w as d,u as c,o as V,a as Q,bP as w,aF as S,dd as b,cU as $,cI as x,$ as j}from"./vue-router.85c27f05.js";import{d as z}from"./utils.6ad8b875.js";import{G as A}from"./PhDownloadSimple.vue.3605c6dc.js";import{e as F}from"./toggleHighContrast.789c5cde.js";import"./gateway.aa5a907a.js";import{P as M}from"./project.947f659b.js";import"./tables.8aae1278.js";import"./popupNotifcation.db970277.js";import"./record.b6b15302.js";import"./string.76b61cc9.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},a=new Error().stack;a&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[a]="5e05653b-63dd-4689-a62c-9d0009c53be2",e._sentryDebugIdIdentifier="sentry-dbid-5e05653b-63dd-4689-a62c-9d0009c53be2")}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 a=1;a<arguments.length;a++){var t=arguments[a]!=null?Object(arguments[a]):{},s=Object.keys(t);typeof Object.getOwnPropertySymbols=="function"&&(s=s.concat(Object.getOwnPropertySymbols(t).filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable}))),s.forEach(function(i){H(e,i,t[i])})}return e}function H(e,a,t){return a in e?Object.defineProperty(e,a,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[a]=t,e}var h=function(a,t){var s=O({},a,t.attrs);return o(k,O({},s,{icon:G}),null)};h.displayName="CaretRightOutlined";h.inheritAttrs=!1;const J=h;function U(e){const a={};for(const t in e)if(e.hasOwnProperty(t)){if(typeof e[t]=="object"&&e[t]!==null){a[t]=JSON.stringify(e[t]);continue}a[t]=String(e[t])}return a}const W={class:"container"},X=D({__name:"Sql",setup(e){const t=E().params.projectId,s=new N(R.string(),"lastQuery"),i=u(null),f=u(""),g=u([]),v=u([]),C=u([]),y=u(!1),I=async()=>{y.value=!0;const n=await M.executeQuery(t,f.value,[]);if(y.value=!1,s.set(f.value),!n)return;const{returns:r,errors:p}=n;C.value=p;for(const l of p)x.error({message:"SQL Execution Failed",description:l});p.length||x.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,_)=>U({key:`${_+1}`,...l}))},q=()=>{const n=v.value.map(m=>m.dataIndex),r=v.value.map(m=>m.title),p=g.value.map(m=>n.map(P=>m[P])),_=`data-${new Date().toISOString()}`;z({fileName:_,columns:r,rows:p})};return B(()=>{const n=F.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)=>(V(),L("div",W,[o(c(b),{gap:"large",class:"sql-container",align:"center"},{default:d(()=>[Q("div",{ref_key:"sqlEditor",ref:i,class:"sql-editor"},null,512),o(c(w),{type:"primary",loading:y.value,onClick:I},{icon:d(()=>[o(c(J))]),default:d(()=>[S(" 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(()=>[S(" Export to CSV "),o(c(A))]),_:1})]),_:1},8,["disabled"])]),_:1}),o(c($),{style:{width:"100%"},scroll:{x:100},"data-source":g.value,columns:v.value},null,8,["data-source","columns"])]))}});const le=j(X,[["__scopeId","data-v-a13d7ced"]]);export{le as default};
//# sourceMappingURL=Sql.ca060c02.js.map
