"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
require("../../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.js");
const index_hook = require("./index.hook.js");
require("./index.vue.js");
const EditorWorker = require("./EditorWorker.vue.js");
const runtimeCore_esmBundler = require("../../../../node_modules/.pnpm/@vue_runtime-core@3.3.4/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js");
const shared_esmBundler = require("../../../../node_modules/.pnpm/@vue_shared@3.3.4/node_modules/@vue/shared/dist/shared.esm-bundler.js");
const reactivity_esmBundler = require("../../../../node_modules/.pnpm/@vue_reactivity@3.3.4/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js");
const _sfc_main = /* @__PURE__ */ runtimeCore_esmBundler.defineComponent({
  __name: "index",
  props: {
    width: {
      type: String,
      default: "100%"
    },
    height: {
      type: String,
      default: "90vh"
    },
    language: {
      type: String,
      default: "typescript"
    },
    preComment: {
      type: String,
      default: ""
    },
    modelValue: {
      type: String,
      default: ""
    },
    editorOptions: {
      type: Object,
      default: () => ({})
    }
  },
  emits: ["blur", "update:modelValue"],
  setup(__props, { emit: emits }) {
    const props = __props;
    const { el, updateVal, getEditor, createEditor } = index_hook.useMonacoEditor(props.language);
    const updateMonacoVal = (_val) => {
      const { modelValue, preComment } = props;
      const val = preComment ? `${preComment}
${_val || modelValue}` : _val || modelValue;
      updateVal(val);
    };
    runtimeCore_esmBundler.onMounted(() => {
      const monacoEditor = createEditor(props.editorOptions);
      monacoEditor.onDidChangeModelContent(() => {
        emits("update:modelValue", monacoEditor.getValue());
      });
      monacoEditor.onDidBlurEditorText(() => {
        emits("blur");
      });
      updateMonacoVal();
    });
    runtimeCore_esmBundler.watch(
      () => props.modelValue,
      (val) => {
        var _a;
        val !== ((_a = getEditor()) == null ? void 0 : _a.getValue()) && updateMonacoVal(val);
      }
    );
    return (_ctx, _cache) => {
      return runtimeCore_esmBundler.openBlock(), runtimeCore_esmBundler.createElementBlock(runtimeCore_esmBundler.Fragment, null, [
        runtimeCore_esmBundler.createElementVNode("div", {
          ref_key: "el",
          ref: el,
          class: "go-editor-area",
          style: shared_esmBundler.normalizeStyle({ width: __props.width, height: __props.height })
        }, null, 4),
        runtimeCore_esmBundler.createVNode(reactivity_esmBundler.unref(EditorWorker.default))
      ], 64);
    };
  }
});
exports.default = _sfc_main;
