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