import { b9 as w, ef as v, cK as C, w as S, bK as x, bB as E, eg as P, U as V, eh as p, H as N, V as l, P as g, bh as O, bi as c, bj as d, a0 as y, bg as n, bl as j, bn as J, bo as M, bG as F, bA as h } from "./684d2f28.js";
import { useRef as f, useEffect as H, useContext as a } from "react";
import { defaultData as k } from "./0a417d48.js";
import { formDataChildren as B, FormDataPropertyView as D } from "./00dac55d.js";
import { u as K } from "./94fb0922.js";
import "react-dom";
import "./6478e58a.js";
const L = w.div`
  background-color: #fff;
  border: 1px solid #d7d9e0;
  border-radius: 4px;
  overflow: auto;
  height: 100%;
`;
function R(e) {
  return e && !e.hasOwnProperty("label") ? {
    ...e,
    label: {
      text: ""
    }
  } : e;
}
function T(e) {
  return e && e.hasOwnProperty("default") ? {
    ...e,
    value: e.default
  } : e;
}
const U = {
  value: v("value", k),
  onEvent: C,
  label: S(x, {
    position: "column"
  }),
  style: E(P),
  ...B
};
let r = function() {
  return new V(U, (e) => {
    var b;
    const o = f(null), u = f(null), s = f(), {
      extensions: m
    } = K({
      codeType: "PureJSON",
      language: "json",
      showLineNum: !0,
      enableClickCompName: !1,
      onFocus: (t) => {
        var i;
        t && ((i = o.current) == null || i.click());
      },
      onChange: (t) => {
        s.current = t.doc.toString();
        try {
          const i = JSON.parse(t.doc.toString());
          e.value.onChange(i), e.onEvent("change");
        } catch {
        }
      }
    });
    if (H(() => {
      if (o.current && !u.current) {
        const t = p.create({
          doc: JSON.stringify(e.value.value, null, 2),
          extensions: m
        });
        u.current = new N({
          state: t,
          parent: o.current
        });
      }
    }, [o.current]), o.current && u.current && !s.current) {
      const t = p.create({
        doc: JSON.stringify(e.value.value, null, 2),
        extensions: m
      });
      (b = u.current) == null || b.setState(t);
    }
    return s.current && (s.current = void 0), e.label({
      style: e.style,
      children: /* @__PURE__ */ l(L, {
        ref: o,
        onFocus: () => s.current = "focus"
      })
    });
  }).setPropertyViewFn((e) => /* @__PURE__ */ g(O, {
    children: [/* @__PURE__ */ l(c, {
      name: d.basic,
      children: e.value.propertyView({
        label: y("export.jsonEditorDesc")
      })
    }), /* @__PURE__ */ l(D, {
      ...e
    }), (a(n).editorModeStatus === "logic" || a(n).editorModeStatus === "both") && /* @__PURE__ */ g(c, {
      name: d.interaction,
      children: [e.onEvent.getPropertyView(), j(e)]
    }), (a(n).editorModeStatus === "layout" || a(n).editorModeStatus === "both") && e.label.getPropertyView(), (a(n).editorModeStatus === "layout" || a(n).editorModeStatus === "both") && /* @__PURE__ */ l(c, {
      name: d.style,
      children: e.style.getPropertyView()
    })]
  })).build();
}();
r = h(r, R);
r = h(r, T);
r = class extends r {
  autoHeight() {
    return !1;
  }
};
const X = J(r, [new M("value", y("export.jsonEditorDesc")), F]);
export {
  X as JsonEditorComp
};
