import"../chunks/DsnmJJEf.js";import{i as hr}from"../chunks/zNh6Oe5P.js";import{p as xr,E as Hr,o as kr,f as w,k as a,j as o,g as e,m as i,r as s,t as k,s as r,e as ne,c as f,v as X,b as _r,z as pr,x as he,D as Be,d as wr,l as q,a as jr,h as Nr,$ as Ur,q as Je,u as mr,n as qr}from"../chunks/sWNKMed7.js";import{i as D,s as Or,a as Lr}from"../chunks/Ccl3fNd2.js";import{r as T,s as Fe,b as xe,g as R}from"../chunks/D30EsFKH.js";import{P as Br}from"../chunks/BAf75JIA.js";import{e as vr,i as fr}from"../chunks/BuuPrWMc.js";import{b as H,a as Jr}from"../chunks/CLagxtgo.js";import{p as Fr}from"../chunks/D4Caz1gY.js";import{M as Vr}from"../chunks/C3KRf8YK.js";import{J as Wr}from"../chunks/CNXs9ZB8.js";import{e as Y}from"../chunks/BZiHL9L3.js";import{U as Kr}from"../chunks/j86Jz9T7.js";import{D as Qr}from"../chunks/B6BdCO3z.js";import{e as Xr,a as yr}from"../chunks/DWynKlcl.js";import{t as ke}from"../chunks/BZUCTtPY.js";import{e as ce,h as Yr}from"../chunks/DyvUHRqW.js";import{D as Zr,G as Ve,a as et}from"../chunks/I29fo47B.js";import{E as rt}from"../chunks/DHJFrtJ4.js";import{E as tt}from"../chunks/BLz-7_AQ.js";import{S as at}from"../chunks/CE4EvFNL.js";import{P as ot}from"../chunks/DSb1C-fb.js";import"../chunks/CWoVlqr_.js";var st=w('
',1);function Ut(_e,we){xr(we,!1);const[Z,O]=Or(),b=()=>Lr(Xr,"$eagerCache",Z),n=i(),m=i(),S=i(),L=i();let C=i([]),$=i(!0),v=i(""),_=i(""),u=i(1),y=i(25),A=i(!1),z=i(!1),I=i(!1),d=i(null);async function B(t){try{r(v,""),r(A,!1),ke.success("Scale Set Created","Scale set has been created successfully.")}catch(c){throw r(v,Y(c)),c}}async function J(t){if(e(d))try{await R.updateScaleSet(e(d).id,t),ke.success("Scale Set Updated",`Scale set ${e(d).name} has been updated successfully.`),r(z,!1),r(d,null)}catch(c){throw c}}async function ee(){if(e(d))try{await R.deleteScaleSet(e(d).id),ke.success("Scale Set Deleted",`Scale set ${e(d).name} has been deleted successfully.`)}catch(t){const c=Y(t);ke.error("Delete Failed",c)}finally{r(I,!1),r(d,null)}}function re(){r(A,!0)}function G(t){r(d,t),r(z,!0)}function ue(t){r(d,t),r(I,!0)}kr(async()=>{try{r($,!0);const t=await yr.getScaleSets();t&&Array.isArray(t)&&r(C,t)}catch(t){console.error("Failed to load scale sets:",t),r(v,Y(t))}finally{r($,!1)}});async function Se(){try{await yr.retryResource("scalesets")}catch(t){console.error("Retry failed:",t)}}const te=[{key:"name",title:"Name",cellComponent:rt,cellProps:{entityType:"scaleset"}},{key:"image",title:"Image",cellComponent:Ve,cellProps:{field:"image",type:"code",showTitle:!0}},{key:"provider",title:"Provider",cellComponent:Ve,cellProps:{field:"provider_name"}},{key:"flavor",title:"Flavor",cellComponent:Ve,cellProps:{field:"flavor"}},{key:"entity",title:"Entity",cellComponent:ot},{key:"endpoint",title:"Endpoint",cellComponent:tt},{key:"status",title:"Status",cellComponent:at,cellProps:{statusType:"enabled"}},{key:"actions",title:"Actions",align:"right",cellComponent:et}],Ce={entityType:"scaleset",primaryText:{field:"name",isClickable:!0,href:"/scalesets/{id}"},secondaryText:{field:"entity_name",computedValue:t=>ce(t)},badges:[{type:"custom",value:t=>({variant:t.enabled?"success":"error",text:t.enabled?"Enabled":"Disabled"})}],actions:[{type:"edit",handler:t=>G(t)},{type:"delete",handler:t=>ue(t)}]};function p(t){r(_,t.detail.term),r(u,1)}function F(t){r(u,t.detail.page)}function P(t){r(y,t.detail.perPage),r(u,1)}function V(t){G(t.detail.item)}function ge(t){ue(t.detail.item)}q(()=>(e(C),b()),()=>{(!e(C).length||b().loaded.scalesets)&&r(C,b().scalesets)}),q(()=>b(),()=>{r($,b().loading.scalesets)}),q(()=>b(),()=>{r(n,b().errorMessages.scalesets)}),q(()=>(e(C),e(_),ce),()=>{r(m,Yr(e(C),e(_),t=>ce(t)))}),q(()=>(e(m),e(y)),()=>{r(S,Math.ceil(e(m).length/e(y)))}),q(()=>(e(u),e(S)),()=>{e(u)>e(S)&&e(S)>0&&r(u,e(S))}),q(()=>(e(m),e(u),e(y)),()=>{r(L,e(m).slice((e(u)-1)*e(y),e(u)*e(y)))}),jr(),hr();var be=vt();Nr(t=>{Ur.title="Scale Sets - GARM"});var j=_r(be),ae=o(j);Br(ae,{title:"Scale Sets",description:"Manage GitHub runner scale sets",actionLabel:"Add Scale Set",$$events:{action:re}});var oe=a(ae,2);{let t=Je(()=>e(n)||e(v)),c=Je(()=>!!e(n));Zr(oe,{get columns(){return te},get data(){return e(L)},get loading(){return e($)},get error(){return e(t)},get searchTerm(){return e(_)},searchPlaceholder:"Search by entity name...",get currentPage(){return e(u)},get perPage(){return e(y)},get totalPages(){return e(S)},get totalItems(){return e(m),mr(()=>e(m).length)},itemName:"scale sets",emptyIconType:"cog",get showRetry(){return e(c)},get mobileCardConfig(){return Ce},$$events:{search:p,pageChange:F,perPageChange:P,retry:Se,edit:V,delete:ge}})}s(j);var se=a(j,2);{var pe=t=>{mt(t,{$$events:{close:()=>r(A,!1),submit:c=>B(c.detail)}})};D(se,t=>{e(A)&&t(pe)})}var W=a(se,2);{var le=t=>{Kr(t,{get scaleSet(){return e(d)},$$events:{close:()=>{r(z,!1),r(d,null)},submit:c=>J(c.detail)}})};D(W,t=>{e(z)&&e(d)&&t(le)})}var me=a(W,2);{var ve=t=>{{let c=Je(()=>(e(d),qr(ce),mr(()=>`Scale Set ${e(d).name} (${ce(e(d))})`)));Qr(t,{title:"Delete Scale Set",message:"Are you sure you want to delete this scale set? This action cannot be undone and will remove all associated runners.",get itemName(){return e(c)},$$events:{close:()=>{r(I,!1),r(d,null)},confirm:ee}})}};D(me,t=>{e(I)&&e(d)&&t(ve)})}f(_e,be),wr(),O()}export{Ut as component};