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 "lodash/omit.js";
import cloneDeep from "lodash/cloneDeep.js";
import { p as page } from "../../../../../chunks/stores-9eb273d1.js";
import { E as Editor } from "../../../../../chunks/editor-8f7742a9.js";
import { E as Entity } from "../../../../../chunks/entity-66c03936.js";
import "lodash/get.js";
const U5Bcorrelation_idu5D = create_ssr_component(($$result, $$props, $$bindings, slots) => {
  let correlationId;
  let $datastore, $$unsubscribe_datastore;
  let $page, $$unsubscribe_page;
  let $models, $$unsubscribe_models;
  let $activeConfig, $$unsubscribe_activeConfig;
  $$unsubscribe_page = subscribe(page, (value) => $page = value);
  getContext("services");
  const activeConfig = getContext("stores").activeConfig;
  $$unsubscribe_activeConfig = subscribe(activeConfig, (value) => $activeConfig = value);
  const models = getContext("stores").models;
  $$unsubscribe_models = subscribe(models, (value) => $models = value);
  const datastore = getContext("stores").activeClient;
  $$unsubscribe_datastore = subscribe(datastore, (value) => $datastore = value);
  let model;
  let events = [];
  let entity = {};
  let originalValue = null;
  async function getValue(model2, correlationId2) {
    if (!model2 || !correlationId2) {
      return;
    }
    const { data } = await $datastore.get(model2.name, correlationId2);
    entity = data;
    try {
      const { data: [decrypted] } = await $datastore.decrypt(model2.name, [entity]);
      entity = decrypted;
    } catch (err) {
      console.warn("[decrypt] Not permitted");
    }
    originalValue = originalValue === null ? Object.freeze(cloneDeep(entity)) : originalValue;
  }
  async function getEvents(model2, correlationId2) {
    if (!model2 || !correlationId2) {
      return;
    }
    const res = await $datastore.events(model2.name, correlationId2);
    events = res.data.reverse();
  }
  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"}"><div class="${"w-8/12"}">${!!entity ? `${validate_component(Entity, "Entity").$$render($$result, {
      activeConfig: $activeConfig,
      model,
      entity
    }, {
      entity: ($$value) => {
        entity = $$value;
        $$settled = false;
      }
    }, {})}` : ``}</div>

		<div class="${"w-4/12"}" style="${"background-color: #272822;"}">${`${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();
  $$unsubscribe_activeConfig();
  return $$rendered;
});
export { U5Bcorrelation_idu5D as default };
