import{b as o,eF as B,d as D,eB as E,L as P,N as R,e as u,$ as j,o as L,eu as N,w as d,u as c,a as V,bH as w,as as S,cW as b,cF as Q,cv as x,S as $}from"./vue-router.74c693f1.js";import{d as F}from"./utils.58e9a36b.js";import{G as z}from"./PhDownloadSimple.vue.d0d9c1d1.js";import{e as A}from"./toggleHighContrast.88ddd545.js";import"./gateway.707771fc.js";import"./index.0791082e.js";import{P as M}from"./project.d7713957.js";import"./popupNotifcation.d39bbf9b.js";import"./record.0d85e3b6.js";import"./string.b1ebfabb.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]="22831ae6-0972-4f0e-9c2f-686e9ad15312",e._sentryDebugIdIdentifier="sentry-dbid-22831ae6-0972-4f0e-9c2f-686e9ad15312")}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 H=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){G(e,i,a[i])})}return e}function G(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(B,O({},s,{icon:H}),null)};h.displayName="CaretRightOutlined";h.inheritAttrs=!1;const W=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"},X=D({__name:"Sql",setup(e){const a=E().params.projectId,s=new P(R.string(),"lastQuery"),i=u(null),f=u(""),g=u([]),v=u([]),C=u([]),_=u(!1),I=async()=>{_.value=!0;const n=await M.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)x.error({message:"SQL Execution Failed",description:l});m.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,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(k=>p[k])),y=`data-${new Date().toISOString()}`;F({fileName:y,columns:r,rows:m})};return j(()=>{const n=A.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)=>(L(),N("div",U,[o(c(b),{gap:"large",class:"sql-container",align:"center"},{default:d(()=>[V("div",{ref_key:"sqlEditor",ref:i,class:"sql-editor"},null,512),o(c(w),{type:"primary",loading:_.value,onClick:I},{icon:d(()=>[o(c(W))]),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(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=$(X,[["__scopeId","data-v-9a10cfc4"]]);export{le as default};
//# sourceMappingURL=Sql.d2093740.js.map
