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