import K from "../../../../../@monaco-editor_loader@1.5.0/node_modules/@monaco-editor/loader/lib/es/loader/index.js";
import b, { memo as q, useState as j, useRef as s, useCallback as $, useEffect as V } from "react";
var ne = { wrapper: { display: "flex", position: "relative", textAlign: "initial" }, fullWidth: { width: "100%" }, hide: { display: "none" } }, Z = ne, ie = { container: { display: "flex", height: "100%", width: "100%", justifyContent: "center", alignItems: "center" } }, ue = ie;
function oe({ children: r }) {
  return b.createElement("div", { style: ue.container }, r);
}
var ae = oe, le = ae;
function ce({ width: r, height: u, isEditorReady: l, loading: n, _ref: p, className: h, wrapperProps: w }) {
  return b.createElement("section", { style: { ...Z.wrapper, width: r, height: u }, ...w }, !l && b.createElement(le, null, n), b.createElement("div", { ref: p, style: { ...Z.fullWidth, ...!l && Z.hide }, className: h }));
}
var de = ce, T = q(de);
function se(r) {
  V(r, []);
}
var ee = se;
function ge(r, u, l = !0) {
  let n = s(!0);
  V(n.current || !l ? () => {
    n.current = !1;
  } : r, u);
}
var m = ge;
function I() {
}
function P(r, u, l, n) {
  return fe(r, n) || pe(r, u, l, n);
}
function fe(r, u) {
  return r.editor.getModel(re(r, u));
}
function pe(r, u, l, n) {
  return r.editor.createModel(u, l, n ? re(r, n) : void 0);
}
function re(r, u) {
  return r.Uri.parse(u);
}
function he({ original: r, modified: u, language: l, originalLanguage: n, modifiedLanguage: p, originalModelPath: h, modifiedModelPath: w, keepCurrentOriginalModel: C = !1, keepCurrentModifiedModel: A = !1, theme: L = "light", loading: R = "Loading...", options: E = {}, height: B = "100%", width: G = "100%", className: J, wrapperProps: Q = {}, beforeMount: X = I, onMount: Y = I }) {
  let [M, N] = j(!1), [k, d] = j(!0), g = s(null), c = s(null), _ = s(null), f = s(Y), i = s(X), y = s(!1);
  ee(() => {
    let e = K.init();
    return e.then((o) => (c.current = o) && d(!1)).catch((o) => (o == null ? void 0 : o.type) !== "cancelation" && console.error("Monaco initialization: error:", o)), () => g.current ? D() : e.cancel();
  }), m(() => {
    if (g.current && c.current) {
      let e = g.current.getOriginalEditor(), o = P(c.current, r || "", n || l || "text", h || "");
      o !== e.getModel() && e.setModel(o);
    }
  }, [h], M), m(() => {
    if (g.current && c.current) {
      let e = g.current.getModifiedEditor(), o = P(c.current, u || "", p || l || "text", w || "");
      o !== e.getModel() && e.setModel(o);
    }
  }, [w], M), m(() => {
    let e = g.current.getModifiedEditor();
    e.getOption(c.current.editor.EditorOption.readOnly) ? e.setValue(u || "") : u !== e.getValue() && (e.executeEdits("", [{ range: e.getModel().getFullModelRange(), text: u || "", forceMoveMarkers: !0 }]), e.pushUndoStop());
  }, [u], M), m(() => {
    var e, o;
    (o = (e = g.current) == null ? void 0 : e.getModel()) == null || o.original.setValue(r || "");
  }, [r], M), m(() => {
    let { original: e, modified: o } = g.current.getModel();
    c.current.editor.setModelLanguage(e, n || l || "text"), c.current.editor.setModelLanguage(o, p || l || "text");
  }, [l, n, p], M), m(() => {
    var e;
    (e = c.current) == null || e.editor.setTheme(L);
  }, [L], M), m(() => {
    var e;
    (e = g.current) == null || e.updateOptions(E);
  }, [E], M);
  let z = $(() => {
    var O;
    if (!c.current) return;
    i.current(c.current);
    let e = P(c.current, r || "", n || l || "text", h || ""), o = P(c.current, u || "", p || l || "text", w || "");
    (O = g.current) == null || O.setModel({ original: e, modified: o });
  }, [l, u, p, r, n, h, w]), H = $(() => {
    var e;
    !y.current && _.current && (g.current = c.current.editor.createDiffEditor(_.current, { automaticLayout: !0, ...E }), z(), (e = c.current) == null || e.editor.setTheme(L), N(!0), y.current = !0);
  }, [E, L, z]);
  V(() => {
    M && f.current(g.current, c.current);
  }, [M]), V(() => {
    !k && !M && H();
  }, [k, M, H]);
  function D() {
    var o, O, S, U;
    let e = (o = g.current) == null ? void 0 : o.getModel();
    C || ((O = e == null ? void 0 : e.original) == null || O.dispose()), A || ((S = e == null ? void 0 : e.modified) == null || S.dispose()), (U = g.current) == null || U.dispose();
  }
  return b.createElement(T, { width: G, height: B, isEditorReady: M, loading: R, _ref: _, className: J, wrapperProps: Q });
}
var Me = he;
q(Me);
function ve(r) {
  let u = s();
  return V(() => {
    u.current = r;
  }, [r]), u.current;
}
var me = ve, W = /* @__PURE__ */ new Map();
function we({ defaultValue: r, defaultLanguage: u, defaultPath: l, value: n, language: p, path: h, theme: w = "light", line: C, loading: A = "Loading...", options: L = {}, overrideServices: R = {}, saveViewState: E = !0, keepCurrentModel: B = !1, width: G = "100%", height: J = "100%", className: Q, wrapperProps: X = {}, beforeMount: Y = I, onMount: M = I, onChange: N, onValidate: k = I }) {
  let [d, g] = j(!1), [c, _] = j(!0), f = s(null), i = s(null), y = s(null), z = s(M), H = s(Y), D = s(), e = s(n), o = me(h), O = s(!1), S = s(!1);
  ee(() => {
    let t = K.init();
    return t.then((a) => (f.current = a) && _(!1)).catch((a) => (a == null ? void 0 : a.type) !== "cancelation" && console.error("Monaco initialization: error:", a)), () => i.current ? te() : t.cancel();
  }), m(() => {
    var a, v, F, x;
    let t = P(f.current, r || n || "", u || p || "", h || l || "");
    t !== ((a = i.current) == null ? void 0 : a.getModel()) && (E && W.set(o, (v = i.current) == null ? void 0 : v.saveViewState()), (F = i.current) == null || F.setModel(t), E && ((x = i.current) == null || x.restoreViewState(W.get(h))));
  }, [h], d), m(() => {
    var t;
    (t = i.current) == null || t.updateOptions(L);
  }, [L], d), m(() => {
    !i.current || n === void 0 || (i.current.getOption(f.current.editor.EditorOption.readOnly) ? i.current.setValue(n) : n !== i.current.getValue() && (S.current = !0, i.current.executeEdits("", [{ range: i.current.getModel().getFullModelRange(), text: n, forceMoveMarkers: !0 }]), i.current.pushUndoStop(), S.current = !1));
  }, [n], d), m(() => {
    var a, v;
    let t = (a = i.current) == null ? void 0 : a.getModel();
    t && p && ((v = f.current) == null || v.editor.setModelLanguage(t, p));
  }, [p], d), m(() => {
    var t;
    C !== void 0 && ((t = i.current) == null || t.revealLine(C));
  }, [C], d), m(() => {
    var t;
    (t = f.current) == null || t.editor.setTheme(w);
  }, [w], d);
  let U = $(() => {
    var t;
    if (!(!y.current || !f.current) && !O.current) {
      H.current(f.current);
      let a = h || l, v = P(f.current, n || r || "", u || p || "", a || "");
      i.current = (t = f.current) == null ? void 0 : t.editor.create(y.current, { model: v, automaticLayout: !0, ...L }, R), E && i.current.restoreViewState(W.get(a)), f.current.editor.setTheme(w), C !== void 0 && i.current.revealLine(C), g(!0), O.current = !0;
    }
  }, [r, u, l, n, p, h, L, R, E, w, C]);
  V(() => {
    d && z.current(i.current, f.current);
  }, [d]), V(() => {
    !c && !d && U();
  }, [c, d, U]), e.current = n, V(() => {
    var t, a;
    d && N && ((t = D.current) == null || t.dispose(), D.current = (a = i.current) == null ? void 0 : a.onDidChangeModelContent((v) => {
      S.current || N(i.current.getValue(), v);
    }));
  }, [d, N]), V(() => {
    if (d) {
      let t = f.current.editor.onDidChangeMarkers((a) => {
        var F;
        let v = (F = i.current.getModel()) == null ? void 0 : F.uri;
        if (v && a.find((x) => x.path === v.path)) {
          let x = f.current.editor.getModelMarkers({ resource: v });
          k == null || k(x);
        }
      });
      return () => {
        t == null || t.dispose();
      };
    }
    return () => {
    };
  }, [d, k]);
  function te() {
    var t, a;
    (t = D.current) == null || t.dispose(), B ? E && W.set(h, i.current.saveViewState()) : (a = i.current.getModel()) == null || a.dispose(), i.current.dispose();
  }
  return b.createElement(T, { width: G, height: J, isEditorReady: d, loading: A, _ref: y, className: Q, wrapperProps: X });
}
var Ee = we, Le = q(Ee), Oe = Le;
export {
  Le as Editor,
  Oe as default,
  K as loader
};
//# sourceMappingURL=index.js.map
