import{a as e,n as t,o as n}from"./BzbovP_B.js";import{t as r}from"./BdOa7B91.js";import{$n as i,Cn as a,M as o,a as s,j as c,tr as l}from"./DLvf9lie.js";var u=s(`outline`,`edit`,`Edit`,[[`path`,{d:`M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1`,key:`svg-0`}],[`path`,{d:`M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415`,key:`svg-1`}],[`path`,{d:`M16 5l3 3`,key:`svg-2`}]]),d=s(`outline`,`external-link`,`ExternalLink`,[[`path`,{d:`M12 6h-6a2 2 0 0 0 -2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-6`,key:`svg-0`}],[`path`,{d:`M11 13l9 -9`,key:`svg-1`}],[`path`,{d:`M15 4h5v5`,key:`svg-2`}]]);function f(e){return Array.isArray(e)?e.map(e=>f(e)):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,f(t)])):e}function p(e){if(!e||typeof e!=`object`)return!1;let t=e,n=t.response;if(n&&typeof n==`object`&&n.status===409)return!0;let r=t.data;return!!r&&typeof r==`object`&&(r.statusCode===409||r.status===409)}function m(){let s=o(),{hasFeature:u}=c(),d=a(()=>u(`visual-config-editor`)),m=l(null),h=l(null),g=i(!1),_=i(!1),v=i(``),y=a(()=>h.value?.data??null),b=a(()=>h.value?.diagnostics??[]);return{available:d,snapshot:m,data:y,diagnostics:b,hasErrors:a(()=>b.value.some(e=>e.severity===`error`)),conflicted:a(()=>!!m.value?.conflicts.length),dirty:a(()=>!m.value||!h.value?!1:t(m.value.editableYaml,h.value).operations.length>0),loading:g,saving:_,errorMessage:v,fullEditorPath:a(()=>m.value?`/profiles/${m.value.profile.id}/edit`:`/profiles`),load:async()=>{if(!d.value)return`unavailable`;g.value=!0,v.value=``,m.value=null,h.value=null;try{let t=(await s.listProfiles()).find(e=>e.active&&e.type!==`merge`&&e.type!==`script`);if(!t)return`no-active-profile`;let n=await s.getProfileEditor(t.id);return m.value=n,h.value=e(n.editableYaml),n.conflicts.length?`conflict`:`ready`}catch(e){return v.value=r(e),`error`}finally{g.value=!1}},replaceSections:e=>{if(!h.value)return;let t={...h.value.data};for(let[n,r]of Object.entries(e))r===void 0?delete t[n]:t[n]=f(r);h.value=n(h.value,t)},save:async()=>{let e=m.value,n=h.value;if(!e||!n)return`error`;if(e.conflicts.length)return`conflict`;if(n.diagnostics.some(e=>e.severity===`error`))return`invalid`;let i=t(e.editableYaml,n);if(!i.operations.length)return`unchanged`;_.value=!0,v.value=``;try{return await s.applyProfileEditor(e.profile.id,i),`saved`}catch(e){return v.value=r(e),p(e)?`conflict`:`error`}finally{_.value=!1}}}}export{d as n,u as r,m as t};