import type { useMonaco } from "@monaco-editor/react";
import typings from "bundle-text:../../../executor/src/builtins/builtins.d.ts";

const TYPINGS_URI = "ts:platform.d.ts";

export function configureEditor(
  monaco: NonNullable<ReturnType<typeof useMonaco>>
) {
  monaco.typescript.javascriptDefaults.setCompilerOptions({
    target: monaco.typescript.ScriptTarget.ES2015,
    allowNonTsExtensions: true, // Fix the very weird bug. Don't touch. EVER.
  });

  monaco.typescript.javascriptDefaults.addExtraLib(typings, TYPINGS_URI);

  const uri = monaco.Uri.parse(TYPINGS_URI);

  if (!monaco.editor.getModel(uri)) {
    monaco.editor.createModel(typings, "typescript");
  }
}
