import{$ as e,A as t,B as n,E as r,G as i,I as a,L as o,N as s,Q as c,R as l,W as u,X as d,Z as f,c as p,ct as m,d as h,dt as g,f as _,ft as v,it as y,j as b,k as x,nt as S,r as C,st as w,tt as T,u as E,x as D,y as O}from"../chunks/BBI__kVO.js";import"../chunks/xihTtKlq.js";import{_ as k,y as A,yt as j}from"../chunks/i-u-oQAW.js";import{a as M,t as N}from"../chunks/DMSxHu0j.js";var P=s(`<div class="alert error svelte-m7qpzt" role="alert"> </div>`),F=s(`<span class="badge default svelte-m7qpzt">Default</span>`),ee=s(`<span class="badge active svelte-m7qpzt">Active</span>`),te=s(`<span class="badge password svelte-m7qpzt" title="Server password configured">🔒</span>`),ne=s(`<button type="button" class="btn btn-primary btn-sm">Use this</button>`),re=s(`<button type="button" class="btn btn-secondary btn-sm">Edit</button> <button type="button" class="btn btn-danger btn-sm svelte-m7qpzt"> </button>`,1),ie=s(`<article><div class="endpoint-main svelte-m7qpzt"><div class="endpoint-title svelte-m7qpzt"><span class="endpoint-label svelte-m7qpzt"> </span> <!> <!> <!></div> <div class="endpoint-url svelte-m7qpzt"> </div></div> <div class="endpoint-actions svelte-m7qpzt"><!> <!></div></article>`),I=s(`<button type="button" class="btn btn-primary">+ Add endpoint</button>`),L=s(`<small class="rotate-hint svelte-m7qpzt"><strong class="svelte-m7qpzt">Rotating this password?</strong> OpenCode reads <code class="svelte-m7qpzt">OPENCODE_SERVER_PASSWORD</code> from its env at startup, so
              rotation is a two-step process: <ol class="svelte-m7qpzt"><li>On the remote host: update <code class="svelte-m7qpzt">OP_OPENCODE_PASSWORD</code> in <code class="svelte-m7qpzt">stack.env</code> and restart the <code class="svelte-m7qpzt">assistant</code> container.</li> <li>Paste the new value here and save.</li></ol></small>`),ae=s(`<label class="field-inline svelte-m7qpzt"><input type="checkbox"/> <span>Clear stored password</span></label>`),oe=s(`<div class="alert error svelte-m7qpzt" role="alert"> </div>`),se=s(`<form class="endpoint-form svelte-m7qpzt"><h2 class="svelte-m7qpzt"> </h2> <label class="field svelte-m7qpzt"><span class="svelte-m7qpzt">Label</span> <input type="text" placeholder="e.g. Home server" required="" autocomplete="off" class="svelte-m7qpzt"/></label> <label class="field svelte-m7qpzt"><span class="svelte-m7qpzt">URL</span> <input type="url" placeholder="http://10.0.0.5:3800" required="" autocomplete="off" class="svelte-m7qpzt"/> <small class="svelte-m7qpzt">The host:port where the remote OpenPalm assistant (OpenCode) is reachable.</small></label> <label class="field svelte-m7qpzt"><span class="svelte-m7qpzt">Server password (optional)</span> <input type="password" autocomplete="new-password" class="svelte-m7qpzt"/> <small class="svelte-m7qpzt">Forwarded as HTTP Basic auth. Only required if the remote OpenCode was started with <code class="svelte-m7qpzt">OPENCODE_SERVER_PASSWORD</code>.</small> <!></label> <!> <!> <div class="form-actions svelte-m7qpzt"><button type="submit" class="btn btn-primary"> </button> <button type="button" class="btn btn-secondary">Cancel</button></div></form>`),ce=s(`<!> <main class="page svelte-m7qpzt"><header class="page-header svelte-m7qpzt"><h1 class="svelte-m7qpzt">Assistant Endpoints</h1> <p class="lede svelte-m7qpzt">Connect to local or remote OpenPalm assistants. The <strong>Default</strong> entry comes
        from the environment (set by the launcher) and cannot be deleted. Add more endpoints to
        switch between stacks at any time.</p></header> <!> <section class="endpoints-list svelte-m7qpzt" aria-label="Configured endpoints"></section> <!></main>`,1);function R(a,s){m(s,!0);let R=S(`idle`),z=S(null),B=S(``),V=S(``),H=S(``),U=S(!1),W=S(!1),G=S(``),K=S(null),le=y(()=>M.endpoints),q=y(()=>M.active);C(()=>{M.load(!0)});function ue(){T(R,`add`),T(z,null),T(B,``),T(V,``),T(H,``),T(U,!1),T(G,``)}function de(e){T(R,`edit`),T(z,e.id,!0),T(B,e.label,!0),T(V,e.url,!0),T(H,``),T(U,!1),T(G,``)}function fe(){T(R,`idle`),T(G,``)}async function pe(e){if(e.preventDefault(),n(W))return;let t=n(B).trim(),r=n(V).trim();if(!t||!r){T(G,`Label and URL are required.`);return}T(W,!0),T(G,``);try{if(n(R)===`add`)await k({label:t,url:r,...n(H)?{password:n(H)}:{}});else if(n(R)===`edit`&&n(z)){let e={label:t,url:r};n(U)?e.password=null:n(H)&&(e.password=n(H)),await j(n(z),e)}await M.load(!0),T(R,`idle`)}catch(e){T(G,e.message??`Save failed.`,!0)}finally{T(W,!1)}}async function me(e){try{await M.activate(e)}catch{}}async function he(e){if(!e.isDefault&&confirm(`Remove endpoint "${e.label}"?`)){T(K,e.id,!0);try{await A(e.id),await M.load(!0)}catch(e){M.error=e.message??`Delete failed.`}finally{T(K,null)}}}var J=ce();D(`m7qpzt`,e=>{u(()=>{d.title=`Assistant Endpoints — OpenPalm`})});var Y=c(J);N(Y,{});var X=e(Y,2),Z=e(f(X),2),ge=e=>{var n=P(),r=f(n,!0);v(n),i(()=>t(r,M.error)),b(e,n)};x(Z,e=>{M.error&&e(ge)});var Q=e(Z,2);r(Q,21,()=>n(le),e=>e.id,(r,a)=>{var s=ie();let l;var u=f(s),d=f(u),p=f(d),m=f(p,!0);v(p);var h=e(p,2),g=e=>{b(e,F())};x(h,e=>{n(a).isDefault&&e(g)});var _=e(h,2),y=e=>{b(e,ee())};x(_,e=>{n(a).id===n(q)?.id&&e(y)});var S=e(_,2),C=e=>{b(e,te())};x(S,e=>{n(a).hasPassword&&e(C)}),v(d);var w=e(d,2),T=f(w,!0);v(w),v(u);var E=e(u,2),D=f(E),k=e=>{var t=ne();o(`click`,t,()=>me(n(a).id)),b(e,t)};x(D,e=>{n(a).id!==n(q)?.id&&e(k)});var A=e(D,2),j=r=>{var s=re(),l=c(s),u=e(l,2),d=f(u,!0);v(u),i(()=>{u.disabled=n(K)===n(a).id,t(d,n(K)===n(a).id?`Removing…`:`Remove`)}),o(`click`,l,()=>de(n(a))),o(`click`,u,()=>he(n(a))),b(r,s)};x(A,e=>{n(a).isDefault||e(j)}),v(E),v(s),i(()=>{l=O(s,1,`endpoint-card svelte-m7qpzt`,null,l,{active:n(a).id===n(q)?.id}),t(m,n(a).label),t(T,n(a).url)}),b(r,s)}),v(Q);var $=e(Q,2),_e=e=>{var t=I();o(`click`,t,ue),b(e,t)},ve=r=>{var a=se(),s=f(a),c=f(s,!0);v(s);var u=e(s,2),d=e(f(u),2);h(d),v(u);var m=e(u,2),y=e(f(m),2);h(y),g(2),v(m);var S=e(m,2),C=e(f(S),2);h(C);var w=e(C,4),D=e=>{b(e,L())};x(w,e=>{n(R)===`edit`&&e(D)}),v(S);var O=e(S,2),k=e=>{var t=ae(),r=f(t);h(r),g(2),v(t),p(r,()=>n(U),e=>T(U,e)),b(e,t)};x(O,e=>{n(R)===`edit`&&e(k)});var A=e(O,2),j=e=>{var r=oe(),a=f(r,!0);v(r),i(()=>t(a,n(G))),b(e,r)};x(A,e=>{n(G)&&e(j)});var M=e(A,2),N=f(M),P=f(N,!0);v(N);var F=e(N,2);v(M),v(a),i(()=>{t(c,n(R)===`add`?`Add endpoint`:`Edit endpoint`),_(C,`placeholder`,n(R)===`edit`?`Leave blank to keep current`:``),N.disabled=n(W),t(P,n(W)?`Saving…`:`Save`),F.disabled=n(W)}),l(`submit`,a,pe),E(d,()=>n(B),e=>T(B,e)),E(y,()=>n(V),e=>T(V,e)),E(C,()=>n(H),e=>T(H,e)),o(`click`,F,fe),b(r,a)};x($,e=>{n(R)===`idle`?e(_e):e(ve,-1)}),v(X),b(a,J),w()}a([`click`]);export{R as component};