import{Ft as e,K as t,Nt as n,Pt as r,Vt as i,Wt as a,_t as o}from"./branding-B7dW-jsD.js";import{t as s}from"./createLucideIcon-DRi237xT.js";import{t as c}from"./use-revalidate-on-event-SnX7JsHj.js";import{t as l}from"./RunFilters-BzITWcjG.js";import{t as u}from"./plus-DD2vE6vi.js";import{E as d,R as f}from"./index-B6j-NK0t.js";import{t as p}from"./HeaderApp-Aqs89_qS.js";import{t as m}from"./use-document-meta-Ds8yu_o4.js";import{o as h,r as g}from"./dist-DPGUuPLH.js";import{t as _}from"./RunsTable-D4YJhDoL.js";var v=s(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]),y=n();function b(e,t){return t<=7?Array.from({length:t},(e,t)=>t+1):e<=3?[1,2,3,4,`ellipsis`,t]:e>=t-2?[1,`ellipsis`,t-3,t-2,t-1,t]:[1,`ellipsis`,e-1,e,e+1,`ellipsis`,t]}function x({currentPage:e,totalPages:n,total:r,onPageChange:i,perPage:a,className:s}){let c=a?Math.min((e-1)*a+1,r):1,l=a?Math.min(e*a,r):r;if(n<=1)return(0,y.jsx)(`div`,{className:o(`flex items-center justify-between`,s),children:(0,y.jsx)(`p`,{className:`text-xs text-muted-foreground tabular-nums`,children:a?`Showing ${c}-${l} of ${r}`:`${r} result${r===1?``:`s`}`})});let u=b(e,n);return(0,y.jsxs)(`div`,{className:o(`flex items-center justify-between`,s),children:[(0,y.jsx)(`p`,{className:`text-xs text-muted-foreground tabular-nums`,children:a?`Showing ${c}-${l} of ${r}`:`Page ${e} of ${n} (${r} total)`}),(0,y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,y.jsx)(t,{variant:`outline`,size:`sm`,className:`size-8 p-0`,onClick:()=>i(e-1),disabled:e<=1,"aria-label":`Previous page`,children:(0,y.jsx)(v,{className:`size-4`})}),u.map((n,r)=>n===`ellipsis`?(0,y.jsx)(`span`,{"aria-hidden":`true`,className:`px-1 text-xs text-muted-foreground select-none`,children:`…`},`ellipsis-${r}`):(0,y.jsx)(t,{variant:n===e?`default`:`outline`,size:`sm`,className:`size-8 p-0 text-xs tabular-nums`,onClick:()=>i(n),"aria-label":`Go to page ${n}`,"aria-current":n===e?`page`:void 0,children:n},n)),(0,y.jsx)(t,{variant:`outline`,size:`sm`,className:`size-8 p-0`,onClick:()=>i(e+1),disabled:e>=n,"aria-label":`Next page`,children:(0,y.jsx)(d,{className:`size-4`})})]})]})}var S=20;async function C({request:e}){let t=new URL(e.url),n=t.searchParams.get(`page`)??`1`,i=t.searchParams.get(`workflow`)??``,a=t.searchParams.get(`status`)??``,o=t.searchParams.get(`has_steps`)??`true`,s=t.searchParams.get(`label`)??``,c=new URLSearchParams;c.set(`page`,n),c.set(`per_page`,String(S)),i&&c.set(`workflow`,i),a&&c.set(`status`,a),o===`true`&&c.set(`has_steps`,`true`),s&&c.set(`label`,s);let l=await r.get(`/runs?${c}`);return{runs:l.data,meta:l.meta}}function w(){let{runs:n,meta:r}=i(),o=a().state===`loading`,s=f(e=>e.auth),d=s.status===`authenticated`&&s.user.is_admin;m({title:`Runs`,description:`Monitor and manage workflow executions.`}),c();let[v,b]=h({page:g.withDefault(1).withOptions({shallow:!1})},{history:`push`}),C=v.page,w=r?Math.ceil(r.total/r.per_page):1,T=e=>{b({page:e})};return(0,y.jsx)(p,{title:`Runs`,description:`Monitor and manage workflow executions.`,titleItem:d?(0,y.jsx)(e,{to:`/workflows`,className:`block`,children:(0,y.jsxs)(t,{className:`w-full sm:w-fit gap-1.5`,children:[(0,y.jsx)(u,{className:`w-4 h-4`}),`Go to Workflows`]})}):void 0,children:(0,y.jsxs)(`div`,{className:`space-y-6`,children:[(0,y.jsx)(l,{}),(0,y.jsx)(`div`,{"aria-busy":o,"aria-live":`polite`,className:o?`opacity-50 pointer-events-none transition-opacity`:``,children:(0,y.jsx)(_,{runs:n})}),(0,y.jsx)(x,{currentPage:C,totalPages:w,total:r?.total??n.length,perPage:S,onPageChange:T})]})})}export{w as Component,C as loader};