import { createFilterExpression as f } from "@arcgis/toolkit/string";
import { format as p } from "@arcgis/arcade-languageservice";
import "monaco-editor";
import "monaco-editor/esm/vs/editor/standalone/browser/standaloneServices.js";
import "monaco-editor/esm/vs/editor/standalone/common/standaloneTheme.js";
import "monaco-editor/esm/vs/editor/common/languages/supports/tokenization.js";
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
v5.0.0-next.20 */
function $(e, n, l, i) {
  if (!n)
    return [];
  const t = Array.isArray(n) ? n : [n];
  if (!t.length)
    return [];
  const m = f(l);
  return e.filter((o) => t.some((a) => m.test(String(o[a] ?? ""))));
}
function E(e) {
  return e ? `${e.portal.url}/home/item.html?id=${e.id}` : "";
}
function M(e, n, l = "add", i) {
  if (!e)
    return;
  const t = e.getSelection(), m = t && (t.startLineNumber !== t.endLineNumber || t.startColumn !== t.endColumn);
  let o = [];
  const a = e.getValue() ?? "";
  if (l === "replace") {
    const u = `${i}
${n}`, s = e.getModel(), r = s?.getLineCount() ?? 1, c = s?.getLineMaxColumn(r) ?? 1;
    o = [
      {
        range: {
          startLineNumber: 1,
          startColumn: 1,
          endLineNumber: r,
          endColumn: c
        },
        text: u
      }
    ];
  } else {
    const u = m ? {
      startLineNumber: t.startLineNumber,
      startColumn: t.startColumn,
      endLineNumber: t.endLineNumber,
      endColumn: t.endColumn
    } : (() => {
      const r = e.getPosition();
      return {
        startLineNumber: r?.lineNumber ?? 1,
        startColumn: r?.column ?? 1,
        endLineNumber: r?.lineNumber ?? 1,
        endColumn: r?.column ?? 1
      };
    })();
    let s = !1;
    if (i) {
      const r = i.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
      s = !new RegExp(`^\\s*${r}\\s*$`, "mu").test(a);
    }
    s && o.push({
      range: {
        startLineNumber: 1,
        startColumn: 1,
        endLineNumber: 1,
        endColumn: 1
      },
      text: `${i}
`
    }), o.push({
      range: u,
      text: n
    });
  }
  try {
    e.pushUndoStop(), e.executeEdits("insertText", o), e.pushUndoStop(), e.focus();
  } catch (u) {
    console.error("Failed to edit model:", u);
  }
}
function R(e) {
  try {
    return p(e);
  } catch {
    return e;
  }
}
const g = async () => {
  const { editor: e } = await import("monaco-editor/esm/vs/editor/editor.api.js");
  return e;
};
let d = null;
async function S() {
  return d ??= g(), await d;
}
export {
  R as a,
  M as e,
  $ as f,
  S as i,
  E as p
};
