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