import{f as o,e7 as q,d as E,eb as D,O as L,L as _,r as p,k as N,a5 as $,b as g,u,aR as B,o as P,e as V,bR as x,g as S,de as b,cX as z,cL as O,_ as A}from"./jwt-decode.esm.95147216.js";import{G as F}from"./PhDownloadSimple.vue.394e595e.js";import{e as M}from"./toggleHighContrast.a1733007.js";import"./router.09c25b35.js";import{a as T}from"./project.47c68ce9.js";import"./tables.7fcaf771.js";import{_ as G}from"./TablesTabs.vue_vue_type_script_setup_true_lang.43b35389.js";import"./index.574c12ce.js";import"./record.44df96f2.js";import"./string.c6b418fe.js";import"./Card.6c9b2903.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]="6ee31f49-fa7a-425e-9a33-10809e8cdd4d",e._sentryDebugIdIdentifier="sentry-dbid-6ee31f49-fa7a-425e-9a33-10809e8cdd4d")}catch{}})();var H={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 J=H;function C(e){for(var a=1;a<arguments.length;a++){var t=arguments[a]!=null?Object(arguments[a]):{},r=Object.keys(t);typeof Object.getOwnPropertySymbols=="function"&&(r=r.concat(Object.getOwnPropertySymbols(t).filter(function(d){return Object.getOwnPropertyDescriptor(t,d).enumerable}))),r.forEach(function(d){U(e,d,t[d])})}return e}function U(e,a,t){return a in e?Object.defineProperty(e,a,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[a]=t,e}var w=function(a,t){var r=C({},a,t.attrs);return o(q,C({},r,{icon:J}),null)};w.displayName="CaretRightOutlined";w.inheritAttrs=!1;const X=w,I=e=>{if(e==null)return"";const a=String(e);return a.includes(";")||a.includes(`
`)||a.includes('"')?`"${a.replace(/"/g,'""')}"`:a},W=e=>{let a=e.columns.map(I).join(";")+`
`;e.rows.forEach(r=>{a+=r.map(I).join(";")+`
`});const t=document.createElement("a");t.href="data:text/csv;charset=utf-8,"+encodeURIComponent(a),t.target="_blank",t.download=`${e.fileName}.csv`,t.click()};function Y(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 Z=E({__name:"Sql",setup(e){const t=D().params.projectId,r=new L(_.array(_.object({projectId:_.string(),lastQuery:_.string()})),"lastQueries"),d=p(null),f=p(""),v=p([]),y=p([]),Q=p([]),h=p(!1),j=async()=>{h.value=!0;const l=await T.executeQuery(t,f.value,[]);h.value=!1;const s=r.get();if(!s)r.set([{projectId:t,lastQuery:f.value}]);else{const n=s.findIndex(i=>i.projectId===t);n===-1?s.push({projectId:t,lastQuery:f.value}):s[n].lastQuery=f.value,r.set(s)}if(!l)return;const{returns:m,errors:c}=l;Q.value=c;for(const n of c)O.error({message:"SQL Execution Failed",description:n});c.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,i)=>Y({key:`${i+1}`,...n}))},k=()=>{const l=y.value.map(i=>i.dataIndex),s=y.value.map(i=>i.title),m=v.value.map(i=>l.map(R=>i[R])),n=`data-${new Date().toISOString()}`;W({fileName:n,columns:s,rows:m})};return N(()=>{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 s=r.get();if(s){const c=(m=s.find(n=>n.projectId===t))==null?void 0:m.lastQuery;c&&(f.value=c,l.setValue(c))}}),(l,s)=>(P(),$(B,null,[o(G),o(u(b),{gap:"large",class:"sql-container",align:"center"},{default:g(()=>[V("div",{ref_key:"sqlEditor",ref:d,class:"sql-editor"},null,512),o(u(x),{type:"primary",loading:h.value,onClick:j},{icon:g(()=>[o(u(X))]),default:g(()=>[S(" Run ")]),_:1},8,["loading"])]),_:1}),o(u(b),{justify:"end",style:{margin:"30px 0 10px 0"}},{default:g(()=>[o(u(x),{disabled:!v.value.length,onClick:k},{default:g(()=>[o(u(b),{align:"center",gap:"small"},{default:g(()=>[S(" Export to CSV "),o(u(F))]),_:1})]),_:1},8,["disabled"])]),_:1}),o(u(z),{style:{width:"100%"},scroll:{x:100},"data-source":v.value,columns:y.value},null,8,["data-source","columns"])],64))}});const ue=A(Z,[["__scopeId","data-v-71ca01e9"]]);export{ue as default};
//# sourceMappingURL=Sql.a15fc5f5.js.map
