import{f as o,eD as D,d as E,ey as P,L as R,z as j,r as u,o as B,b as L,eq as Q,w as d,u as c,e as V,bz as w,ak as x,cQ as b,cz as z,cp as S,E as N}from"./outputWidgets.f7b80e9f.js";import{d as $}from"./utils.7b8329eb.js";import{G as A}from"./PhDownloadSimple.vue.eb3a15a1.js";import{e as M}from"./toggleHighContrast.d6977377.js";import"./gateway.58b63376.js";import"./index.f21af923.js";import{P as F}from"./project.4ecb704a.js";import"./popupNotifcation.6f5b518c.js";import"./record.188928bf.js";import"./pubsub.10df5fd2.js";import"./string.18a9daee.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]="f8ff34fa-6266-4e3c-9732-043ae89b77c2",e._sentryDebugIdIdentifier="sentry-dbid-f8ff34fa-6266-4e3c-9732-043ae89b77c2")}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 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){H(e,i,a[i])})}return e}function H(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(D,O({},s,{icon:G}),null)};h.displayName="CaretRightOutlined";h.inheritAttrs=!1;const J=h;function U(e){const t={};for(const a in e)e.hasOwnProperty(a)&&(t[a]=String(e[a]));return t}const W={class:"container"},X=E({__name:"Sql",setup(e){const a=P().params.projectId,s=new R(j.string(),"lastQuery"),i=u(null),f=u(""),g=u([]),v=u([]),C=u([]),_=u(!1),I=async()=>{_.value=!0;const n=await F.executeQuery(a,f.value,[]);if(_.value=!1,s.set(f.value),!n)return;const{returns:r,errors:p}=n;C.value=p;for(const l of p)S.error({message:"SQL Execution Failed",description:l});p.length||S.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)=>U({key:`${y+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(k=>m[k])),y=`data-${new Date().toISOString()}`;$({fileName:y,columns:r,rows:p})};return B(()=>{const n=M.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(),Q("div",W,[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(J))]),default:d(()=>[x(" 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(()=>[x(" Export to CSV "),o(c(A))]),_:1})]),_:1},8,["disabled"])]),_:1}),o(c(z),{style:{width:"100%"},scroll:{x:100},"data-source":g.value,columns:v.value},null,8,["data-source","columns"])]))}});const ce=N(X,[["__scopeId","data-v-9a10cfc4"]]);export{ce as default};
//# sourceMappingURL=Sql.75276495.js.map
