import{d as Ct,a as g,s as _,f as x,e as tt}from"../chunks/BqgPKE-B.js";import"../chunks/zzPCSqzL.js";import{o as wt}from"../chunks/C4QyggyU.js";import{B as zt,f as B,t as w,D as kt,F as s,G as h,I as t,J as e,K as i,L as E,M as at,O as yt}from"../chunks/6mnWt3YZ.js";import{i as z,a as Mt,b as $t}from"../chunks/BJ0MJm0w.js";import{t as Ft,e as Lt,i as Et}from"../chunks/BfTcz1DI.js";import{c as Pt,a as D,b as H,d as N,i as St}from"../chunks/CIjYD0We.js";import{s as Ot}from"../chunks/DTfXqUUs.js";import{L as et,M as Tt}from"../chunks/BA0YBOgD.js";import{M as jt}from"../chunks/DVkXtby2.js";import{F as Bt}from"../chunks/D9CiKqJ1.js";import{T as Q}from"../chunks/DJFqYGin.js";import{P as Dt}from"../chunks/BClmvUCF.js";import{C as R}from"../chunks/DC0jHa5L.js";import{C as Gt}from"../chunks/Bm9mODJJ.js";var It=x('<div class="alert alert-warn"><!> </div>'),Jt=x('<div class="loading-text"><!> </div>'),Kt=x('<div class="alert alert-warn"><!> </div> <div class="instructions"><h4> </h4> <ol><li> </li> <li> </li> <li> </li></ol></div>',1),qt=x('<div class="btn-group"><button class="btn btn-primary"><!> </button> <button class="btn"><!> </button></div>'),At=x('<div class="alert alert-success"><!> </div>'),Ht=x('<div class="alert alert-warn"><!> </div>'),Nt=x("<li><!> </li>"),Qt=x('<!> <ul class="check-list"></ul>',1),Rt=x("<!> <!> <!> <!>",1),Ut=x('<div class="main-header"><h2><!> </h2> <p> </p></div> <!>',1);function Vt(G,rt){zt(rt,!0);const o=()=>$t(Ft,"$t",st),[st,it]=Mt();let M=E(null),$=E(null),P=E(!1),S=E(""),O=E(!1);wt(()=>{U()});async function U(){try{h(M,await Pt("constitution",()=>D.getConstitution()),!0)}catch(a){h(S,a.message,!0),H(a.message,"constitution")}}async function ot(){h(P,!0),h($,null),N(o()("log.validating"));try{h($,await D.validateConstitution(),!0),N(i($).valid?o()("log.validation_passed"):o()("log.validation_issues"))}catch(a){H(a.message,"validateConstitution"),h(S,a.message,!0)}h(P,!1)}async function nt(a){try{await D.saveConstitution(a),St("constitution","status"),Ot.set(await D.getStatus()),await U(),N(o()("editor.doc_saved")),h(O,!1)}catch(v){throw H(v.message,"constitutionSave"),v}}var V=Ut(),I=B(V),J=s(I),W=s(J);Bt(W,{size:24});var vt=t(W);e(J);var X=t(J,2),lt=s(X,!0);e(X),e(I);var ct=t(I,2);{var dt=a=>{var v=It(),C=s(v);Q(C,{size:14});var F=t(C);e(v),w(()=>_(F,` ${i(S)??""}`)),g(a,v)},_t=a=>{var v=Jt(),C=s(v);et(C,{size:14,class:"spin"});var F=t(C);e(v),w(K=>_(F,` ${K??""}`),[()=>o()("app.loading")]),g(a,v)},ut=a=>{var v=Rt(),C=B(v);{var F=r=>{var f=Kt(),u=B(f),k=s(u);Q(k,{size:14});var L=t(k);e(u);var y=t(u,2),c=s(y),l=s(c,!0);e(c);var d=t(c,2),m=s(d),n=s(m,!0);e(m);var b=t(m,2),T=s(b,!0);e(b);var j=t(b,2),q=s(j,!0);e(j),e(d),e(y),w((A,p,ht,xt,bt)=>{_(L,` ${A??""}`),_(l,p),_(n,ht),_(T,xt),_(q,bt)},[()=>o()("const.empty"),()=>o()("const.next_steps"),()=>o()("const.step1",{file:".skaro/constitution.md"}),()=>o()("const.step2"),()=>o()("const.step3")]),g(r,f)},K=r=>{var f=qt(),u=s(f),k=s(u);{var L=n=>{et(n,{size:14,class:"spin"})},y=n=>{R(n,{size:14})};z(k,n=>{i(P)?n(L):n(y,!1)})}var c=t(k);e(u);var l=t(u,2),d=s(l);Dt(d,{size:14});var m=t(d);e(l),e(f),w((n,b)=>{u.disabled=i(P),_(c,` ${n??""}`),_(m,` ${b??""}`)},[()=>o()("const.validate"),()=>o()("editor.edit")]),tt("click",u,ot),tt("click",l,()=>h(O,!0)),g(r,f)};z(C,r=>{i(M).has_constitution?r(K,!1):r(F)})}var Y=t(C,2);{var ft=r=>{var f=Qt(),u=B(f);{var k=c=>{var l=At(),d=s(l);R(d,{size:14});var m=t(d);e(l),w(n=>_(m,` ${n??""}`),[()=>o()("const.valid")]),g(c,l)},L=c=>{var l=Ht(),d=s(l);Q(d,{size:14});var m=t(d);e(l),w(n=>_(m,` ${n??""}`),[()=>o()("const.invalid")]),g(c,l)};z(u,c=>{i($).valid?c(k):c(L,!1)})}var y=t(u,2);Lt(y,21,()=>Object.entries(i($).checks),Et,(c,l)=>{var d=at(()=>yt(i(l),2));let m=()=>i(d)[0],n=()=>i(d)[1];var b=Nt(),T=s(b);{var j=p=>{R(p,{size:14,color:"var(--gn-bright)"})},q=p=>{Gt(p,{size:14,color:"var(--rd)"})};z(T,p=>{n()?p(j):p(q,!1)})}var A=t(T);e(b),w(p=>_(A,` ${p??""}`),[()=>m().replace(/_/g," ")]),g(c,b)}),e(y),g(r,f)};z(Y,r=>{i($)&&r(ft)})}var Z=t(Y,2);{var mt=r=>{Tt(r,{get content(){return i(M).content}})};z(Z,r=>{i(M).content&&r(mt)})}var pt=t(Z,2);{var gt=r=>{{let f=at(()=>i(M).content||"");jt(r,{get content(){return i(f)},onSave:nt,onClose:()=>h(O,!1)})}};z(pt,r=>{i(O)&&r(gt)})}g(a,v)};z(ct,a=>{i(S)?a(dt):i(M)?a(ut,!1):a(_t,1)})}w((a,v)=>{_(vt,` ${a??""}`),_(lt,v)},[()=>o()("const.title"),()=>o()("const.subtitle")]),g(G,V),kt(),it()}Ct(["click"]);function da(G){Vt(G,{})}export{da as component};
