import{S as E,i as x,s as I,e as J,j as N,c as O,a as q,m as z,d as g,b as D,J as P,f as j,o as $,a2 as A,x as m,u as h,v as B,l as w,w as F,O as v,P as b,a0 as G,a1 as H,r as K,$ as L}from"../../../chunks/vendor-f44913f5.js";import{p as Q}from"../../../chunks/stores-79a3d42c.js";import{E as R}from"../../../chunks/editor-9793cec3.js";import"../../../chunks/preload-helper-ec9aa979.js";function M(r){let o,s,e,t;function i(a){r[6](a)}let c={language:"json"};return r[0]!==void 0&&(c.value=r[0]),s=new R({props:c}),G.push(()=>H(s,"value",i)),{c(){o=J("div"),N(s.$$.fragment),this.h()},l(a){o=O(a,"DIV",{class:!0,style:!0});var l=q(o);z(s.$$.fragment,l),l.forEach(g),this.h()},h(){D(o,"class","flex flex-row h-screen"),P(o,"background-color","#272822")},m(a,l){j(a,o,l),$(s,o,null),t=!0},p(a,l){const d={};!e&&l&1&&(e=!0,d.value=a[0],A(()=>e=!1)),s.$set(d)},i(a){t||(m(s.$$.fragment,a),t=!0)},o(a){h(s.$$.fragment,a),t=!1},d(a){a&&g(o),B(s)}}}function T(r){let o,s,e=r[1]&&M(r);return{c(){e&&e.c(),o=w()},l(t){e&&e.l(t),o=w()},m(t,i){e&&e.m(t,i),j(t,o,i),s=!0},p(t,[i]){t[1]?e?(e.p(t,i),i&2&&m(e,1)):(e=M(t),e.c(),m(e,1),e.m(o.parentNode,o)):e&&(K(),h(e,1,1,()=>{e=null}),F())},i(t){s||(m(e),s=!0)},o(t){h(e),s=!1},d(t){e&&e.d(t),t&&g(o)}}}function U(r,o,s){let e,t,i;v(r,Q,n=>s(4,e=n));const c=b("stores").models;v(r,c,n=>s(5,t=n));const a=b("stores").activeClient;v(r,a,n=>s(9,i=n));const l=b("services");let d,u,k,p;async function S(n){!n||y(n)}function y(n){s(0,u=JSON.stringify(n,null,2)),d=u}async function V(n){console.log("Saving...",n);try{if(n===d)return;k=null;const f=l.sanitize(l.parse(n)),{data:_}=await i.updateModel(f);console.log("Model updated",{model:_}),await i.createModelIndexes(f),L(c,t[e.params.model]=_,t),y(_)}catch(f){k=f}}function C(n){u=n,s(0,u)}return r.$$.update=()=>{r.$$.dirty&48&&s(1,p=t[e.params.model]),r.$$.dirty&1&&V(u),r.$$.dirty&2&&S(p)},[u,p,c,a,e,t,C]}class ee extends E{constructor(o){super();x(this,o,U,T,I,{})}}export{ee as default};
