var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
import { c as create_ssr_component, b as subscribe, g as getContext, v as validate_component } from "../../../../../chunks/index-0e008fb3.js";
import "fast-json-patch";
import cloneDeep from "lodash/cloneDeep.js";
import "lodash/get.js";
import "lodash/omit.js";
import "lodash/set.js";
import { p as page } from "../../../../../chunks/stores-9eb273d1.js";
import { E as Editor } from "../../../../../chunks/editor-8f7742a9.js";
import { E as Error2 } from "../../../../../chunks/error-b3674f8e.js";
const Raw = create_ssr_component(($$result, $$props, $$bindings, slots) => {
  let correlationId;
  let $datastore, $$unsubscribe_datastore;
  let $page, $$unsubscribe_page;
  let $models, $$unsubscribe_models;
  $$unsubscribe_page = subscribe(page, (value2) => $page = value2);
  getContext("services");
  const models = getContext("stores").models;
  $$unsubscribe_models = subscribe(models, (value2) => $models = value2);
  const datastore = getContext("stores").activeClient;
  $$unsubscribe_datastore = subscribe(datastore, (value2) => $datastore = value2);
  let model;
  let value;
  let error;
  let events = [];
  let entity = {};
  let originalValue = null;
  let editor;
  async function getValue(model2, correlationId2) {
    if (!model2 || !correlationId2) {
      return;
    }
    const res = await $datastore.get(model2.name, correlationId2);
    try {
      const { data: [decrypted] } = await $datastore.decrypt(model2.name, [res.data]);
      entity = decrypted;
    } catch (err) {
      console.warn("[decrypt] Not permitted");
      entity = res.data;
    }
    originalValue = originalValue === null ? Object.freeze(cloneDeep(entity)) : originalValue;
    return setValue(entity);
  }
  async function getEvents(model2, correlationId2) {
    if (!model2 || !correlationId2) {
      return;
    }
    const res = await $datastore.events(model2.name, correlationId2);
    events = res.data.reverse();
  }
  function setValue(entity2) {
    value = JSON.stringify(entity2, null, 2);
  }
  let $$settled;
  let $$rendered;
  do {
    $$settled = true;
    model = $models[$page.params.model];
    correlationId = $page.params.correlation_id;
    {
      getValue(model, correlationId);
    }
    {
      getEvents(model, correlationId);
    }
    $$rendered = `${!!model ? `<div class="${"flex flex-column h-screen"}" style="${"background-color: #272822;"}"><div class="${"w-8/12 border-r-2"}" style="${"border-color: #171812;"}"><div class="${"w-full h-4/6"}">${validate_component(Editor, "Editor").$$render($$result, {
      language: "json",
      schema: __spreadValues({ type: "object" }, model.schema.model),
      this: editor,
      value
    }, {
      this: ($$value) => {
        editor = $$value;
        $$settled = false;
      },
      value: ($$value) => {
        value = $$value;
        $$settled = false;
      }
    }, {})}</div>

			<div class="${"w-full h-2/6 border-t-2"}" style="${"border-color: #171812;"}">${validate_component(Error2, "Error").$$render($$result, { error }, {}, {})}</div></div>

		<div class="${"w-4/12"}">${validate_component(Editor, "Editor").$$render($$result, {
      language: "json",
      fontSize: "10px",
      isReadonly: true,
      value: JSON.stringify(events, null, 2)
    }, {}, {})}</div></div>` : ``}`;
  } while (!$$settled);
  $$unsubscribe_datastore();
  $$unsubscribe_page();
  $$unsubscribe_models();
  return $$rendered;
});
export { Raw as default };
