var oe=Object.defineProperty;var A=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,ie=Object.prototype.propertyIsEnumerable;var F=(s,a,e)=>a in s?oe(s,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[a]=e,C=(s,a)=>{for(var e in a||(a={}))ne.call(a,e)&&F(s,e,a[e]);if(A)for(var e of A(a))ie.call(a,e)&&F(s,e,a[e]);return s};import{S as le,i as ce,s as ue,e as N,w as q,k as G,c as $,a as O,x as P,d as w,m as H,b as z,f as R,g as Z,M as S,y as B,W as de,q as V,o as I,B as M,l as K,p as fe,P as Q,Q as W,X as x,Y as pe,n as me}from"../../../../chunks/index-e2bb409a.js";import{c as _e,a as ge}from"../../../../chunks/index-0b0fc960.js";import{c as L}from"../../../../chunks/cloneDeep-38b1d6f5.js";import{g as he}from"../../../../chunks/get-102ab8d2.js";import{o as ve}from"../../../../chunks/omit-2d34bd5f.js";import{s as ye}from"../../../../chunks/set-97c39334.js";import{p as be}from"../../../../chunks/stores-9025718b.js";import{E as T,a as we}from"../../../../chunks/error-06511b87.js";import"../../../../chunks/_baseGet-42226e95.js";import"../../../../chunks/_isIndex-e69b0e86.js";import"../../../../chunks/preload-helper-60cab3ee.js";function U(s){let a,e,t,r,l,b,p,d,E,c,u,g;function J(o){s[12](o)}let f={language:"json",schema:C({type:"object"},s[0].schema.model)};return s[1]!==void 0&&(f.value=s[1]),r=new T({props:f}),s[11](r),x.push(()=>pe(r,"value",J)),r.$on("save",s[13]),d=new we({props:{error:s[2]}}),u=new T({props:{language:"json",fontSize:"10px",isReadonly:!0,value:JSON.stringify(s[3],null,2)}}),{c(){a=N("div"),e=N("div"),t=N("div"),q(r.$$.fragment),b=G(),p=N("div"),q(d.$$.fragment),E=G(),c=N("div"),q(u.$$.fragment),this.h()},l(o){a=$(o,"DIV",{class:!0,style:!0});var i=O(a);e=$(i,"DIV",{class:!0,style:!0});var m=O(e);t=$(m,"DIV",{class:!0});var h=O(t);P(r.$$.fragment,h),h.forEach(w),b=H(m),p=$(m,"DIV",{class:!0,style:!0});var v=O(p);P(d.$$.fragment,v),v.forEach(w),m.forEach(w),E=H(i),c=$(i,"DIV",{class:!0});var j=O(c);P(u.$$.fragment,j),j.forEach(w),i.forEach(w),this.h()},h(){z(t,"class","w-full h-4/6"),z(p,"class","w-full h-2/6 border-t-2"),R(p,"border-color","#171812"),z(e,"class","w-8/12 border-r-2"),R(e,"border-color","#171812"),z(c,"class","w-4/12"),z(a,"class","flex flex-column h-screen"),R(a,"background-color","#272822")},m(o,i){Z(o,a,i),S(a,e),S(e,t),B(r,t,null),S(e,b),S(e,p),B(d,p,null),S(a,E),S(a,c),B(u,c,null),g=!0},p(o,i){const m={};i&1&&(m.schema=C({type:"object"},o[0].schema.model)),!l&&i&2&&(l=!0,m.value=o[1],de(()=>l=!1)),r.$set(m);const h={};i&4&&(h.error=o[2]),d.$set(h);const v={};i&8&&(v.value=JSON.stringify(o[3],null,2)),u.$set(v)},i(o){g||(V(r.$$.fragment,o),V(d.$$.fragment,o),V(u.$$.fragment,o),g=!0)},o(o){I(r.$$.fragment,o),I(d.$$.fragment,o),I(u.$$.fragment,o),g=!1},d(o){o&&w(a),s[11](null),M(r),M(d),M(u)}}}function Ee(s){let a,e,t=!!s[0]&&U(s);return{c(){t&&t.c(),a=K()},l(r){t&&t.l(r),a=K()},m(r,l){t&&t.m(r,l),Z(r,a,l),e=!0},p(r,[l]){r[0]?t?(t.p(r,l),l&1&&V(t,1)):(t=U(r),t.c(),V(t,1),t.m(a.parentNode,a)):t&&(me(),I(t,1,1,()=>{t=null}),fe())},i(r){e||(V(t),e=!0)},o(r){I(t),e=!1},d(r){t&&t.d(r),r&&w(a)}}}function ke(s,a,e){let t,r,l,b;Q(s,be,n=>e(9,l=n));const p=W("services"),d=W("stores").models;Q(s,d,n=>e(10,b=n));const E=W("stores").activeClient;Q(s,E,n=>e(16,r=n));let c,u,g,J=[],f={},o=null,i;async function m(n,_){if(!n||!_)return;const y=await r.get(n.name,_);try{const{data:[D]}=await r.decrypt(n.name,[y.data]);f=D}catch{console.warn("[decrypt] Not permitted"),f=y.data}return o=o===null?Object.freeze(L(f)):o,v(f)}async function h(n,_){if(!n||!_)return;const y=await r.events(n.name,_);e(3,J=y.data.reverse())}function v(n){e(1,u=JSON.stringify(n,null,2))}async function j(n){console.log("Saving...",n);try{e(2,g=null);const _=JSON.parse(n),y=_e(p.sanitize(o),p.sanitize(_));if(y.length===0)return;const D={};y.filter(k=>["add","remove","replace"].includes(k.op)).forEach(k=>{const Y=k.path.slice(1).replace(/\/.*/,"");ye(D,Y,he(o,Y))});const{newDocument:ae}=ge(D,y),se=ve(ae,"created_at","updated_at","version"),X=await r.update(c.name,t,se);try{const{data:[k]}=await r.decrypt(c.name,[X.data]);f=k}catch{console.warn("[decrypt] Not permitted"),f=X.data}o=Object.freeze(L(f)),v(f),h(c,t)}catch(_){console.error(_),e(2,g=_)}}function ee(n){x[n?"unshift":"push"](()=>{i=n,e(4,i)})}function te(n){u=n,e(1,u)}const re=()=>j(u);return s.$$.update=()=>{s.$$.dirty&1536&&e(0,c=b[l.params.model]),s.$$.dirty&512&&e(8,t=l.params.correlation_id),s.$$.dirty&257&&m(c,t),s.$$.dirty&257&&h(c,t)},[c,u,g,J,i,d,E,j,t,l,b,ee,te,re]}class Pe extends le{constructor(a){super(),ce(this,a,ke,Ee,ue,{})}}export{Pe as default};
