/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import d from "@arcgis/core/request.js";
import "monaco-editor";
import { StandaloneServices as w } from "monaco-editor/esm/vs/editor/standalone/browser/standaloneServices.js";
import "monaco-editor/esm/vs/editor/standalone/common/standaloneTheme.js";
import { IHoverService as y } from "monaco-editor/esm/vs/platform/hover/browser/hover.js";
import "monaco-editor/esm/vs/editor/common/languages/supports/tokenization.js";
import "monaco-editor/esm/vs/base/browser/dom.js";
import "monaco-editor/esm/vs/editor/browser/editorDom.js";
import "monaco-editor/esm/vs/editor/browser/controller/mouseTarget.js";
function g() {
  return !!window.MonacoEnvironment?.getWorker;
}
let n = "";
const m = /* @__PURE__ */ new Map(), i = !1;
async function l(s, e, r) {
  if (r)
    return e ? e() : new Worker(s);
  const t = window.location.origin;
  if (new URL(s, window.location.href).origin !== t) {
    const o = await d(s, { responseType: "text" });
    return new Worker(URL.createObjectURL(new Blob([o.data], { type: "text/javascript" })), {
      type: "module"
    });
  }
  return new Worker(s, {
    type: "module"
  });
}
function U(s) {
  if (g())
    return;
  q(), n = s;
  const e = `${n}/code-editor`, r = {
    arcade: `${e}/arcade.worker.js`,
    "arcgis-sql-expression": `${e}/sql-expr.worker.js`,
    "sql-layer-sql-server": `${e}/sql-layer.worker.js`,
    "sql-layer-postgres": `${e}/sql-layer.worker.js`,
    "sql-layer-bigquery": `${e}/sql-layer.worker.js`,
    html: `${e}/html.worker.js`,
    css: `${e}/css.worker.js`,
    typescript: `${e}/ts.worker.js`,
    json: `${e}/json.worker.js`,
    default: `${e}/editor.worker.js`
  }, t = {
    arcade: {
      url: r.arcade
    },
    "arcgis-sql-expression": {
      url: r["arcgis-sql-expression"]
    },
    "sql-layer-sql-server": {
      url: r["sql-layer-sql-server"]
    },
    "sql-layer-postgres": {
      url: r["sql-layer-postgres"]
    },
    "sql-layer-bigquery": {
      url: r["sql-layer-bigquery"]
    },
    html: {
      url: r.html
    },
    css: {
      url: r.css
    },
    typescript: {
      url: r.typescript
    },
    javascript: {
      url: r.typescript
    },
    json: {
      url: r.json
    },
    default: {
      url: r.default
    }
  };
  window.MonacoEnvironment = {
    getWorker: async (u, o) => {
      const a = m.get(o);
      if (a)
        return await l(a, void 0, i);
      const { url: p, localWorker: f } = t[o] || t.default;
      return await l(p, f, i);
    }
  };
}
let c = !1;
function q() {
  c || (w.get(y), c = !0);
}
async function E() {
  return (await k()).getArcadeDiagnosticService();
}
async function k() {
  return await import("./arcade-mode.js");
}
export {
  k as a,
  E as g,
  U as s
};
