var m = Object.defineProperty;
var a = (n, t) => m(n, "name", { value: t, configurable: !0 });
import { rooms as L } from "./collab.js";
const { autocompletion: u } = await import("./node_modules/.pnpm/@codemirror_autocomplete@6.18.6/node_modules/@codemirror/autocomplete/dist/index.js"), { javascript: p } = await import("./node_modules/.pnpm/@codemirror_lang-javascript@6.2.3/node_modules/@codemirror/lang-javascript/dist/index.js"), { tsAutocompleteWorker: h, tsFacetWorker: E, tsGotoWorker: v, tsHoverWorker: g, tsLinterWorker: w, tsSyncWorker: C } = await import("./node_modules/.pnpm/@valtown_codemirror-ts@3.0.0-9_@codemirror_autocomplete@6.18.6_@codemirror_lint@6.8.5_@codemi_zyfniedpy4wyedcrakm4jzo4te/node_modules/@valtown/codemirror-ts/dist/index.js"), b = await import("./node_modules/.pnpm/comlink@4.4.2/node_modules/comlink/dist/esm/comlink.js"), { containerStyles: k, editorTheme: f, tooltipStyles: y } = await import("./styles.js"), { cmCollab: x } = await import("./collab.js"), { default: S } = await import("./worker2.js"), { codeiumCopilot: T, copilotStyle: A } = await import("./copilot.js"), { EditorView: W, basicSetup: N } = await import("./node_modules/.pnpm/codemirror@6.0.1/node_modules/codemirror/dist/index.js");
function d(n) {
  const t = document.createElement("div");
  for (const e of n) {
    const i = t.appendChild(document.createElement("span"));
    i.className = `quick-info-${e.kind}`, i.innerText = e.text;
  }
  return t;
}
a(d, "renderDisplayParts");
const R = "cm:ts:ready", V = "change";
class D extends HTMLElement {
  static {
    a(this, "TypeScriptEditor");
  }
  editor = null;
  static get observedAttributes() {
    return ["value", "url", "room", "component"];
  }
  constructor() {
    super(), this.attachShadow({ mode: "open" });
  }
  get url() {
    return this.getAttribute("url") || "ws://localhost:1234";
  }
  get room() {
    return this.getAttribute("room") || "default";
  }
  get component() {
    return this.getAttribute("component") || "codemirror";
  }
  async connectedCallback() {
    const t = document.createElement("style");
    t.textContent = k + y + A, this.shadowRoot?.appendChild(t);
    const e = document.createElement("div");
    e.id = "editor", this.shadowRoot?.appendChild(e);
    const i = "index.ts", l = new S({
      name: "ts-editor-worker"
    }), c = b.wrap(l);
    await c.initialize(), this.editor = new W({
      extensions: [
        N,
        f,
        p({
          typescript: !0,
          jsx: !0
        }),
        E.of({ worker: c, path: i }),
        // syntaxHighlighting(classHighlighter),
        C(),
        w(),
        u({
          override: [
            h({
              renderAutocomplete: /* @__PURE__ */ a((r) => () => {
                const s = document.createElement("div");
                if (s.classList.add("cm-tooltip"), r.displayParts) {
                  const o = s.appendChild(document.createElement("div"));
                  o.className = "quick-info-signature", o.appendChild(d(r.displayParts));
                }
                if (r.documentation) {
                  const o = s.appendChild(document.createElement("div"));
                  o.className = "quick-info-documentation", o.appendChild(d(r.documentation));
                }
                return { dom: s };
              }, "renderAutocomplete")
            })
          ]
        }),
        g(),
        v(),
        x({
          url: this.url,
          room: this.room,
          component: this.component
        }),
        T()
      ],
      parent: e
    }), this.editor.dom.onchange = this.onValueChanged.bind(this), this.dispatchEvent(new CustomEvent(R, {
      detail: this.editor,
      bubbles: !0,
      composed: !0
    }));
  }
  onValueChanged(t) {
    console.debug("cm: value changed", t), this.dispatchEvent(new CustomEvent(V, {
      detail: this.value,
      bubbles: !0,
      composed: !0
    }));
  }
  disconnectedCallback() {
    this.editor?.destroy();
  }
  get value() {
    return this.editor?.state.doc.toString() || "";
  }
  set value(t) {
    this.editor && this.editor.dispatch({
      changes: {
        from: 0,
        to: this.editor.state.doc.length,
        insert: t
      }
    });
  }
}
customElements.define("ts-editor", D);
export {
  V as EDITOR_CHANGE_EVENT,
  R as EDITOR_READY_EVENT,
  D as TypeScriptEditor,
  d as renderDisplayParts,
  L as rooms
};
