"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var ricos_schema_exports = {};
__export(ricos_schema_exports, {
  RicosSchemaTab: () => RicosSchemaTab
});
module.exports = __toCommonJS(ricos_schema_exports);
var import_react = __toESM(require("react"));
var import_react_json_tree = require("react-json-tree");
var import_next_schema = require("./../../../ricos-schema/next-schema/index.js");
var import_button = require("../components/button.js");
var import_theme = require("../theme.js");
const RicosSchemaTab = () => {
  const [openedRef, setOpenedRef] = import_react.default.useState(null);
  import_react.default.useEffect(() => {
    if (!openedRef) {
      return;
    }
    const el = document.querySelector(`[data-definition="${openedRef}"]`);
    if (el) {
      el.scrollIntoView({ behavior: "smooth" });
    }
  }, [openedRef]);
  return /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("div", { style: { display: "flex", justifyContent: "flex-end" } }, /* @__PURE__ */ import_react.default.createElement("p", { style: { color: "rgba(205, 214, 244, .8)" } }, "Ricos schema is defined in JSON Typedef, you can read more about it", " ", /* @__PURE__ */ import_react.default.createElement(
    "a",
    {
      target: "_blank",
      style: { color: import_theme.jsonTreeTheme.base0A },
      href: "https://jsontypedef.com/docs/jtd-in-5-minutes/",
      rel: "noreferrer"
    },
    "here."
  )), /* @__PURE__ */ import_react.default.createElement(
    import_button.Button,
    {
      onClick: () => {
        console.log(import_next_schema.RicosDocumentJTD);
      }
    },
    "Log Schema"
  )), /* @__PURE__ */ import_react.default.createElement(
    import_react_json_tree.JSONTree,
    {
      collectionLimit: 0,
      labelRenderer: (path) => {
        if (path.length === 2 && path[1] === "definitions") {
          return /* @__PURE__ */ import_react.default.createElement("span", { "data-definition": path[0] }, path[0]);
        }
        return path[0];
      },
      valueRenderer: (valueAsString, value, ...nodePath) => {
        if (nodePath[0] === "ref") {
          return /* @__PURE__ */ import_react.default.createElement("span", null, valueAsString, /* @__PURE__ */ import_react.default.createElement(
            import_button.Button,
            {
              onClick: () => {
                setOpenedRef(value);
              }
            },
            "open"
          ));
        }
        return valueAsString;
      },
      data: import_next_schema.RicosDocumentJTD,
      invertTheme: false,
      theme: import_theme.jsonTreeTheme,
      hideRoot: true,
      shouldExpandNode: (path) => {
        const rev = [...path].reverse();
        if (rev.length === 1 && rev[0] === "definitions") {
          return true;
        }
        if (rev.length === 2 && rev[0] === "definitions" && openedRef && openedRef === rev[1]) {
          return true;
        }
        return false;
      }
    }
  ));
};
//# sourceMappingURL=ricos-schema.js.map
