"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const index$1 = require("../_vendor/@codemirror/state/dist-index.cjs");
const index = require("../_vendor/@codemirror/view/dist-index.cjs");
const react = require("react");
const index$2 = require("../_vendor/@codemirror/commands/dist-index.cjs");
const index$4 = require("../_vendor/@codemirror/autocomplete/dist-index.cjs");
const index$5 = require("../_vendor/@codemirror/search/dist-index.cjs");
const index$3 = require("../_vendor/@codemirror/language/dist-index.cjs");
function useBaseExtensions(options = {}) {
  const {
    readonly = false,
    lineWrapping = true,
    onChange,
    onCursorChange,
    onSelectionChange,
    onEditorUpdate,
    theme,
    includeLineNumbers = true,
    includeKeymap = true
  } = options;
  const extensions = react.useMemo(() => {
    const baseExtensions = [];
    if (includeLineNumbers) {
      baseExtensions.push(index.lineNumbers());
    }
    baseExtensions.push(
      index.highlightActiveLineGutter(),
      index.highlightActiveLine()
    );
    if (lineWrapping) {
      baseExtensions.push(index.EditorView.lineWrapping);
    }
    if (theme) {
      baseExtensions.push(theme);
    }
    if (readonly) {
      baseExtensions.push(
        index$1.EditorState.readOnly.of(true),
        index.EditorView.editable.of(false)
      );
    } else {
      baseExtensions.push(
        index$2.history(),
        index$3.foldGutter({
          markerDOM: (open) => {
            const svgNS = "http://www.w3.org/2000/svg";
            const wrapper = document.createElement("div");
            wrapper.classList.add("cm-fold-marker");
            wrapper.style.cursor = "default";
            const svgElement = document.createElementNS(svgNS, "svg");
            svgElement.setAttribute("viewBox", "0 0 10 10");
            svgElement.setAttribute("width", "6");
            svgElement.setAttribute("height", "6");
            const pathElement = document.createElementNS(svgNS, "path");
            const d = open ? "M1 3 L5 7 L9 3" : "M3 1 L7 5 L3 9";
            pathElement.setAttribute("d", d);
            pathElement.setAttribute("fill", "none");
            pathElement.setAttribute("stroke", "currentColor");
            pathElement.setAttribute("stroke-width", "1.5");
            pathElement.setAttribute("stroke-linecap", "round");
            svgElement.appendChild(pathElement);
            wrapper.appendChild(svgElement);
            return wrapper;
          }
        }),
        index$3.indentOnInput(),
        index$3.bracketMatching(),
        index$4.closeBrackets(),
        index$5.highlightSelectionMatches({ minSelectionLength: 2 }),
        index.drawSelection(),
        index.dropCursor(),
        index$1.EditorState.allowMultipleSelections.of(true),
        index.EditorView.clickAddsSelectionRange.of(
          (event) => event.altKey && !event.metaKey && !event.shiftKey
        )
      );
      if (includeKeymap) {
        baseExtensions.push(
          index.keymap.of(index$4.closeBracketsKeymap)
        );
      }
      if (onChange || onCursorChange || onSelectionChange || onEditorUpdate) {
        baseExtensions.push(
          index.EditorView.updateListener.of((update) => {
            onEditorUpdate == null ? void 0 : onEditorUpdate(update);
            if (onChange && update.docChanged) {
              const newValue = update.state.doc.toString();
              onChange(newValue, update);
            }
            if (onCursorChange && update.selectionSet) {
              const { state } = update;
              const pos = state.selection.main.head;
              const lineInfo = state.doc.lineAt(pos);
              onCursorChange({
                column: pos - lineInfo.from + 1,
                line: lineInfo.number
              });
            }
            if (onSelectionChange && update.selectionSet) {
              const { state } = update;
              const { from, to } = state.selection.main;
              const characterCount = to - from;
              onSelectionChange(characterCount);
            }
          })
        );
      }
    }
    return baseExtensions;
  }, [
    readonly,
    lineWrapping,
    onChange,
    onCursorChange,
    onSelectionChange,
    onEditorUpdate,
    theme,
    includeLineNumbers,
    includeKeymap
  ]);
  return extensions;
}
exports.useBaseExtensions = useBaseExtensions;
//# sourceMappingURL=use-base-extensions.cjs.map
