import{g as o,I as E,d as D,S as N,L as P,z as _,r as p,X as $,l as B,m as L,G as g,q as R,D as u,H as x,$ as S,M as h,a_ as V,F,aZ as I,ap as M}from"./jwt-decode.esm-Dca5fHH5.js";import{G as z}from"./PhDownloadSimple.vue-WTX49Oyt.js";import{e as A}from"./editor.main-Bc1xRROv.js";import"./router-D5wfdag3.js";import{P as T}from"./project-BZzoNeQM.js";import"./tables-BsqTY_wE.js";import{_ as G}from"./TablesTabs.vue_vue_type_script_setup_true_lang-BOH5jv3X.js";import"./index-Cyx2lZTa.js";import"./record-BZIfMWML.js";import"./string-BYR4BIXr.js";import"./index-mvr8okoq.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]="f54cc116-3e7c-4c96-ba85-8b28d2263225",e._sentryDebugIdIdentifier="sentry-dbid-f54cc116-3e7c-4c96-ba85-8b28d2263225")}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"};function O(e){for(var a=1;a<arguments.length;a++){var t=arguments[a]!=null?Object(arguments[a]):{},n=Object.keys(t);typeof Object.getOwnPropertySymbols=="function"&&(n=n.concat(Object.getOwnPropertySymbols(t).filter(function(d){return Object.getOwnPropertyDescriptor(t,d).enumerable}))),n.forEach(function(d){J(e,d,t[d])})}return e}function J(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 n=O({},a,t.attrs);return o(E,O({},n,{icon:H}),null)};w.displayName="CaretRightOutlined";w.inheritAttrs=!1;const C=e=>{if(e==null)return"";const a=String(e);return a.includes(";")||a.includes(`
`)||a.includes('"')?`"${a.replace(/"/g,'""')}"`:a},U=e=>{let a=e.columns.map(C).join(";")+`
`;e.rows.forEach(n=>{a+=n.map(C).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 X(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=D({__name:"Sql",setup(e){const t=N().params.projectId,n=new P(_.array(_.object({projectId:_.string(),lastQuery:_.string()})),"lastQueries"),d=p(null),f=p(""),v=p([]),y=p([]),Q=p([]),b=p(!1),j=async()=>{b.value=!0;const l=await T.executeQuery(t,f.value,[]);b.value=!1;const s=n.get();if(!s)n.set([{projectId:t,lastQuery:f.value}]);else{const r=s.findIndex(c=>c.projectId===t);r===-1?s.push({projectId:t,lastQuery:f.value}):s[r].lastQuery=f.value,n.set(s)}if(!l)return;const{returns:i,errors:m}=l;Q.value=m;for(const r of m)I.error({message:"SQL Execution Failed",description:r});m.length||I.success({message:"SQL Execution Succeeded"}),y.value=i.fields.map(r=>({title:r.name,key:r.name,dataIndex:r.name})),v.value=i.result.map((r,c)=>X({key:`${c+1}`,...r}))},k=()=>{const l=y.value.map(c=>c.dataIndex),s=y.value.map(c=>c.title),i=v.value.map(c=>l.map(q=>c[q])),r=`data-${new Date().toISOString()}`;U({fileName:r,columns:s,rows:i})};return $(()=>{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 s=n.get();if(s){const i=s.find(m=>m.projectId===t)?.lastQuery;i&&(f.value=i,l.setValue(i))}}),(l,s)=>(L(),B(F,null,[o(G),o(u(h),{gap:"large",class:"sql-container",align:"center"},{default:g(()=>[R("div",{ref_key:"sqlEditor",ref:d,class:"sql-editor"},null,512),o(u(x),{type:"primary",loading:b.value,onClick:j},{icon:g(()=>[o(u(w))]),default:g(()=>[S(" Run ")]),_:1},8,["loading"])]),_:1}),o(u(h),{justify:"end",style:{margin:"30px 0 10px 0"}},{default:g(()=>[o(u(x),{disabled:!v.value.length,onClick:k},{default:g(()=>[o(u(h),{align:"center",gap:"small"},{default:g(()=>[S(" Export to CSV "),o(u(z))]),_:1})]),_:1},8,["disabled"])]),_:1}),o(u(V),{style:{width:"100%"},scroll:{x:100},"data-source":v.value,columns:y.value},null,8,["data-source","columns"])],64))}}),ce=M(Z,[["__scopeId","data-v-71ca01e9"]]);export{ce as default};
//# sourceMappingURL=Sql-D2C39Y7D.js.map
