import{S as H,i as L,s as M,e as z,k as Q,c as D,a as S,d as w,n as T,b as N,J as Z,f as R,K as O,x as _,j as V,m as J,o as I,W as x,u as d,v as P,w as $,l as U,O as j,P as E,r as q,X as ee,Y as te,aj as W,ak as ne,al as re}from"../../../../chunks/vendor-cb8fe21e.js";import{p as se}from"../../../../chunks/stores-3696a338.js";import{E as oe}from"../../../../chunks/editor-045a54b8.js";import{E as ae}from"../../../../chunks/entity-d9b59351.js";import{E as ie}from"../../../../chunks/error-ce582bf2.js";import"../../../../chunks/preload-helper-ec9aa979.js";import"../../../../chunks/navigation-51f4a605.js";import"../../../../chunks/singletons-12a22614.js";function X(a){let t,n,e,r,s,o,p,i=!!a[2]&&Y(a);const h=[le,ce],m=[];function b(c,u){return c[3]?0:1}return s=b(a),o=m[s]=h[s](a),{c(){t=z("div"),n=z("div"),i&&i.c(),e=Q(),r=z("div"),o.c(),this.h()},l(c){t=D(c,"DIV",{class:!0});var u=S(t);n=D(u,"DIV",{class:!0});var f=S(n);i&&i.l(f),f.forEach(w),e=T(u),r=D(u,"DIV",{class:!0,style:!0});var g=S(r);o.l(g),g.forEach(w),u.forEach(w),this.h()},h(){N(n,"class","w-8/12"),N(r,"class","w-4/12"),Z(r,"background-color","#272822"),N(t,"class","flex flex-column h-screen")},m(c,u){R(c,t,u),O(t,n),i&&i.m(n,null),O(t,e),O(t,r),m[s].m(r,null),p=!0},p(c,u){c[2]?i?(i.p(c,u),u&4&&_(i,1)):(i=Y(c),i.c(),_(i,1),i.m(n,null)):i&&(q(),d(i,1,1,()=>{i=null}),$());let f=s;s=b(c),s===f?m[s].p(c,u):(q(),d(m[f],1,1,()=>{m[f]=null}),$(),o=m[s],o?o.p(c,u):(o=m[s]=h[s](c),o.c()),_(o,1),o.m(r,null))},i(c){p||(_(i),_(o),p=!0)},o(c){d(i),d(o),p=!1},d(c){c&&w(t),i&&i.d(),m[s].d()}}}function Y(a){let t,n,e;function r(o){a[12](o)}let s={activeConfig:a[4],model:a[0]};return a[2]!==void 0&&(s.entity=a[2]),t=new ae({props:s}),ee.push(()=>te(t,"entity",r)),t.$on("save",a[8]),{c(){V(t.$$.fragment)},l(o){J(t.$$.fragment,o)},m(o,p){I(t,o,p),e=!0},p(o,p){const i={};p&16&&(i.activeConfig=o[4]),p&1&&(i.model=o[0]),!n&&p&4&&(n=!0,i.entity=o[2],x(()=>n=!1)),t.$set(i)},i(o){e||(_(t.$$.fragment,o),e=!0)},o(o){d(t.$$.fragment,o),e=!1},d(o){P(t,o)}}}function ce(a){let t,n;return t=new oe({props:{language:"json",fontSize:"10px",isReadonly:!0,value:JSON.stringify(a[1],null,2)}}),{c(){V(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,r){I(t,e,r),n=!0},p(e,r){const s={};r&2&&(s.value=JSON.stringify(e[1],null,2)),t.$set(s)},i(e){n||(_(t.$$.fragment,e),n=!0)},o(e){d(t.$$.fragment,e),n=!1},d(e){P(t,e)}}}function le(a){let t,n;return t=new ie({props:{error:a[3]}}),{c(){V(t.$$.fragment)},l(e){J(t.$$.fragment,e)},m(e,r){I(t,e,r),n=!0},p(e,r){const s={};r&8&&(s.error=e[3]),t.$set(s)},i(e){n||(_(t.$$.fragment,e),n=!0)},o(e){d(t.$$.fragment,e),n=!1},d(e){P(t,e)}}}function fe(a){let t,n,e=!!a[0]&&X(a);return{c(){e&&e.c(),t=U()},l(r){e&&e.l(r),t=U()},m(r,s){e&&e.m(r,s),R(r,t,s),n=!0},p(r,[s]){r[0]?e?(e.p(r,s),s&1&&_(e,1)):(e=X(r),e.c(),_(e,1),e.m(t.parentNode,t)):e&&(q(),d(e,1,1,()=>{e=null}),$())},i(r){n||(_(e),n=!0)},o(r){d(e),n=!1},d(r){e&&e.d(r),r&&w(t)}}}function ue(a,t,n){let e,r,s,o,p;j(a,se,l=>n(10,s=l));const i=E("services"),h=E("stores").activeConfig;j(a,h,l=>n(4,p=l));const m=E("stores").models;j(a,m,l=>n(11,o=l));const b=E("stores").activeClient;j(a,b,l=>n(14,r=l));let c,u=[],f={},g=null,C;async function A(l,y){if(!l||!y)return;const{data:k}=await r.get(l.name,y);n(2,f=k);try{const{data:[v]}=await r.decrypt(l.name,[f]);n(2,f=v)}catch{console.warn("[decrypt] Not permitted")}g=g===null?Object.freeze(W(f)):g}async function F(){console.log("Saving...",f);try{n(3,C=null);const l=ne(i.sanitize(g),i.sanitize(f));if(l.length===0)return;const{newDocument:y}=re({},l),k=i.sanitize(y),v=await r.update(c.name,e,k);try{const{data:[K]}=await r.decrypt(c.name,[v.data]);n(2,f=K)}catch{console.warn("[decrypt] Not permitted"),n(2,f=v.data)}g=Object.freeze(W(f)),console.log("Entity updated",{entity:f}),B(c,e)}catch(l){n(3,C=l)}}async function B(l,y){if(!l||!y)return;const k=await r.events(l.name,y);n(1,u=k.data.reverse())}function G(l){f=l,n(2,f)}return a.$$.update=()=>{a.$$.dirty&3072&&n(0,c=o[s.params.model]),a.$$.dirty&1024&&n(9,e=s.params.correlation_id),a.$$.dirty&513&&A(c,e),a.$$.dirty&513&&B(c,e)},[c,u,f,C,p,h,m,b,F,e,s,o,G]}class ke extends H{constructor(t){super();L(this,t,ue,fe,M,{})}}export{ke as default};
