import{b as s,ee as q,d as E,ea as N,N as R,O as _,e as p,X as D,o as B,Y as P,w as g,u,aS as V,a as $,bT as x,aG as S,dh as b,cY as L,cM as O,a0 as M}from"./index.b466b20d.js";import{G as z}from"./PhDownloadSimple.vue.a3448aec.js";import{e as A}from"./toggleHighContrast.ed9cac97.js";import"./gateway.973a0055.js";import{a as F}from"./project.eb1f21da.js";import"./tables.1fa225bd.js";import{_ as T}from"./TablesTabs.vue_vue_type_script_setup_true_lang.61f8e193.js";import"./popupNotifcation.d1201e83.js";import"./record.fd6fbc29.js";import"./string.42378387.js";import"./TabPane.83921cd6.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]="d096e364-491d-420a-a0f6-4c9bc2cc7701",t._sentryDebugIdIdentifier="sentry-dbid-d096e364-491d-420a-a0f6-4c9bc2cc7701")}catch{}})();var G={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 Y=G;function C(t){for(var a=1;a<arguments.length;a++){var e=arguments[a]!=null?Object(arguments[a]):{},r=Object.keys(e);typeof Object.getOwnPropertySymbols=="function"&&(r=r.concat(Object.getOwnPropertySymbols(e).filter(function(d){return Object.getOwnPropertyDescriptor(e,d).enumerable}))),r.forEach(function(d){H(t,d,e[d])})}return t}function H(t,a,e){return a in t?Object.defineProperty(t,a,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[a]=e,t}var w=function(a,e){var r=C({},a,e.attrs);return s(q,C({},r,{icon:Y}),null)};w.displayName="CaretRightOutlined";w.inheritAttrs=!1;const J=w,U=t=>{let a=t.columns.join(",")+`
`;t.rows.forEach(r=>{a+=r.join(","),a+=`
`});const e=document.createElement("a");e.href="data:text/csv;charset=utf-8,"+encodeURIComponent(a),e.target="_blank",e.download=`${t.fileName}.csv`,e.click()};function X(t){const a={};for(const e in t)if(t.hasOwnProperty(e)){if(typeof t[e]=="object"&&t[e]!==null){a[e]=JSON.stringify(t[e]);continue}a[e]=String(t[e])}return a}const W=E({__name:"Sql",setup(t){const e=N().params.projectId,r=new R(_.array(_.object({projectId:_.string(),lastQuery:_.string()})),"lastQueries"),d=p(null),f=p(""),v=p([]),y=p([]),I=p([]),h=p(!1),Q=async()=>{h.value=!0;const l=await F.executeQuery(e,f.value,[]);h.value=!1;const o=r.get();if(!o)r.set([{projectId:e,lastQuery:f.value}]);else{const n=o.findIndex(c=>c.projectId===e);n===-1?o.push({projectId:e,lastQuery:f.value}):o[n].lastQuery=f.value,r.set(o)}if(!l)return;const{returns:m,errors:i}=l;I.value=i;for(const n of i)O.error({message:"SQL Execution Failed",description:n});i.length||O.success({message:"SQL Execution Succeeded"}),y.value=m.fields.map(n=>({title:n.name,key:n.name,dataIndex:n.name})),v.value=m.result.map((n,c)=>X({key:`${c+1}`,...n}))},j=()=>{const l=y.value.map(c=>c.dataIndex),o=y.value.map(c=>c.title),m=v.value.map(c=>l.map(k=>c[k])),n=`data-${new Date().toISOString()}`;U({fileName:n,columns:o,rows:m})};return D(()=>{var m;const l=A.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 o=r.get();if(o){const i=(m=o.find(n=>n.projectId===e))==null?void 0:m.lastQuery;i&&(f.value=i,l.setValue(i))}}),(l,o)=>(B(),P(V,null,[s(T),s(u(b),{gap:"large",class:"sql-container",align:"center"},{default:g(()=>[$("div",{ref_key:"sqlEditor",ref:d,class:"sql-editor"},null,512),s(u(x),{type:"primary",loading:h.value,onClick:Q},{icon:g(()=>[s(u(J))]),default:g(()=>[S(" Run ")]),_:1},8,["loading"])]),_:1}),s(u(b),{justify:"end",style:{margin:"30px 0 10px 0"}},{default:g(()=>[s(u(x),{disabled:!v.value.length,onClick:j},{default:g(()=>[s(u(b),{align:"center",gap:"small"},{default:g(()=>[S(" Export to CSV "),s(u(z))]),_:1})]),_:1},8,["disabled"])]),_:1}),s(u(L),{style:{width:"100%"},scroll:{x:100},"data-source":v.value,columns:y.value},null,8,["data-source","columns"])],64))}});const ie=M(W,[["__scopeId","data-v-71ca01e9"]]);export{ie as default};
//# sourceMappingURL=Sql.80027922.js.map
