import"../chunks/DsnmJJEf.js";import{i as Fe}from"../chunks/zNh6Oe5P.js";import{f as h,k as a,j as r,r as t,t as D,v as S,c as m,B as He,b as ze,p as Oe,E as vt,l as Le,s as v,m as I,g as e,a as Ne,C as ut,z as ve,n as _,u,d as Qe,e as Ge,o as mt,A as gt,h as bt,$ as pt,y as Q}from"../chunks/sWNKMed7.js";import{p as fe,i as z,s as ft,a as xt}from"../chunks/Ccl3fNd2.js";import{e as ht,w as Me,i as kt}from"../chunks/BuuPrWMc.js";import{s as xe,B as yt,r as Ue,g as Ke,d as P,c as ue}from"../chunks/D30EsFKH.js";import{e as _t,a as Ce}from"../chunks/DWynKlcl.js";import{b as Re}from"../chunks/CLagxtgo.js";import{p as wt}from"../chunks/D4Caz1gY.js";import{M as Mt}from"../chunks/C3KRf8YK.js";import{t as Je}from"../chunks/BZUCTtPY.js";import{e as Ut}from"../chunks/BZiHL9L3.js";var Ct=h('
'),Rt=h('
'),zt=h('
'),Lt=h('
'),St=h('
');function pe(me,V){let f=fe(V,"title",8),re=fe(V,"content",8),s=fe(V,"position",8,"top"),ae=fe(V,"width",8,"w-80");var l=St(),k=a(r(l),2),p=r(k),y=r(p,!0);t(p);var d=a(p,2),L=r(d,!0);t(d);var oe=a(d,2);{var ge=E=>{var q=Ct();m(E,q)},se=E=>{var q=He(),J=ze(q);{var F=j=>{var T=Rt();m(j,T)},K=j=>{var T=He(),ie=ze(T);{var le=$=>{var H=zt();m($,H)},ne=$=>{var H=He(),X=ze(H);{var de=i=>{var o=Lt();m(i,o)};z(X,i=>{s()==="right"&&i(de)},!0)}m($,H)};z(ie,$=>{s()==="left"?$(le):$(ne,!1)},!0)}m(j,T)};z(J,j=>{s()==="bottom"?j(F):j(K,!1)},!0)}m(E,q)};z(oe,E=>{s()==="top"?E(ge):E(se,!1)})}t(k),t(l),D(()=>{xe(k,1,`absolute ${s()==="top"?"bottom-full":s()==="bottom"?"top-full":s()==="left"?"right-full top-1/2 -translate-y-1/2":"left-full top-1/2 -translate-y-1/2"} left-1/2 transform -translate-x-1/2 ${s()==="top"?"mb-2":s()==="bottom"?"mt-2":"mx-2"} ${ae()??""} p-3 bg-gray-900 text-white text-xs rounded-lg shadow-lg opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 z-50`),S(y,f()),S(L,re())}),m(me,l)}var jt=ut(' Settings',1),$t=h('
Metadata
'),Bt=h('
Callback
'),At=h('
Webhook
'),It=h('

No URLs configured

'),Et=h('
Controller Webhook URL

Use this URL in your GitHub organization/repository webhook settings

'),Ht=h('

Please enter a valid URL

'),Gt=h('

Please enter a valid URL

'),Pt=h('

Please enter a valid URL

'),qt=h('

Controller Settings

URL where runners can fetch metadata and setup information

URL where runners send status updates and lifecycle events

URL where GitHub/Gitea will send webhook events for job notifications

Time to wait before spinning up a runner for a new job (0 = immediate)

'),Tt=h('

Controller Information

Identity

Controller ID
Hostname
Job Age Backoff

Integration URLs

',1);function Dt(me,V){Oe(V,!1);const f=I(),re=I();let s=fe(V,"controllerInfo",12);const ae=vt();let l=I(!1),k=I(!1),p=I(""),y=I(""),d=I(""),L=I(null);function oe(){v(p,s().metadata_url||""),v(y,s().callback_url||""),v(d,s().webhook_url||""),v(L,s().minimum_job_age_backoff||null),v(l,!0)}async function ge(){try{v(k,!0);const n={};e(p).trim()&&(n.metadata_url=e(p).trim()),e(y).trim()&&(n.callback_url=e(y).trim()),e(d).trim()&&(n.webhook_url=e(d).trim()),e(L)!==null&&e(L)>=0&&(n.minimum_job_age_backoff=e(L));const c=await Ke.updateController(n);Je.success("Settings Updated","Controller settings have been updated successfully."),v(l,!1),s(c),ae("updated",c)}catch(n){Je.error("Update Failed",n instanceof Error?n.message:"Failed to update controller settings")}finally{v(k,!1)}}function se(){v(l,!1),v(p,""),v(y,""),v(d,""),v(L,null)}Le(()=>{},()=>{v(f,n=>{if(!n.trim())return!0;try{return new URL(n),!0}catch{return!1}})}),Le(()=>(e(f),e(p),e(y),e(d),e(L)),()=>{v(re,e(f)(e(p))&&e(f)(e(y))&&e(f)(e(d))&&(e(L)===null||e(L)>=0))}),Ne(),Fe();var E=Tt(),q=ze(E),J=r(q),F=r(J),K=r(F),j=a(r(K),2),T=a(r(j),2),ie=r(T),le=r(ie);t(ie),t(T),t(j),t(K);var ne=a(K,2);yt(ne,{variant:"secondary",size:"sm",$$events:{click:oe},children:(n,c)=>{var b=jt();ve(),m(n,b)},$$slots:{default:!0}}),t(F);var $=a(F,2),H=r($),X=r(H),de=a(r(X),2),i=r(de),o=a(r(i),2),w=r(o,!0);t(o),t(i);var M=a(i,2),x=a(r(M),2),U=r(x,!0);t(x),t(M);var A=a(M,2),W=r(A),Y=a(r(W),2),Z=r(Y);pe(Z,{title:"Job Age Backoff",content:"Time in seconds GARM waits after receiving a new job before spinning up a runner. This delay allows existing idle runners to pick up jobs first, preventing unnecessary runner creation. Set to 0 for immediate response."}),t(Y),t(W);var O=a(W,2),N=r(O);t(O),t(A),t(de),t(X),t(H);var ee=a(H,2),ce=r(ee),he=a(r(ce),2),ke=r(he);{var Se=n=>{var c=$t(),b=r(c),C=a(r(b),2),G=r(C);pe(G,{title:"Metadata URL",content:"URL where runners retrieve setup information and metadata. Runners must be able to connect to this URL during their initialization process. Usually accessible at /api/v1/metadata endpoint."}),t(C),t(b);var R=a(b,2),B=r(R,!0);t(R),t(c),D(()=>S(B,(_(s()),u(()=>s().metadata_url)))),m(n,c)};z(ke,n=>{_(s()),u(()=>s().metadata_url)&&n(Se)})}var Pe=a(ke,2);{var Xe=n=>{var c=Bt(),b=r(c),C=a(r(b),2),G=r(C);pe(G,{title:"Callback URL",content:"URL where runners send status updates and system information (OS version, runner agent ID, etc.) to the controller. Runners must be able to connect to this URL. Usually accessible at /api/v1/callbacks endpoint."}),t(C),t(b);var R=a(b,2),B=r(R,!0);t(R),t(c),D(()=>S(B,(_(s()),u(()=>s().callback_url)))),m(n,c)};z(Pe,n=>{_(s()),u(()=>s().callback_url)&&n(Xe)})}var qe=a(Pe,2);{var Ye=n=>{var c=At(),b=r(c),C=a(r(b),2),G=r(C);pe(G,{title:"Webhook Base URL",content:"Base URL for webhooks where GitHub sends job notifications. GARM needs to receive these webhooks to know when to create new runners for jobs. GitHub must be able to connect to this URL. Usually accessible at /webhooks endpoint."}),t(C),t(b);var R=a(b,2),B=r(R,!0);t(R),t(c),D(()=>S(B,(_(s()),u(()=>s().webhook_url)))),m(n,c)};z(qe,n=>{_(s()),u(()=>s().webhook_url)&&n(Ye)})}var Ze=a(qe,2);{var et=n=>{var c=It(),b=a(r(c),4);t(c),Ge("click",b,oe),m(n,c)};z(Ze,n=>{_(s()),u(()=>!s().metadata_url&&!s().callback_url&&!s().webhook_url)&&n(et)})}t(he),t(ce),t(ee),t($);var tt=a($,2);{var rt=n=>{var c=Et(),b=r(c),C=a(r(b),2),G=r(C);pe(G,{title:"Controller Webhook URL",content:"Unique webhook URL for this GARM controller. This is the preferred URL to use in GitHub webhook settings as it's controller-specific and allows multiple GARM controllers to work with the same repository. Automatically combines the webhook base URL with the controller ID."}),t(C),t(b);var R=a(b,2),B=r(R),be=a(r(B),2),ye=r(be),je=r(ye,!0);t(ye),ve(2),t(be),t(B),t(R),t(c),D(()=>S(je,(_(s()),u(()=>s().controller_webhook_url)))),m(n,c)};z(tt,n=>{_(s()),u(()=>s().controller_webhook_url)&&n(rt)})}t(J),t(q);var at=a(q,2);{var ot=n=>{Mt(n,{$$events:{close:se},children:(c,b)=>{var C=qt(),G=a(r(C),2),R=r(G),B=a(r(R),2);Ue(B);let be;var ye=a(B,2);{var je=g=>{var te=Ht();m(g,te)};z(ye,g=>{e(f),e(p),u(()=>!e(f)(e(p)))&&g(je)})}ve(2),t(R);var $e=a(R,2),_e=a(r($e),2);Ue(_e);let Te;var st=a(_e,2);{var it=g=>{var te=Gt();m(g,te)};z(st,g=>{e(f),e(y),u(()=>!e(f)(e(y)))&&g(it)})}ve(2),t($e);var Be=a($e,2),we=a(r(Be),2);Ue(we);let De;var lt=a(we,2);{var nt=g=>{var te=Pt();m(g,te)};z(lt,g=>{e(f),e(d),u(()=>!e(f)(e(d)))&&g(nt)})}ve(2),t(Be);var Ae=a(Be,2),Ve=a(r(Ae),2);Ue(Ve),ve(2),t(Ae);var We=a(Ae,2),Ie=r(We),Ee=a(Ie,2),dt=r(Ee,!0);t(Ee),t(We),t(G),t(C),D((g,te,ct)=>{be=xe(B,1,"block w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 bg-white dark:bg-gray-700 text-gray-900 dark:text-white sm:text-sm",null,be,g),Te=xe(_e,1,"block w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 bg-white dark:bg-gray-700 text-gray-900 dark:text-white sm:text-sm",null,Te,te),De=xe(we,1,"block w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 bg-white dark:bg-gray-700 text-gray-900 dark:text-white sm:text-sm",null,De,ct),Ie.disabled=e(k),Ee.disabled=!e(re)||e(k),S(dt,e(k)?"Saving...":"Save Changes")},[()=>({"border-red-300":!e(f)(e(p))}),()=>({"border-red-300":!e(f)(e(y))}),()=>({"border-red-300":!e(f)(e(d))})]),Re(B,()=>e(p),g=>v(p,g)),Re(_e,()=>e(y),g=>v(y,g)),Re(we,()=>e(d),g=>v(d,g)),Re(Ve,()=>e(L),g=>v(L,g)),Ge("click",Ie,se),Ge("submit",G,wt(ge)),m(c,C)},$$slots:{default:!0}})};z(at,n=>{e(l)&&n(ot)})}D(n=>{S(le,`v${n??""}`),S(w,(_(s()),u(()=>s().controller_id))),S(U,(_(s()),u(()=>s().hostname||"Unknown"))),S(N,`${_(s()),u(()=>s().minimum_job_age_backoff||30)??""}s`)},[()=>(_(s()),u(()=>s().version?.replace(/^v/,"")||"Unknown"))]),m(me,E),Qe()}var Vt=h('

Error loading dashboard

'),Wt=h('
'),Jt=h('

Dashboard

Welcome to GARM - GitHub Actions Runner Manager

');function or(me,V){Oe(V,!1);const[f,re]=ft(),s=()=>xt(_t,"$eagerCache",f),ae=I();let l=I({repositories:0,organizations:0,pools:0,instances:0}),k=I(null),p=I(""),y=[];function d(i,o,w=1e3){const M=parseInt(i.textContent||"0"),x=(o-M)/(w/16);let U=M;const A=()=>{if(U+=x,x>0&&U>=o||x<0&&U<=o){i.textContent=o.toString();return}i.textContent=Math.floor(U).toString(),requestAnimationFrame(A)};M!==o&&requestAnimationFrame(A)}mt(async()=>{try{const[x,U,A,W,Y]=await Promise.all([Ce.getRepositories(),Ce.getOrganizations(),Ce.getPools(),Ke.listInstances(),Ce.getControllerInfo()]);setTimeout(()=>{const Z=document.querySelector('[data-stat="repositories"]'),O=document.querySelector('[data-stat="organizations"]'),N=document.querySelector('[data-stat="pools"]'),ee=document.querySelector('[data-stat="instances"]');Z&&d(Z,x.length),O&&d(O,U.length),N&&d(N,A.length),ee&&d(ee,W.length)},100),v(l,{repositories:x.length,organizations:U.length,pools:A.length,instances:W.length}),Y&&v(k,Y)}catch(x){v(p,Ut(x)),console.error("Dashboard error:",x)}const i=Me.subscribeToEntity("repository",["create","delete"],L),o=Me.subscribeToEntity("organization",["create","delete"],oe),w=Me.subscribeToEntity("pool",["create","delete"],ge),M=Me.subscribeToEntity("instance",["create","delete"],se);y=[i,o,w,M]}),gt(()=>{y.forEach(i=>i())});function L(i){const o=document.querySelector('[data-stat="repositories"]');i.operation==="create"?(Q(l,e(l).repositories++),o&&d(o,e(l).repositories,500)):i.operation==="delete"&&(Q(l,e(l).repositories=Math.max(0,e(l).repositories-1)),o&&d(o,e(l).repositories,500))}function oe(i){const o=document.querySelector('[data-stat="organizations"]');i.operation==="create"?(Q(l,e(l).organizations++),o&&d(o,e(l).organizations,500)):i.operation==="delete"&&(Q(l,e(l).organizations=Math.max(0,e(l).organizations-1)),o&&d(o,e(l).organizations,500))}function ge(i){const o=document.querySelector('[data-stat="pools"]');i.operation==="create"?(Q(l,e(l).pools++),o&&d(o,e(l).pools,500)):i.operation==="delete"&&(Q(l,e(l).pools=Math.max(0,e(l).pools-1)),o&&d(o,e(l).pools,500))}function se(i){const o=document.querySelector('[data-stat="instances"]');i.operation==="create"?(Q(l,e(l).instances++),o&&d(o,e(l).instances,500)):i.operation==="delete"&&(Q(l,e(l).instances=Math.max(0,e(l).instances-1)),o&&d(o,e(l).instances,500))}function E(i){v(k,i.detail)}function q(i){return{blue:"bg-blue-500 text-white",green:"bg-green-500 text-white",purple:"bg-purple-500 text-white",yellow:"bg-yellow-500 text-white"}[i]||"bg-gray-500 text-white"}Le(()=>(e(k),s()),()=>{(!e(k)||s().loaded.controllerInfo)&&v(k,s().controllerInfo)}),Le(()=>(e(l),P),()=>{v(ae,[{title:"Repositories",value:e(l).repositories,icon:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z",color:"blue",href:P("/repositories")},{title:"Organizations",value:e(l).organizations,icon:"M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z",color:"green",href:P("/organizations")},{title:"Pools",value:e(l).pools,icon:"M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z",color:"purple",href:P("/pools")},{title:"Instances",value:e(l).instances,icon:"M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z",color:"yellow",href:P("/instances")}])}),Ne(),Fe();var J=Jt();bt(i=>{pt.title="Dashboard - GARM"});var F=a(r(J),2);{var K=i=>{var o=Vt(),w=r(o),M=a(r(w),2),x=a(r(M),2),U=r(x,!0);t(x),t(M),t(w),t(o),D(()=>S(U,e(p))),m(i,o)};z(F,i=>{e(p)&&i(K)})}var j=a(F,2);ht(j,5,()=>e(ae),kt,(i,o)=>{var w=Wt(),M=r(w),x=r(M),U=r(x),A=r(U),W=r(A),Y=r(W);t(W),t(A),t(U);var Z=a(U,2),O=r(Z),N=r(O),ee=r(N,!0);t(N);var ce=a(N,2),he=r(ce,!0);t(ce),t(O),t(Z),t(x),t(M),t(w),D((ke,Se)=>{ue(w,"href",(e(o),u(()=>e(o).href))),xe(A,1,`w-8 h-8 rounded-md ${ke??""} flex items-center justify-center`),ue(Y,"d",(e(o),u(()=>e(o).icon))),S(ee,(e(o),u(()=>e(o).title))),ue(ce,"data-stat",Se),S(he,(e(o),u(()=>e(o).value)))},[()=>(e(o),u(()=>q(e(o).color))),()=>(e(o),u(()=>e(o).title.toLowerCase()))]),m(i,w)}),t(j);var T=a(j,2);{var ie=i=>{Dt(i,{get controllerInfo(){return e(k)},$$events:{updated:E}})};z(T,i=>{e(k)&&i(ie)})}var le=a(T,2),ne=r(le),$=a(r(ne),4),H=r($),X=a(H,2),de=a(X,2);t($),t(ne),t(le),t(J),D((i,o,w)=>{ue(H,"href",i),ue(X,"href",o),ue(de,"href",w)},[()=>(_(P),u(()=>P("/repositories"))),()=>(_(P),u(()=>P("/pools"))),()=>(_(P),u(()=>P("/instances")))]),m(me,J),Qe(),re()}export{or as component};