import{n as f,d as N,u as y,e as w,j as t,B as _,S,f as C,g as v,h as I,i as d}from"./index-DXI13nSQ.js";import{r as m}from"./react-Cb2sDjhD.js";import{D as T}from"./data-table-BVcXWtPw.js";import{E as D}from"./empty-state-WHzNYVaT.js";import{S as R}from"./status-badge-DeESb2dc.js";import{u as k}from"./useQuery-CEwGD94N.js";import{L as B}from"./loader-circle-BS5FFFg-.js";import{R as L}from"./refresh-ccw-BPKXoMZa.js";import"./table-oUi0mGOn.js";import"./arrow-up-DtrvOH7Z.js";import"./arrow-down-OdSfpgG4.js";/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const M=f("Terminal",[["polyline",{points:"4 17 10 11 4 5",key:"akl6gq"}],["line",{x1:"12",x2:"20",y1:"19",y2:"19",key:"q2wloq"}]]),A={all:["bgjobs"],list:s=>["bgjobs","list",s]};function q(s){return k({queryKey:A.list(s),queryFn:()=>N.listBgJobs(s),refetchInterval:5e3,refetchIntervalInBackground:!1})}function G(){const{t:s}=y(["tasks","common"]),[a,i]=w(),l=a.get("root")??null,{data:o,isLoading:x,isFetching:c,refetch:h}=q(l?{root:l}:{}),n=o?.roots??[],b=m.useMemo(()=>o?o.jobs?o.jobs:o.groups?o.groups.flatMap(e=>e.jobs):[]:[],[o]);function j(e){const r=new URLSearchParams(a);e?r.set("root",e):r.delete("root"),i(r,{replace:!0})}const p=m.useMemo(()=>[{id:"name",header:s("bgjobs.col.name"),cell:e=>t.jsx("span",{className:"font-medium",children:e.name}),asCardTitle:!0},{id:"status",header:s("bgjobs.col.status"),cell:e=>t.jsx(R,{status:e.status,children:e.status}),headClassName:"w-28"},{id:"root",header:s("bgjobs.col.root"),cell:e=>{const r=n.find(g=>g.id===e.rootId);return t.jsx("span",{className:"text-text-dim",title:r?.path??e.rootId,children:r?.label??e.rootId})},headClassName:"w-32"},{id:"pid",header:s("bgjobs.col.pid"),cell:e=>t.jsx("span",{className:"tabular-nums text-text-dim",children:e.pid??"—"}),headClassName:"w-20",hideOnMobile:!0},{id:"startedAt",header:s("bgjobs.col.startedAt"),cell:e=>t.jsx("span",{className:"text-text-dim",children:u(e.started_at)}),headClassName:"w-40",hideOnMobile:!0},{id:"endedAt",header:s("bgjobs.col.endedAt"),cell:e=>t.jsx("span",{className:"text-text-dim",children:u(e.ended_at)}),headClassName:"w-40",hideOnMobile:!0},{id:"exit",header:s("bgjobs.col.exit"),cell:e=>e.ended_at==null?t.jsx("span",{className:"text-text-muted",children:s("bgjobs.stillRunning")}):e.exit_code===0?t.jsx("span",{className:"text-success",children:s("bgjobs.exitOk")}):e.exit_code!=null?t.jsx("span",{className:"text-danger tabular-nums",children:e.exit_code}):t.jsx("span",{className:"text-text-muted",children:"—"}),headClassName:"w-20"}],[s,n]);return t.jsxs("div",{className:"mx-auto flex max-w-7xl flex-col gap-4",children:[t.jsxs("header",{className:"flex flex-col gap-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[t.jsx("h1",{className:"text-xl font-semibold",children:s("bgjobs.title")}),t.jsxs(_,{variant:"ghost",size:"sm",className:"ml-auto",onClick:()=>h(),disabled:c,"aria-label":s("actions.refresh",{ns:"common"}),children:[c?t.jsx(B,{className:"h-4 w-4 animate-spin"}):t.jsx(L,{className:"h-4 w-4"}),t.jsx("span",{className:"hidden sm:inline",children:s("actions.refresh",{ns:"common"})})]})]}),t.jsx("p",{className:"text-sm text-text-dim",children:s("bgjobs.subtitle")})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("label",{className:"text-sm text-text-dim",htmlFor:"root-filter",children:s("bgjobs.filter.root")}),t.jsxs(S,{value:l??"__any__",onValueChange:e=>j(e==="__any__"?null:e),children:[t.jsx(C,{id:"root-filter",className:"w-[180px]",children:t.jsx(v,{})}),t.jsxs(I,{children:[t.jsx(d,{value:"__any__",children:s("bgjobs.filter.rootAny")}),n.map(e=>t.jsx(d,{value:e.id,children:e.label},e.id))]})]})]}),t.jsx(T,{columns:p,rows:b,getRowId:e=>`${e.rootId}:${e.id}`,loading:x,emptyState:t.jsx(D,{icon:t.jsx(M,{}),title:s("bgjobs.empty.title"),description:s("bgjobs.empty.description")})})]})}function u(s){if(s==null)return"—";try{const a=new Date(s);if(Number.isNaN(a.getTime()))return s;const i=new Date;return a.toDateString()===i.toDateString()?a.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit"}):a.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return s}}export{G as default};
//# sourceMappingURL=bgjobs-D3wsuZBR.js.map
