"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),e=require("./index-BmF6F_Ux.js"),n=require("react"),g=require("./sqlRunnerSlice-Dab1Ma3p.js"),y={...e.MONACO_DEFAULT_OPTIONS,readOnly:!0},f=({selectedView:l="query"})=>{const{colorScheme:h}=e.useMantineColorScheme(),{projectUuid:m}=e.useParams(),{data:s}=e.useProject(m),c=n.useMemo(()=>e.getMonacoLanguage(s?.warehouseConnection?.type),[s]),{data:o,error:a,isInitialLoading:p}=e.useCompiledSql(),x=n.useCallback(t=>{e.registerMonacoLanguage(t,c),t.editor.defineTheme("lightdash-light",{base:"vs",inherit:!0,...e.getLightdashMonacoTheme("light")}),t.editor.defineTheme("lightdash-dark",{base:"vs-dark",inherit:!0,...e.getLightdashMonacoTheme("dark")})},[c]),d=n.useCallback(t=>{if(!t)return"";try{return g.format(t,{language:g.getLanguage(s?.warehouseConnection?.type)})}catch(i){return console.error("Error rendering SQL:",i instanceof Error?i.message:"Unknown error occurred"),t}},[s?.warehouseConnection?.type]),u=n.useMemo(()=>l==="pivotQuery"&&!o?.pivotQuery?"query":l,[l,o?.pivotQuery]),j=n.useMemo(()=>{const t=u==="pivotQuery"?o?.pivotQuery:o?.query;return d(t)},[o?.query,o?.pivotQuery,u,d]);return p?r.jsxs(e.Stack,{my:"xs",align:"center",children:[r.jsx(e.Loader,{size:"lg",color:"gray",mt:"xs"}),r.jsx(e.Title,{order:4,fw:500,c:"ldGray.7",children:"Compiling SQL"})]}):a?.error.message?r.jsx("div",{style:{margin:10},children:r.jsx(e.Alert,{icon:r.jsx(e.IconAlertCircle,{size:"1rem"}),title:"Compilation error",color:"red",variant:"filled",children:r.jsx("p",{children:a.error.message})})}):a?.error.data?r.jsx("div",{style:{margin:10},children:r.jsx(e.Alert,{icon:r.jsx(e.IconAlertCircle,{size:"1rem"}),title:"Compilation error",color:"red",variant:"filled",children:Object.entries(a.error.data).map(([t,i])=>r.jsx("p",{children:JSON.stringify(i)},t))})}):r.jsxs(e.Stack,{gap:0,h:"100%",children:[o?.compilationErrors&&o.compilationErrors.length>0&&r.jsx("div",{style:{margin:10},children:r.jsx(e.Alert,{icon:r.jsx(e.IconAlertCircle,{size:"1rem"}),title:"Compilation error",color:"red",variant:"filled",children:o.compilationErrors.map((t,i)=>r.jsx("p",{children:t},i))})}),r.jsx(e.Box,{flex:1,children:r.jsx(e.Ft,{loading:r.jsx(e.Loader,{color:"gray",size:"xs"}),language:c,beforeMount:x,value:j,options:y,theme:h==="dark"?"lightdash-dark":"lightdash-light"})})]})};exports.RenderedSql=f;
//# sourceMappingURL=RenderedSql-DHEy1nPZ.js.map
