const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["../chunks/DLQqXQ6R.js","../chunks/C1FmrZbK.js","../assets/editor.BMIWPGx3.css"])))=>i.map(i=>d[i]);
import{_ as ie}from"../chunks/C1FmrZbK.js";import"../chunks/CWj6FrbW.js";import{o as le,b as ne,s as D}from"../chunks/CB3MYTwM.js";import{p as ce,k as ve,h as e,i as v,c as de,l as a,f as d,a as H,s as P,d as g,r as _,b as i,q as ue,t as I}from"../chunks/BRMnbBOX.js";import{i as h}from"../chunks/BFchB-2I.js";import{b as fe}from"../chunks/CmatTLDp.js";import{g as me,P as pe}from"../chunks/Bk5z628g.js";import{e as ge,a as _e}from"../chunks/CxPv-oiS.js";import{t as W}from"../chunks/BEJ5fU19.js";var he=d("<span>Saving…</span>"),xe=d("<span>Saved</span>"),ye=d('<div class="text-rc-gray-400">Loading…</div>'),be=d('<div class="text-rc-red-500"> </div>'),Ce=d('<div class="text-rc-red-500 mb-2 text-xs"> </div>'),Ee=d('<div class="text-rc-red-500 mb-2 text-xs"> </div>'),Se=d('<!> <!> <div class="min-h-0 flex-1"></div>',1),ke=d('<div class="flex flex-none items-center justify-between gap-3 pb-2"><div class="min-w-0"><div class="truncate font-semibold text-rc-gray-100">Region config</div> <div class="truncate text-xs text-rc-gray-400">Edits `region-config.json` in the project</div></div> <div class="flex items-center gap-3 text-xs text-rc-gray-400"><!></div></div> <!>',1);function De(q,z){ce(z,!0);const{actions:F}=me();let s=v(null),w,A=null,j=[],T=null,B=!1,x=v(""),M=v(""),N=v(!0),y=v(null),b=v(null),C=v(!1),p=v(null),E=null;const R=800;function O(){E&&(clearTimeout(E),E=null)}function Q(t){O(),E=setTimeout(()=>{U(t)},R)}async function U(t){if(!e(C)&&t!==e(M)){try{JSON.parse(t)}catch{return}a(C,!0),a(p,null);try{await W.regionConfig.save.mutate({text:t}),a(M,t,!0),F.sendAppEvent({type:"reload-project"})}catch(l){console.error(l),a(p,"Failed to save region config")}finally{a(C,!1)}}}le(async()=>{try{ge();const t=await ie(()=>import("../chunks/DLQqXQ6R.js").then(n=>n.e),__vite__mapDeps([0,1,2]),import.meta.url);if(B)return;T=t,_e(t),a(N,!0),a(y,null);const l=await W.regionConfig.get.query();if(B)return;a(x,l,!0),a(M,l,!0),a(s,t.editor.create(w,{value:l,language:"json",theme:"bosun-dark",automaticLayout:!0,lineNumbers:"on",minimap:{enabled:!1},wordWrap:"on",matchBrackets:"never",bracketPairColorization:{enabled:!1},guides:{highlightActiveBracketPair:!1,bracketPairs:!1,bracketPairsHorizontal:!1},occurrencesHighlight:"off",selectionHighlight:!1,unicodeHighlight:{ambiguousCharacters:!1,nonBasicASCII:!1,invisibleCharacters:!1,includeStrings:!1,includeComments:!1},autoClosingQuotes:"never",padding:{top:12}}),!0),A=e(s).getModel(),j.push(e(s).onDidChangeModelContent(()=>{if(!e(s))return;const n=e(s).getValue();a(x,n,!0),a(p,null);try{JSON.parse(n),a(b,null),Q(n)}catch{O(),a(b,"Invalid JSON")}}))}catch(t){console.error(t),a(y,"Failed to load region config")}finally{a(N,!1)}}),ne(()=>{B=!0,O();for(const l of j)try{l.dispose()}catch{}j=[];const t=A;A=null;try{if(e(s)){try{e(s).setModel(null)}catch{}e(s).dispose()}}finally{a(s,null)}try{t==null||t.dispose()}catch{}T=null}),ve(()=>{e(s)&&e(x)!==e(s).getValue()&&e(s).setValue(e(x))}),pe(q,{class:"flex h-full min-h-0 flex-col !rounded-none p-2",children:(t,l)=>{var n=ke(),S=H(n),J=P(g(S),2),G=g(J);{var K=r=>{var c=he();i(r,c)},X=r=>{var c=xe();i(r,c)};h(G,r=>{e(C)?r(K):r(X,!1)})}_(J),_(S);var Y=P(S,2);{var Z=r=>{var c=ye();i(r,c)},$=r=>{var c=ue(),ee=H(c);{var te=f=>{var m=be(),k=g(m,!0);_(m),I(()=>D(k,e(y))),i(f,m)},ae=f=>{var m=Se(),k=H(m);{var re=o=>{var u=Ce(),V=g(u,!0);_(u),I(()=>D(V,e(b))),i(o,u)};h(k,o=>{e(b)&&o(re)})}var L=P(k,2);{var se=o=>{var u=Ee(),V=g(u,!0);_(u),I(()=>D(V,e(p))),i(o,u)};h(L,o=>{e(p)&&o(se)})}var oe=P(L,2);fe(oe,o=>w=o,()=>w),i(f,m)};h(ee,f=>{e(y)?f(te):f(ae,!1)},!0)}i(r,c)};h(Y,r=>{e(N)?r(Z):r($,!1)})}i(t,n)}}),de()}export{De as component};
