var ae=Object.defineProperty;var G=Object.getOwnPropertySymbols;var se=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var H=(r,s,e)=>s in r?ae(r,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[s]=e,I=(r,s)=>{for(var e in s||(s={}))se.call(s,e)&&H(r,e,s[e]);if(G)for(var e of G(s))re.call(s,e)&&H(r,e,s[e]);return r};import{S as ne,i as oe,s as ie,e as V,j as C,k as L,c as D,a as N,m as P,d as w,n as M,b as O,J as ce,f as Q,K as k,o as R,a2 as le,x as E,u as $,v as q,l as T,w as ue,O as F,P as K,a0 as U,a1 as de,r as fe,ah as W,ai as pe,aj as me,F as _e}from"../../../../chunks/vendor-f44913f5.js";import{p as he}from"../../../../chunks/stores-79a3d42c.js";import{E as X}from"../../../../chunks/editor-9793cec3.js";import{E as ge}from"../../../../chunks/error-569bd06a.js";import"../../../../chunks/preload-helper-ec9aa979.js";function Y(r){let s,e,t,a,c,y,m,d,j,l,u,h;function z(n){r[12](n)}let f={language:"json",schema:I({type:"object"},r[0].schema.model)};return r[1]!==void 0&&(f.value=r[1]),a=new X({props:f}),r[11](a),U.push(()=>de(a,"value",z)),a.$on("save",r[13]),d=new ge({props:{error:r[2]}}),u=new X({props:{language:"json",fontSize:"10px",isReadonly:!0,value:JSON.stringify(r[3],null,2)}}),{c(){s=V("div"),e=V("div"),t=V("div"),C(a.$$.fragment),y=L(),m=V("div"),C(d.$$.fragment),j=L(),l=V("div"),C(u.$$.fragment),this.h()},l(n){s=D(n,"DIV",{class:!0,style:!0});var i=N(s);e=D(i,"DIV",{class:!0});var p=N(e);t=D(p,"DIV",{class:!0});var g=N(t);P(a.$$.fragment,g),g.forEach(w),y=M(p),m=D(p,"DIV",{class:!0});var v=N(m);P(d.$$.fragment,v),v.forEach(w),p.forEach(w),j=M(i),l=D(i,"DIV",{class:!0});var S=N(l);P(u.$$.fragment,S),S.forEach(w),i.forEach(w),this.h()},h(){O(t,"class","w-full h-3/6"),O(m,"class","w-full h-3/6"),O(e,"class","w-8/12"),O(l,"class","w-4/12"),O(s,"class","flex flex-column h-screen"),ce(s,"background-color","#272822")},m(n,i){Q(n,s,i),k(s,e),k(e,t),R(a,t,null),k(e,y),k(e,m),R(d,m,null),k(s,j),k(s,l),R(u,l,null),h=!0},p(n,i){const p={};i&1&&(p.schema=I({type:"object"},n[0].schema.model)),!c&&i&2&&(c=!0,p.value=n[1],le(()=>c=!1)),a.$set(p);const g={};i&4&&(g.error=n[2]),d.$set(g);const v={};i&8&&(v.value=JSON.stringify(n[3],null,2)),u.$set(v)},i(n){h||(E(a.$$.fragment,n),E(d.$$.fragment,n),E(u.$$.fragment,n),h=!0)},o(n){$(a.$$.fragment,n),$(d.$$.fragment,n),$(u.$$.fragment,n),h=!1},d(n){n&&w(s),r[11](null),q(a),q(d),q(u)}}}function ve(r){let s,e,t=!!r[0]&&Y(r);return{c(){t&&t.c(),s=T()},l(a){t&&t.l(a),s=T()},m(a,c){t&&t.m(a,c),Q(a,s,c),e=!0},p(a,[c]){a[0]?t?(t.p(a,c),c&1&&E(t,1)):(t=Y(a),t.c(),E(t,1),t.m(s.parentNode,s)):t&&(fe(),$(t,1,1,()=>{t=null}),ue())},i(a){e||(E(t),e=!0)},o(a){$(t),e=!1},d(a){t&&t.d(a),a&&w(s)}}}function ye(r,s,e){let t,a,c,y;F(r,he,o=>e(9,c=o));const m=K("services"),d=K("stores").models;F(r,d,o=>e(10,y=o));const j=K("stores").activeClient;F(r,j,o=>e(16,a=o));let l,u,h,z=[],f={},n=null,i;async function p(o,_){if(!o||!_)return;const b=await a.get(o.name,_);try{const{data:[J]}=await a.decrypt(o.name,[b.data]);f=J}catch{console.warn("[decrypt] Not permitted"),f=b.data}return n=n===null?Object.freeze(W(f)):n,v(f)}async function g(o,_){if(!o||!_)return;const b=await a.events(o.name,_);e(3,z=b.data.reverse())}function v(o){e(1,u=JSON.stringify(o,null,2))}async function S(o){console.log("Saving...",o);try{e(2,h=null);const _=JSON.parse(o),b=pe(m.sanitize(n),m.sanitize(_));if(b.length===0)return;const{newDocument:J}=me({},b),te=_e(J,"created_at","updated_at","version"),A=await a.update(l.name,t,te);try{const{data:[B]}=await a.decrypt(l.name,[A.data]);f=B}catch{console.warn("[decrypt] Not permitted"),f=A.data}n=Object.freeze(W(f)),v(f),g(l,t)}catch(_){e(2,h=_)}}function Z(o){U[o?"unshift":"push"](()=>{i=o,e(4,i)})}function x(o){u=o,e(1,u)}const ee=()=>S(u);return r.$$.update=()=>{r.$$.dirty&1536&&e(0,l=y[c.params.model]),r.$$.dirty&512&&e(8,t=c.params.correlation_id),r.$$.dirty&257&&p(l,t),r.$$.dirty&257&&g(l,t)},[l,u,h,z,i,d,j,S,t,c,y,Z,x,ee]}class Ve extends ne{constructor(s){super();oe(this,s,ye,ve,ie,{})}}export{Ve as default};
