import{f as c,e7 as L,d as D,eb as N,O as $,L as _,r as f,em as B,J as P,a5 as V,b as m,u as i,aR as z,o as A,e as F,bR as S,g as O,de as b,cX as M,cL as C,_ as T}from"./jwt-decode.esm.7fb8faf4.js";import{G as J}from"./PhDownloadSimple.vue.4c39fa52.js";import{e as G}from"./toggleHighContrast.15446005.js";import"./router.643f183e.js";import{a as H}from"./project.47800fcd.js";import"./tables.736ccb3d.js";import{_ as U}from"./TablesTabs.vue_vue_type_script_setup_true_lang.1a057f69.js";import"./index.d928bc3c.js";import"./record.5fbe6782.js";import"./string.d8337a2b.js";import"./Card.897ad69d.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]="1dcd58ec-fa57-4a9d-8280-8f17a822ffec",e._sentryDebugIdIdentifier="sentry-dbid-1dcd58ec-fa57-4a9d-8280-8f17a822ffec")}catch{}})();var X={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 W=X;function I(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(u){return Object.getOwnPropertyDescriptor(t,u).enumerable}))),r.forEach(function(u){Y(e,u,t[u])})}return e}function Y(e,a,t){return a in e?Object.defineProperty(e,a,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[a]=t,e}var x=function(a,t){var r=I({},a,t.attrs);return c(L,I({},r,{icon:W}),null)};x.displayName="CaretRightOutlined";x.inheritAttrs=!1;const Z=x,Q=e=>{if(e==null)return"";const a=String(e);return a.includes(";")||a.includes(`
`)||a.includes('"')?`"${a.replace(/"/g,'""')}"`:a},K=e=>{let a=e.columns.map(Q).join(";")+`
`;e.rows.forEach(r=>{a+=r.map(Q).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 ee(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 te=D({__name:"Sql",setup(e){const t=N().params.projectId,r=new $(_.array(_.object({projectId:_.string(),lastQuery:_.string()})),"lastQueries"),u=f(null),d=f(""),v=f([]),y=f([]),j=f([]),h=f(!1),w=()=>{const n=r.get();if(!n)r.set([{projectId:t,lastQuery:d.value}]);else{const o=n.findIndex(l=>l.projectId===t);o===-1?n.push({projectId:t,lastQuery:d.value}):n[o].lastQuery=d.value,r.set(n)}},R=async()=>{h.value=!0;const n=await H.executeQuery(t,d.value,[]);if(w(),h.value=!1,!n)return;const{returns:o,errors:l}=n;j.value=l;for(const s of l)C.error({message:"SQL Execution Failed",description:s});l.length||C.success({message:"SQL Execution Succeeded"}),y.value=o.fields.map(s=>({title:s.name,key:s.name,dataIndex:s.name})),v.value=o.result.map((s,p)=>ee({key:`${p+1}`,...s}))},k=()=>{const n=y.value.map(g=>g.dataIndex),o=y.value.map(g=>g.title),l=v.value.map(g=>n.map(E=>g[E])),p=`data-${new Date().toISOString()}`;K({fileName:p,columns:o,rows:l})},q=B.exports.debounce(w,1e3);return P(()=>{var l;const n=G.create(u.value,{language:"sql",value:d.value,fontFamily:"monospace",lineNumbers:"on",minimap:{enabled:!1},scrollbar:{vertical:"hidden",horizontal:"visible"},fontSize:14,scrollBeyondLastLine:!1,lineHeight:20});n.onDidChangeModelContent(()=>{d.value=n.getValue(),q()});const o=r.get();if(o){const s=(l=o.find(p=>p.projectId===t))==null?void 0:l.lastQuery;s&&(d.value=s,n.setValue(s))}}),(n,o)=>(A(),V(z,null,[c(U),c(i(b),{gap:"large",class:"sql-container",align:"center"},{default:m(()=>[F("div",{ref_key:"sqlEditor",ref:u,class:"sql-editor"},null,512),c(i(S),{type:"primary",loading:h.value,onClick:R},{icon:m(()=>[c(i(Z))]),default:m(()=>[O(" Run ")]),_:1},8,["loading"])]),_:1}),c(i(b),{justify:"end",style:{margin:"30px 0 10px 0"}},{default:m(()=>[c(i(S),{disabled:!v.value.length,onClick:k},{default:m(()=>[c(i(b),{align:"center",gap:"small"},{default:m(()=>[O(" Export to CSV "),c(i(J))]),_:1})]),_:1},8,["disabled"])]),_:1}),c(i(M),{style:{width:"100%"},scroll:{x:100},"data-source":v.value,columns:y.value},null,8,["data-source","columns"])],64))}});const me=T(te,[["__scopeId","data-v-3629dc62"]]);export{me as default};
//# sourceMappingURL=Sql.afd70c7f.js.map
