const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./QueryResultTable-1.0.63-B-YDAtM_.js","./cm-1.0.63-CSIRHMXC.js","./redux-1.0.63-Df-eBzJn.js","./vendor-1.0.63-CN03Eozo.js","./Spinner-1.0.63-zcgIyS7Z.js","./lib-1.0.63-DJZPtMem.js","./loglevel-1.0.63-BZ7XahX3.js","./lodash-1.0.63-hMxolcpJ.js","./moment-1.0.63-C5S46NFB.js","./Typography-1.0.63-mecuj_Wl.js","./QueryResultsResponse-1.0.63-qvbLLv55.js","./jsonview-1.0.63-DQEcqiMn.js","./QueryResultsResponse-1.0.63-DeIZ423H.css"])))=>i.map(i=>d[i]);
import{_ as D}from"./cmJson-1.0.63-CyZ2MfFg.js";import{j as t}from"./cm-1.0.63-CSIRHMXC.js";import{r as h}from"./redux-1.0.63-Df-eBzJn.js";import{n as z,o as M,p as P}from"./index-1.0.63-BbQj9wqD.js";import{j as Q,G as V,B as H,L as J}from"./jstoxml-1.0.63-Cid7y3kP.js";import{c7 as X}from"./lib-1.0.63-DJZPtMem.js";import{F as B}from"./FileSaver.min-1.0.63-DJRT4Qoi.js";import{e as f,p as $,q as W,F as G,E as K,B as N}from"./index-1.0.63-oIDff4nA.js";import{u as U}from"./QueryBuilder-1.0.63-DtyYMIMt.js";import{P as Y}from"./index-1.0.63-DEVN4tRF.js";import{C as Z}from"./index-1.0.63-MKbdS7Mb.js";import{e as u}from"./notistack-1.0.63-B49ULGrj.js";import{a as y}from"./hooks-1.0.63-CWs3kTdT.js";import{m as R}from"./StartQueryBuilder-1.0.63-REjvqyiC.js";import{T as q,a as I}from"./TabPanel-1.0.63-CSMGfwNU.js";import{B as e}from"./Spinner-1.0.63-zcgIyS7Z.js";import{I as c}from"./iconBase-1.0.63-CFvHhC4t.js";import{T as tt}from"./TabList-1.0.63-z7zNziDb.js";import{T as E}from"./Tabs-1.0.63-6c0rSlLk.js";import{P as O}from"./ButtonBase-1.0.63-CF10PFMS.js";import"./vendor-1.0.63-CN03Eozo.js";import"./rehyperaw-1.0.63-AkovKNCK.js";import"./markdown-1.0.63-BJvkzZkj.js";import"./jstoxml-1.0.63-DkGlThlH.js";import"./loglevel-1.0.63-BZ7XahX3.js";import"./lodash-1.0.63-hMxolcpJ.js";import"./moment-1.0.63-C5S46NFB.js";import"./Typography-1.0.63-mecuj_Wl.js";import"./ThemeProvider-1.0.63-Cq0KMgkh.js";import"./useEnhancedEffect-1.0.63-DnR0ZFqV.js";import"./Modal-1.0.63-fMXTbfks.js";import"./ConfirmDialog-1.0.63-eXgm3P8b.js";import"./cjs-1.0.63-4A2xol4v.js";import"./AdminTheme-1.0.63-DhJ0rrw5.js";import"./DialogContent-1.0.63-B3W-DlSe.js";import"./MainQueryBuilder-1.0.63-B0m2zVpP.js";import"./ActionsExplorer-1.0.63-DQojhfpy.js";import"./RestApi-1.0.63-BUfzocgq.js";import"./DatabaseTypeEnum-1.0.63-DeJfpW1u.js";import"./SanitizeComponent-1.0.63-CtRxRbku.js";import"./dompurify-1.0.63-DhD2mIk-.js";import"./TextField-1.0.63-C35Mfi1Q.js";import"./Select-1.0.63-BMejr8a7.js";import"./Menu-1.0.63-DLh4HkF0.js";import"./createSvgIcon-1.0.63-DWL3J-DK.js";import"./FormControlLabel-1.0.63-DpYUdUm6.js";import"./Checkbox-1.0.63-DPBXeOde.js";import"./SwitchBase-1.0.63-Br-lbcZ1.js";import"./Divider-1.0.63-dQ0q4iIX.js";import"./MenuItem-1.0.63-Bvb3IjMP.js";import"./InputAdornment-1.0.63-q8tTbJxw.js";import"./getThemeProps-1.0.63-5ZzcWe3G.js";import"./Switch-1.0.63-m0NqOO9s.js";/* empty css                    */import"./ctc-1.0.63-C3KWqNfd.js";import"./useViewHeight-1.0.63-C7T4FLFa.js";const it=(j,r)=>{const i=()=>{var a;if(Array.isArray((a=r==null?void 0:r.status)==null?void 0:a.last_result)&&r.status.last_result.length>0){const x=V({filename:j,fieldSeparator:",",decimalSeparator:".",useKeysAsHeaders:!0}),o=H(x)(m());J(x)(o)}},w=()=>{var a;Array.isArray((a=r==null?void 0:r.status)==null?void 0:a.last_result)&&r.status.last_result.length>0&&B(new Blob([JSON.stringify(m())],{type:"text/json;charset=utf-8"}),`${j}.json`)},p=()=>{var a;if(Array.isArray((a=r==null?void 0:r.status)==null?void 0:a.last_result)&&r.status.last_result.length>0){const x=r.status.last_result.map(n=>{const s={};return Object.keys(n).map(l=>{s[l]=n[l]}),{row:s}}),o=Q.toXML({table:x});B(new Blob([o],{type:"text/plain;charset=utf-8"}),`${j}.xml`)}},m=()=>{const a=[];return Array.isArray(r==null?void 0:r.columns)&&r.columns.map(o=>{if(o.Field&&o.Type){const n=o.Type.indexOf("(")>0?o.Type.substring(0,o.Type.indexOf("(")).toLowerCase():o.Type;X(n)==="number"&&a.push(o.Field)}}),r.status.last_result.map(o=>{const n={};return Object.keys(o).map(s=>{a.includes(s)?n[s]=Number(o[s]):n[s]=o[s]}),n})};return{downloadCsv:i,downloadJson:w,downloadXml:p}},rt=h.lazy(()=>D(()=>import("./QueryResultTable-1.0.63-B-YDAtM_.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]),import.meta.url)),ot=h.lazy(()=>D(()=>import("./QueryResultsResponse-1.0.63-qvbLLv55.js"),__vite__mapDeps([10,1,2,3,11,12]),import.meta.url)),ni=({queries:j,queryKey:r,queryResults:i,tabs:w,index:p,setIndex:m})=>{const a=y(),{getQueryKey:x}=U(),{downloadCsv:o,downloadJson:n,downloadXml:s}=it(x(r),i),[l,F]=h.useState("table"),[d,g]=h.useState(!1),L=()=>{var b,C,_,T,k,S,A;return((b=i==null?void 0:i.status)==null?void 0:b.last_error)!==""?t.jsxs(e,{sx:{display:"grid",gridTemplateColumns:"1fr auto",justifyContent:"space-between",alignItems:"center",gap:"5px"},children:[t.jsxs(e,{sx:{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"},children:["ERROR: ",i.status.last_error]}),t.jsxs(e,{children:[t.jsx(Z,{text:i.status.last_error,onCopy:()=>{u("Error successfully copied to clipboard",{variant:"info"})},children:t.jsx(f,{title:"Copy to clipboard",children:t.jsx(c,{size:"small",children:t.jsx(N,{})})})}),t.jsx(f,{title:"Ask AI Assistant for help",children:t.jsx(c,{size:"small",onClick:()=>{a(R({prompt:`This SQL query:

${j[r].query}

Returns the following error:

${i.status.last_error}

Can you help?`,queryKey:r}))},children:t.jsx(Y,{})})})]})]}):i!=null&&i.cmd.trim().startsWith("select")?((_=i==null?void 0:i.status)==null?void 0:_.num_rows)+(((T=i==null?void 0:i.status)==null?void 0:T.num_rows)===1?" row":" rows")+(((k=i==null?void 0:i.status)==null?void 0:k.queries)===null?"":" ("+((A=i==null?void 0:i.status)==null?void 0:A.queries[((S=i==null?void 0:i.status)==null?void 0:S.num_queries)-1][1].toFixed(5))+" sec)"):((C=i==null?void 0:i.status)==null?void 0:C.rows_affected)+" rows affected"},v=b=>t.jsxs(e,{sx:{display:"flex",flexDirection:"row",justifyContent:"center",alignItems:"center",fontSize:"11px",position:"absolute",top:b,left:0,right:0},children:[t.jsx(c,{size:"small",color:"primary",disableRipple:!0,onClick:()=>{g(!d)},children:t.jsx(K,{})}),t.jsx(e,{sx:{display:"inline-block",cursor:"pointer"},onClick:()=>{g(!d)},children:l==="table"?"full-screen query result":"full-screen server response"})]});return Object.keys(i).length===0?null:t.jsxs(q,{value:l,children:[t.jsxs(e,{sx:{marginBottom:"2px",display:"grid",gridTemplateColumns:"auto 1fr 1fr 1fr",justifyContent:"space-between",alignItems:"center"},children:[w!==void 0?t.jsxs(e,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"5px"},children:[t.jsx(f,{title:"Previous query",children:t.jsx(c,{disabled:p===0,onClick:()=>{p!==void 0&&m!==void 0&&m(p-1)},children:t.jsx($,{})})}),t.jsx(e,{children:(p??0)+1}),t.jsx(f,{title:"Next query",children:t.jsx(c,{disabled:w-1===p,onClick:()=>{p!==void 0&&m!==void 0&&m(p+1)},children:t.jsx(W,{})})})]}):t.jsx(e,{}),t.jsxs(tt,{onChange:(b,C)=>{g(!1),F(C)},children:[t.jsx(E,{label:"Query Result",value:"table"}),t.jsx(E,{label:"Server Response",value:"response"})]}),t.jsxs(e,{sx:{display:"flex",flexDirection:"row",justifyContent:"center",alignItems:"center",fontSize:"11px"},children:[t.jsx(c,{size:"small",color:"primary",disableRipple:!0,onClick:()=>{g(!d)},children:t.jsx(G,{})}),t.jsx(e,{sx:{display:"inline-block",cursor:"pointer"},onClick:()=>{g(!d)},children:l==="table"?"full-screen query result":"full-screen server response"})]}),t.jsxs(e,{sx:{display:"flex",flexDirection:"row",justifyContent:"end",alignItems:"center"},children:[t.jsx(f,{title:"Export to CSV",children:t.jsx(c,{onClick:()=>{o()},children:t.jsx(z,{})})}),t.jsx(f,{title:"Export to JSON",children:t.jsx(c,{onClick:()=>{n()},children:t.jsx(M,{})})}),t.jsx(f,{title:"Export to XML",children:t.jsx(c,{onClick:()=>{s()},children:t.jsx(P,{})})})]})]}),t.jsxs(e,{className:"pp-sql-query-builder-results",children:[t.jsx(I,{value:"table",keepMounted:!0,sx:{padding:0},children:t.jsxs(O,{sx:{marginTop:"5px",padding:0,backgroundColor:"#ddd",display:"grid",gridTemplateRows:"1fr auto",borderRadius:"4px",...l==="table"&&d&&{width:"calc(100vw - 100px) !important",height:"calc(calc(var(--ppViewHeight, 1vh) * 100) - 100px) !important",position:"fixed",top:0,left:0,zIndex:9999999,margin:0,padding:"50px !important","& table.pp-sql-query-builder-table tbody":{height:"calc(calc(var(--ppViewHeight, 1vh) * 100) - 160px) !important"}}},children:[d&&v("10px"),t.jsx(h.Suspense,{children:t.jsx(rt,{queryResults:i})}),t.jsx(e,{sx:{display:"flex",flexDirection:"row",alignItems:"center",height:"30px",paddingLeft:"5px",paddingRight:"5px",backgroundColor:"#eee",borderBottomLeftRadius:"4px",borderBottomRightRadius:"4px"},children:L()})]})}),t.jsx(I,{value:"response",keepMounted:!0,sx:{padding:0},children:t.jsxs(O,{className:"pp-sql-query-builder-response-paper",sx:{marginTop:"5px",padding:"30px",height:"240px",...l==="response"&&d&&{width:"calc(100vw - 100px) !important",height:"calc(calc(var(--ppViewHeight, 1vh) * 100) - 100px) !important",position:"fixed",top:0,left:0,zIndex:9999999,margin:0,padding:"50px !important",backgroundColor:"#ddd"}},children:[d&&v("10px"),t.jsx(e,{sx:{height:"240px",overflow:"auto","& code":{padding:0,margin:0,backgroundColor:"transparent"},...l==="response"&&d&&{height:"calc(calc(var(--ppViewHeight, 1vh) * 100) - 145px) !important",backgroundColor:"#fff",padding:"20px !important",borderRadius:"4px"}},className:"pp-sql-query-builder-response",children:t.jsx(h.Suspense,{children:t.jsx(ot,{queryResults:i})})})]})})]})]})};export{ni as default};
