const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./CodeField-1.0.74-CaC6WTx4.js","./RestApiError-1.0.74-Bb1un17k.js","./vendor-1.0.74-CN03Eozo.js","./tanstack-1.0.74-aU0azVkW.js","./redux-1.0.74-D8bIc6ki.js","./index-1.0.74-DxwH6OqZ.js","./CircularProgress-1.0.74-QfwfRJ7i.js","./lib-1.0.74-B5IEqfHg.js","./utils-1.0.74-7xWhx9mc.js","./ButtonBase-1.0.74-W6tAH7AI.js","./Typography-1.0.74-B4mhsevh.js","./useEnhancedEffect-1.0.74-B56M26dS.js","./ThemeProvider-1.0.74-4uzbYYLM.js","./Portal-1.0.74-BrUPeMX9.js","./iconBase-1.0.74-Cs0vntJu.js","./ConfirmDialog-1.0.74-CXu4CqK2.js","./AdminTheme-1.0.74-BtTaJUu_.js","./Modal-1.0.74-BfLid1bk.js","./Box-1.0.74-DEbuVvGV.js"])))=>i.map(i=>d[i]);
import{_ as S}from"./RestApiError-1.0.74-Bb1un17k.js";import{j as n}from"./tanstack-1.0.74-aU0azVkW.js";import{r as o}from"./redux-1.0.74-D8bIc6ki.js";import{r as l,l as N}from"./lib-1.0.74-B5IEqfHg.js";import{a as E}from"./hooks-1.0.74-NYCTWeI9.js";import{u as _,j as f,z as H,d as j,e as I}from"./StartQueryBuilder-1.0.74-WVV-m136.js";import{u as b,d as R}from"./QueryBuilder-1.0.74-DbuP4hMk.js";import{u as V}from"./QueryContainer-1.0.74-CoHKrQqX.js";import{e as d}from"./utils-1.0.74-7xWhx9mc.js";import{B}from"./Box-1.0.74-DEbuVvGV.js";import"./vendor-1.0.74-CN03Eozo.js";import"./index-1.0.74-FmkvObU2.js";import"./useViewHeight-1.0.74-CuK7XWCG.js";import"./AdminTheme-1.0.74-BtTaJUu_.js";import"./CircularProgress-1.0.74-QfwfRJ7i.js";import"./ActionsExplorer-1.0.74-BKccLQP2.js";import"./RestApi-1.0.74-5XKxNzpR.js";import"./DatabaseTypeEnum-1.0.74-DeJfpW1u.js";import"./Spinner-1.0.74-B63QTBL9.js";import"./Typography-1.0.74-B4mhsevh.js";import"./ThemeProvider-1.0.74-4uzbYYLM.js";import"./useEnhancedEffect-1.0.74-B56M26dS.js";import"./index-1.0.74-DxwH6OqZ.js";import"./ButtonBase-1.0.74-W6tAH7AI.js";import"./Portal-1.0.74-BrUPeMX9.js";import"./iconBase-1.0.74-Cs0vntJu.js";import"./ConfirmDialog-1.0.74-CXu4CqK2.js";import"./Modal-1.0.74-BfLid1bk.js";import"./index-1.0.74-CCIRxPEn.js";import"./index-1.0.74-DtMr5-xA.js";import"./index-1.0.74-C9JunOsO.js";import"./SanitizeComponent-1.0.74-DsOvasd7.js";import"./TextField-1.0.74-BW9Byijb.js";import"./Select-1.0.74-DHOnlEEH.js";import"./Menu-1.0.74-CdjCBJ4R.js";import"./isHostComponent-1.0.74-DVu5iVWx.js";import"./createSvgIcon-1.0.74-Cw_ZFbxi.js";import"./FormControlLabel-1.0.74-CdAG1Jo8.js";import"./Checkbox-1.0.74-DOdb-56q.js";import"./SwitchBase-1.0.74-pUYMwK3f.js";import"./Divider-1.0.74-BpwHmJ_P.js";import"./MenuItem-1.0.74-D9LDbFUb.js";import"./InputAdornment-1.0.74-DzikPcDx.js";import"./TabPanel-1.0.74-BfVdq8Gf.js";import"./useThemeProps-1.0.74-eOKEtzB-.js";import"./getThemeProps-1.0.74-DOfDN6_V.js";import"./TabList-1.0.74-Buya9FWs.js";import"./Tabs-1.0.74-BLkbuumd.js";import"./Switch-1.0.74-IHNqKL8Y.js";/* empty css                    */import"./FallbackSpinner-1.0.74-7h-h2HIM.js";import"./ClickAwayListener-1.0.74-B83n3LG4.js";import"./index-1.0.74-8lphm33F.js";import"./TableRow-1.0.74-CECYdZO6.js";import"./ToggleButtonGroup-1.0.74-DMigw7sg.js";import"./sortable.esm-1.0.74-BjjsGbF3.js";const w=o.lazy(()=>S(()=>import("./CodeField-1.0.74-CaC6WTx4.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]),import.meta.url)),ze=({queryKey:e,query:s,fullScreen:x,isReadOnly:Q,updateCode:a})=>{const p=E(),r=_(),g=V(),{getQueryKey:q}=b(),[h,c]=o.useState(l(s.query));o.useEffect(()=>{a&&c(l(a))},[a]);const u=o.useRef();u.current=h,o.useEffect(()=>{r.showSqlHints&&g(r.queries[e].schemaName)},[r.showSqlHints,r.queries[e].schemaName]),o.useEffect(()=>{r.copyQuery&&(c(r.copyQuery),p(f({queryKey:e,query:{access:s.access,queryName:s.queryName,query:r.copyQuery,schemaName:s.schemaName,isVisual:s.isVisual,isInserting:s.isInserting,params:s.params}})),p(H({copyQuery:void 0})))},[r.copyQuery]);const v=()=>{var m;if(u.current){const i=j.getSelectors().selectQueryBuilder(I.getState().sql);(m=i==null?void 0:i.queries)!=null&&m[e]&&R(i.queries[e].access,i.queries[e].schemaName,i.queries[e].queryName,l(u.current),i.queries[e].isVisual,i.queries[e].vqb??"","",i.queries[e].isInserting,i.queries[e].params,t=>{N.debug(t),(t==null?void 0:t.code)==="ok"&&(p(f({queryKey:e,query:{...i.queries[e],isInserting:void 0},isUpdated:!1})),d("Query succesfully saved",{variant:"success"}))},t=>{console.error(t),d(t,{variant:"error"})})}else d("Invalid code reference",{variant:"error"})};return n.jsx(B,{className:"pp-sql-query-builder-editor",children:n.jsx(o.Suspense,{children:n.jsx(w,{code:h,setCode:m=>{c(m),p(f({queryKey:e,query:{...s,query:m},isUpdated:!0}))},dialogTitle:q(e),extension:"sql",sqlSchema:r.showSqlHints?r.sqlSchemas[r.queries[e].schemaName]:void 0,initialHeight:x?"calc(((calc(var(--ppViewHeight, 1vh) * 100) - 69px - 48px - 69px - 48px - 5px) / 2) - 28px - 5px)":"270px",saveCode:v,isReadOnly:Q===!0})})})};export{ze as default};
