import{b as s,e6 as q,d as E,e4 as R,L as B,B as _,f as p,J as D,K as L,w as g,u,aL as N,o as P,a as V,bM as x,az as S,da as h,cR as $,cF as O,Q as z}from"./index.6b1213c6.js";import{G as F}from"./PhDownloadSimple.vue.fcad7b67.js";import{e as M}from"./toggleHighContrast.5807794c.js";import"./gateway.d1bcadc7.js";import{a as A}from"./project.b277ffd0.js";import"./columns.5cccb454.js";import{_ as T}from"./TablesTabs.vue_vue_type_script_setup_true_lang.2cebd1ab.js";import"./popupNotifcation.97dc9547.js";import"./record.9f32285a.js";import"./string.8a712bbd.js";import"./TabPane.49a7fa43.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]="71bdc07a-3433-467a-bf3b-5a2fe4a380ad",t._sentryDebugIdIdentifier="sentry-dbid-71bdc07a-3433-467a-bf3b-5a2fe4a380ad")}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 G=J;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:G}),null)};w.displayName="CaretRightOutlined";w.inheritAttrs=!1;const U=w,W=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 Y=E({__name:"Sql",setup(t){const e=R().params.projectId,r=new B(_.array(_.object({projectId:_.string(),lastQuery:_.string()})),"lastQueries"),d=p(null),f=p(""),v=p([]),y=p([]),I=p([]),b=p(!1),Q=async()=>{b.value=!0;const l=await A.executeQuery(e,f.value,[]);b.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()}`;W({fileName:n,columns:o,rows:m})};return D(()=>{var m;const l=M.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)=>(P(),L(N,null,[s(T),s(u(h),{gap:"large",class:"sql-container",align:"center"},{default:g(()=>[V("div",{ref_key:"sqlEditor",ref:d,class:"sql-editor"},null,512),s(u(x),{type:"primary",loading:b.value,onClick:Q},{icon:g(()=>[s(u(U))]),default:g(()=>[S(" Run ")]),_:1},8,["loading"])]),_:1}),s(u(h),{justify:"end",style:{margin:"30px 0 10px 0"}},{default:g(()=>[s(u(x),{disabled:!v.value.length,onClick:j},{default:g(()=>[s(u(h),{align:"center",gap:"small"},{default:g(()=>[S(" Export to CSV "),s(u(F))]),_:1})]),_:1},8,["disabled"])]),_:1}),s(u($),{style:{width:"100%"},scroll:{x:100},"data-source":v.value,columns:y.value},null,8,["data-source","columns"])],64))}});const ie=z(Y,[["__scopeId","data-v-71ca01e9"]]);export{ie as default};
//# sourceMappingURL=Sql.0a322dc9.js.map
