import { X as E, ed as P, cW as O, w as p, O as H, Z as b, ee as N, az as J, U as M, ef as V, eg as j, F as t, dk as F, a6 as g, G as C, a7 as n, a8 as c, Y as h, af as i, a9 as k, aa as $, ac as A, ab as B, aA as T, P as z, bS as x } from "./603b75d9.js";
import { useRef as d, useEffect as v, useContext as l } from "react";
import { defaultData as D } from "./0a417d48.js";
import { formDataChildren as L, FormDataPropertyView as R } from "./f9847c56.js";
import { u as U } from "./c3d6afd0.js";
import "react-dom";
import "./c320947b.js";
import "./8fde2cf8.js";
const W = E.div`
  background-color: #fff;
  border: 1px solid #d7d9e0;
  border-radius: 4px;
  height: 100%;
  overflow-y: ${(e) => e.$showVerticalScrollbar ? "scroll" : "auto"};
`;
function G(e) {
  return e && !e.hasOwnProperty("label") ? {
    ...e,
    label: {
      text: ""
    }
  } : e;
}
function I(e) {
  return e && e.hasOwnProperty("default") ? {
    ...e,
    value: e.default
  } : e;
}
const X = {
  value: P("value", D),
  onEvent: O,
  autoHeight: p(T, "auto"),
  showVerticalScrollbar: H,
  label: p(z, {
    position: "column"
  }),
  style: b(N, "style"),
  animationStyle: b(J, "animationStyle"),
  ...L
};
let o = function() {
  return new M(X, (e) => {
    var w;
    const r = d(null), f = d(null), S = d(!1), m = d(null), s = d(), {
      extensions: y
    } = U({
      codeType: "PureJSON",
      language: "json",
      showLineNum: !0,
      enableClickCompName: !1,
      onFocus: (a) => {
        var u;
        a && ((u = r.current) == null || u.click());
      },
      onChange: (a) => {
        s.current = a.doc.toString();
        try {
          const u = JSON.parse(a.doc.toString());
          e.value.onChange(u), e.onEvent("change");
        } catch {
        }
      }
    });
    if (v(() => {
      !S.current && r.current && (m.current = V.create({
        doc: JSON.stringify(e.value.value, null, 2),
        extensions: y
      }));
    }, [r.current]), v(() => {
      m.current && r.current && (f.current = new j({
        state: m.current,
        parent: r.current
      }), S.current = !0);
    }, [e.showVerticalScrollbar]), r.current && f.current && !s.current) {
      const a = V.create({
        doc: JSON.stringify(e.value.value, null, 2),
        extensions: y
      });
      (w = f.current) == null || w.setState(a);
    }
    return s.current && (s.current = void 0), e.label({
      style: e.style,
      animationStyle: e.animationStyle,
      children: /* @__PURE__ */ t(F, {
        hideScrollbar: !e.showVerticalScrollbar,
        children: /* @__PURE__ */ t(W, {
          ref: r,
          onFocus: () => s.current = "focus",
          $height: e.autoHeight,
          $showVerticalScrollbar: e.showVerticalScrollbar
        })
      })
    });
  }).setPropertyViewFn((e) => /* @__PURE__ */ g(C, {
    children: [/* @__PURE__ */ t(n, {
      name: c.basic,
      children: e.value.propertyView({
        label: h("export.jsonEditorDesc")
      })
    }), /* @__PURE__ */ t(R, {
      ...e
    }), (l(i).editorModeStatus === "logic" || l(i).editorModeStatus === "both") && /* @__PURE__ */ g(n, {
      name: c.interaction,
      children: [e.onEvent.getPropertyView(), k(e)]
    }), /* @__PURE__ */ t(n, {
      name: h("prop.height"),
      children: e.autoHeight.propertyView({
        label: h("prop.height")
      })
    }), !e.autoHeight.getView() && /* @__PURE__ */ t(n, {
      name: c.layout,
      children: e.showVerticalScrollbar.propertyView({
        label: h("prop.showVerticalScrollbar")
      })
    }), (l(i).editorModeStatus === "layout" || l(i).editorModeStatus === "both") && e.label.getPropertyView(), (l(i).editorModeStatus === "layout" || l(i).editorModeStatus === "both") && /* @__PURE__ */ g(C, {
      children: [/* @__PURE__ */ t(n, {
        name: c.style,
        children: e.style.getPropertyView()
      }), /* @__PURE__ */ t(n, {
        name: c.animationStyle,
        hasTooltip: !0,
        children: e.animationStyle.getPropertyView()
      })]
    })]
  })).build();
}();
o = x(o, G);
o = x(o, I);
o = class extends o {
  autoHeight() {
    return this.children.autoHeight.getView();
  }
};
const re = $(o, [new A("value", h("export.jsonEditorDesc")), B]);
export {
  re as JsonEditorComp
};
