import { a3 as E, ej as H, dr as P, w as p, V as N, a5 as b, ek as O, aG as j, ci as J, U as M, el as V, em as F, H as t, eh as k, ad as g, I as C, ae as n, af as c, a4 as h, co as $, am as i, ag as B, ah as T, aj as A, ai as D, aH as I, W as L, c3 as x } from "./56c67d3b.js";
import { useRef as d, useEffect as v, useContext as l } from "react";
import { defaultData as R } from "./0a417d48.js";
import { u as U } from "./cf64eb1a.js";
import "react-dom";
import "./c320947b.js";
import "./99912daf.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 z(e) {
  return e && !e.hasOwnProperty("label") ? {
    ...e,
    label: {
      text: ""
    }
  } : e;
}
function G(e) {
  return e && e.hasOwnProperty("default") ? {
    ...e,
    value: e.default
  } : e;
}
const q = {
  value: H("value", R),
  onEvent: P,
  autoHeight: p(I, "auto"),
  showVerticalScrollbar: N,
  label: p(L, {
    position: "column"
  }),
  style: b(O, "style"),
  animationStyle: b(j, "animationStyle"),
  ...J
};
let o = function() {
  return new M(q, (e) => {
    var w;
    const r = d(null), m = d(null), y = d(!1), f = d(null), s = d(), {
      extensions: S
    } = 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(() => {
      !y.current && r.current && (f.current = V.create({
        doc: JSON.stringify(e.value.value, null, 2),
        extensions: S
      }));
    }, [r.current]), v(() => {
      f.current && r.current && (m.current = new F({
        state: f.current,
        parent: r.current
      }), y.current = !0);
    }, [e.showVerticalScrollbar]), r.current && m.current && !s.current) {
      const a = V.create({
        doc: JSON.stringify(e.value.value, null, 2),
        extensions: S
      });
      (w = m.current) == null || w.setState(a);
    }
    return s.current && (s.current = void 0), e.label({
      style: e.style,
      animationStyle: e.animationStyle,
      children: /* @__PURE__ */ t(k, {
        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($, {
      ...e
    }), (l(i).editorModeStatus === "logic" || l(i).editorModeStatus === "both") && /* @__PURE__ */ g(n, {
      name: c.interaction,
      children: [e.onEvent.getPropertyView(), B(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, z);
o = x(o, G);
o = class extends o {
  autoHeight() {
    return this.children.autoHeight.getView();
  }
};
const te = T(o, [new A("value", h("export.jsonEditorDesc")), D]);
export {
  te as JsonEditorComp
};
