import "../../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.mjs";
import { useMonacoEditor } from "./index.hook.mjs";
import "./index.vue.mjs";
import _sfc_main$1 from "./EditorWorker.vue.mjs";
import { defineComponent, onMounted, watch, openBlock, createElementBlock, createElementVNode as createBaseVNode, createVNode, Fragment } from "../../../../node_modules/.pnpm/@vue_runtime-core@3.3.4/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.mjs";
import { normalizeStyle } from "../../../../node_modules/.pnpm/@vue_shared@3.3.4/node_modules/@vue/shared/dist/shared.esm-bundler.mjs";
import { unref } from "../../../../node_modules/.pnpm/@vue_reactivity@3.3.4/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.mjs";
const _sfc_main = /* @__PURE__ */ 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 } = useMonacoEditor(props.language);
    const updateMonacoVal = (_val) => {
      const { modelValue, preComment } = props;
      const val = preComment ? `${preComment}
${_val || modelValue}` : _val || modelValue;
      updateVal(val);
    };
    onMounted(() => {
      const monacoEditor = createEditor(props.editorOptions);
      monacoEditor.onDidChangeModelContent(() => {
        emits("update:modelValue", monacoEditor.getValue());
      });
      monacoEditor.onDidBlurEditorText(() => {
        emits("blur");
      });
      updateMonacoVal();
    });
    watch(
      () => props.modelValue,
      (val) => {
        var _a;
        val !== ((_a = getEditor()) == null ? void 0 : _a.getValue()) && updateMonacoVal(val);
      }
    );
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock(Fragment, null, [
        createBaseVNode("div", {
          ref_key: "el",
          ref: el,
          class: "go-editor-area",
          style: normalizeStyle({ width: __props.width, height: __props.height })
        }, null, 4),
        createVNode(unref(_sfc_main$1))
      ], 64);
    };
  }
});
export {
  _sfc_main as default
};
