import { jsxs as h, jsx as r } from "react/jsx-runtime";
import { F as M } from "./index-DgLlxXt5.mjs";
import { useMemo as l, useCallback as u } from "react";
import { cF as k, cG as x, aE as E, cH as Q, S as p, aU as f, cw as q, cI as c, aR as d, B as T } from "./index-CUr2awEp.mjs";
import { f as j, g as A } from "./sqlRunnerSlice-D4ZpJ-1S.mjs";
import { g as b, r as w, a as y, M as z } from "./monaco-BNMCt5QW.mjs";
const F = {
  ...z,
  readOnly: !0
}, B = ({
  selectedView: n = "query"
}) => {
  const { colorScheme: v } = k(), { projectUuid: C } = x(), { data: i } = E(C), s = l(
    () => b(i?.warehouseConnection?.type),
    [i]
  ), { data: o, error: a, isInitialLoading: S } = Q(), L = u(
    (e) => {
      w(e, s), e.editor.defineTheme("lightdash-light", {
        base: "vs",
        inherit: !0,
        ...y("light")
      }), e.editor.defineTheme("lightdash-dark", {
        base: "vs-dark",
        inherit: !0,
        ...y("dark")
      });
    },
    [s]
  ), m = u(
    (e) => {
      if (!e) return "";
      try {
        return j(e, {
          language: A(i?.warehouseConnection?.type)
        });
      } catch (t) {
        return console.error(
          "Error rendering SQL:",
          t instanceof Error ? t.message : "Unknown error occurred"
        ), e;
      }
    },
    [i?.warehouseConnection?.type]
  ), g = l(
    () => n === "pivotQuery" && !o?.pivotQuery ? "query" : n,
    [n, o?.pivotQuery]
  ), O = l(() => {
    const e = g === "pivotQuery" ? o?.pivotQuery : o?.query;
    return m(e);
  }, [o?.query, o?.pivotQuery, g, m]);
  return S ? /* @__PURE__ */ h(p, { my: "xs", align: "center", children: [
    /* @__PURE__ */ r(f, { size: "lg", color: "gray", mt: "xs" }),
    /* @__PURE__ */ r(q, { order: 4, fw: 500, c: "ldGray.7", children: "Compiling SQL" })
  ] }) : a?.error.message ? /* @__PURE__ */ r("div", { style: { margin: 10 }, children: /* @__PURE__ */ r(
    c,
    {
      icon: /* @__PURE__ */ r(d, { size: "1rem" }),
      title: "Compilation error",
      color: "red",
      variant: "filled",
      children: /* @__PURE__ */ r("p", { children: a.error.message })
    }
  ) }) : a?.error.data ? /* @__PURE__ */ r("div", { style: { margin: 10 }, children: /* @__PURE__ */ r(
    c,
    {
      icon: /* @__PURE__ */ r(d, { size: "1rem" }),
      title: "Compilation error",
      color: "red",
      variant: "filled",
      children: Object.entries(a.error.data).map(
        ([e, t]) => /* @__PURE__ */ r("p", { children: JSON.stringify(t) }, e)
      )
    }
  ) }) : /* @__PURE__ */ h(p, { gap: 0, h: "100%", children: [
    o?.compilationErrors && o.compilationErrors.length > 0 && /* @__PURE__ */ r("div", { style: { margin: 10 }, children: /* @__PURE__ */ r(
      c,
      {
        icon: /* @__PURE__ */ r(d, { size: "1rem" }),
        title: "Compilation error",
        color: "red",
        variant: "filled",
        children: o.compilationErrors.map(
          (e, t) => /* @__PURE__ */ r("p", { children: e }, t)
        )
      }
    ) }),
    /* @__PURE__ */ r(T, { flex: 1, children: /* @__PURE__ */ r(
      M,
      {
        loading: /* @__PURE__ */ r(f, { color: "gray", size: "xs" }),
        language: s,
        beforeMount: L,
        value: O,
        options: F,
        theme: v === "dark" ? "lightdash-dark" : "lightdash-light"
      }
    ) })
  ] });
};
export {
  B as RenderedSql
};
//# sourceMappingURL=RenderedSql-b-_P4eVj.mjs.map
