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