"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[243],{6639:function(e,s,t){t.d(s,{Z:function(){return r}});/**
 * @license lucide-react v0.407.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */let r=(0,t(60998).Z)("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]])},16826:function(e,s,t){t.d(s,{Z:function(){return r}});/**
 * @license lucide-react v0.407.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */let r=(0,t(60998).Z)("Download",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"7 10 12 15 17 10",key:"2ggqvy"}],["line",{x1:"12",x2:"12",y1:"15",y2:"3",key:"1vk2je"}]])},13626:function(e,s,t){t.d(s,{Z:function(){return r}});/**
 * @license lucide-react v0.407.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */let r=(0,t(60998).Z)("RotateCw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]])},8686:function(e,s,t){t.d(s,{N:function(){return a}});var r=t(85893);t(67294);var n=t(470);let a=e=>{let{showTooltip:s=!0,className:t=""}=e,a=(0,r.jsxs)("span",{className:"\n        inline-flex items-center gap-0.5\n        px-1.5 py-0.5\n        text-[10px] font-semibold uppercase tracking-wide\n        bg-gradient-to-r from-emerald-50 to-teal-50\n        text-emerald-700\n        border border-emerald-200\n        rounded\n        shadow-sm\n        cursor-help\n        select-none\n        ".concat(t,"\n      "),children:[(0,r.jsx)("svg",{className:"w-2.5 h-2.5 text-emerald-500",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,r.jsx)("path",{fillRule:"evenodd",d:"M10.868 2.884c-.321-.772-1.415-.772-1.736 0l-1.83 4.401-4.753.381c-.833.067-1.171 1.107-.536 1.651l3.62 3.102-1.106 4.637c-.194.813.691 1.456 1.405 1.02L10 15.591l4.069 2.485c.713.436 1.598-.207 1.404-1.02l-1.106-4.637 3.62-3.102c.635-.544.297-1.584-.536-1.65l-4.752-.382-1.831-4.401z",clipRule:"evenodd"})}),(0,r.jsx)("span",{children:"Primary"})]});return s?(0,r.jsx)(n.Md,{content:"Primary task – other tasks will be terminated once all primary tasks finish",className:"text-muted-foreground",children:a}):a}},20546:function(e,s,t){t.d(s,{H:function(){return d}});var r=t(85893);t(67294);var n=t(41664),a=t.n(n),l=t(45697),i=t.n(l);function c(e){return!!e&&"string"==typeof e&&e.toLowerCase().startsWith("sa-")}let o=()=>(0,r.jsx)("span",{className:"px-2 py-0.5 text-xs bg-blue-100 text-blue-700 rounded font-medium ml-1",children:"SA"}),d=e=>{let{username:s,userHash:t,className:n="flex items-center gap-1",linkClassName:l="text-gray-700 hover:text-blue-600 hover:underline",showBadge:i=!0}=e,d=c(t),u=c(t)?"/users?tab=service-accounts":"/users";return(0,r.jsxs)("div",{className:n,children:[(0,r.jsx)(a(),{href:u,className:l,children:s}),i&&d&&(0,r.jsx)(o,{})]})};d.propTypes={username:i().string.isRequired,userHash:i().string,className:i().string,linkClassName:i().string,showBadge:i().bool}},92128:function(e,s,t){t.d(s,{Oh:function(){return h},_R:function(){return x},cV:function(){return m}});var r=t(85893),n=t(67294),a=t(91360),l=t(30803),i=t(37673),c=t(27325),o=t(470),d=t(93225),u=t(23001);function h(e){let{isOpen:s,onClose:t,cluster:d}=e,[u,h]=n.useState(!1),x=e=>{navigator.clipboard.writeText(e),h(!0),setTimeout(()=>h(!1),2e3)},m=["sky status ".concat(d),"ssh ".concat(d)],p=m.join("\n");return(0,r.jsx)(a.Vq,{open:s,onOpenChange:t,children:(0,r.jsxs)(a.cZ,{className:"sm:max-w-md",children:[(0,r.jsxs)(a.fK,{children:[(0,r.jsxs)(a.$N,{children:["Connect to: ",(0,r.jsx)("span",{className:"font-light",children:d})]}),(0,r.jsx)(a.Be,{children:"Use these instructions to connect to your cluster via SSH."})]}),(0,r.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("h3",{className:"text-sm font-medium mb-2",children:"SSH Command"}),(0,r.jsx)(i.Zb,{className:"p-3 bg-gray-50",children:(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)("pre",{className:"text-sm w-full whitespace-pre-wrap",children:m.map((e,s)=>(0,r.jsx)("code",{className:"block",children:e},s))}),(0,r.jsx)(o.WH,{content:u?"Copied!":"Copy command",children:(0,r.jsx)(l.z,{variant:"ghost",size:"icon",onClick:()=>x(p),className:"h-8 w-8 rounded-full",children:(0,r.jsx)(c.Z,{className:"h-4 w-4"})})})]})})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("h3",{className:"text-sm font-medium mb-2",children:"Additional Information"}),(0,r.jsxs)("p",{className:"text-sm text-secondary-foreground",children:["Make sure to run"," ",(0,r.jsxs)("code",{className:"text-sm",children:["sky status ",d]})," first to have SkyPilot set up the SSH access."]})]})]})]})})}function x(e){let{isOpen:s,onClose:t,cluster:n}=e,h=(0,u.X)();return(0,r.jsx)(a.Vq,{open:s,onOpenChange:t,children:(0,r.jsx)(a.cZ,{className:"sm:max-w-3xl",children:(0,r.jsxs)(a.fK,{children:[(0,r.jsxs)(a.$N,{children:["Connect to: ",(0,r.jsx)("span",{className:"font-light",children:n})]}),(0,r.jsx)(a.Be,{children:(0,r.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("h3",{className:"text-sm font-medium mb-2 my-2",children:"Setup SSH access"}),(0,r.jsx)(i.Zb,{className:"p-3 bg-gray-50",children:(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)("pre",{className:"text-sm",children:(0,r.jsxs)("code",{children:["sky status ",n]})}),(0,r.jsx)(o.WH,{content:"Copy command",children:(0,r.jsx)(l.z,{variant:"ghost",size:"icon",onClick:()=>navigator.clipboard.writeText("sky status ".concat(n)),className:"h-8 w-8 rounded-full",children:(0,r.jsx)(c.Z,{className:"h-4 w-4"})})})]})})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("h3",{className:"text-sm font-medium mb-2 my-2",children:"Connect with VSCode/Cursor"}),(0,r.jsx)(i.Zb,{className:"p-3 bg-gray-50",children:(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)("pre",{className:"text-sm",children:(0,r.jsxs)("code",{children:["code --remote ssh-remote+",n,' "/home"']})}),(0,r.jsx)(o.WH,{content:"Copy command",children:(0,r.jsx)(l.z,{variant:"ghost",size:"icon",onClick:()=>navigator.clipboard.writeText("code --remote ssh-remote+".concat(n,' "/home"')),className:"h-8 w-8 rounded-full",children:(0,r.jsx)(c.Z,{className:"h-4 w-4"})})})]})})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("h3",{className:"text-sm font-medium",children:"Or use the GUI to connect"}),(0,r.jsx)("div",{className:"relative ".concat(h?"-mt-5":"-mt-10"),style:{paddingBottom:"70%"},children:(0,r.jsxs)("video",{className:"absolute top-0 left-0 w-full h-full rounded-lg",controls:!0,autoPlay:!0,muted:!0,preload:"metadata",children:[(0,r.jsx)("source",{src:"".concat(d.GW,"/videos/cursor-small.mp4"),type:"video/mp4"}),"Your browser does not support the video tag."]})})]})]})})]})})})}function m(e){let{isOpen:s,onClose:t,onConfirm:n,title:i,message:c,confirmText:o="Confirm",confirmVariant:d="destructive",confirmClassName:u=null}=e;return(0,r.jsx)(a.Vq,{open:s,onOpenChange:t,children:(0,r.jsxs)(a.cZ,{className:"sm:max-w-md",children:[(0,r.jsxs)(a.fK,{children:[(0,r.jsx)(a.$N,{children:i}),(0,r.jsx)(a.Be,{children:c})]}),(0,r.jsxs)(a.cN,{className:"flex justify-end gap-2 pt-4",children:[(0,r.jsx)(l.z,{variant:"outline",onClick:t,children:"Cancel"}),(0,r.jsx)(l.z,{variant:u?void 0:d,className:u,onClick:()=>{n(),t()},children:o})]})]})})}},9243:function(e,s,t){t.r(s),t.d(s,{ClusterJobs:function(){return K},ManagedJobs:function(){return B},ManagedJobsTable:function(){return G},Status2Actions:function(){return J},filterJobsByName:function(){return O},filterJobsByPool:function(){return W},filterJobsByUser:function(){return U},filterJobsByWorkspace:function(){return F},getAggregatedStatus:function(){return H},statusGroups:function(){return Z}});var r=t(85893),n=t(67294),a=t(11163),l=t(41664),i=t.n(l),c=t(55739),o=t(30803),d=t(37673),u=t(68764),h=t(470),x=t(51214),m=t(68969),p=t(97335),j=t(23266),f=t(17324),g=t(45895),b=t(6639),N=t(13626),v=t(60998);/**
 * @license lucide-react v0.407.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */let w=(0,v.Z)("RefreshCcw",[["path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"14sxne"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16",key:"1hlbsb"}],["path",{d:"M16 16h5v5",key:"ccwih5"}]]),y=(0,v.Z)("FileSearch",[["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M4.268 21a2 2 0 0 0 1.727 1H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v3",key:"ms7g94"}],["path",{d:"m9 18-1.5-1.5",key:"1j6qii"}],["circle",{cx:"5",cy:"14",r:"3",key:"ufru5t"}]]);var k=t(16826),C=t(92128),S=t(94545),_=t(99307),E=t(8686),L=t(20546),R=t(23001),M=t(6378),I=t(36856),D=t(55988),P=t(23800),A=t(10546);let Z={active:["PENDING","RUNNING","RECOVERING","SUBMITTED","STARTING","CANCELLING"],finished:["SUCCEEDED","FAILED","CANCELLED","FAILED_SETUP","FAILED_PRECHECKS","FAILED_NO_RESOURCE","FAILED_CONTROLLER"]},T={SUCCEEDED:0,PENDING:1,SUBMITTED:2,STARTING:3,RUNNING:4,RECOVERING:5,CANCELLING:6,CANCELLED:7,FAILED_SETUP:8,FAILED_PRECHECKS:9,FAILED_NO_RESOURCE:10,FAILED:11,FAILED_CONTROLLER:12};function H(e){if(!e||0===e.length)return"PENDING";if(1===e.length)return e[0].status;let s=e.filter(e=>null===e.is_primary_in_job_group||void 0===e.is_primary_in_job_group||!0===e.is_primary_in_job_group),t=s.length>0?s:e,r="SUCCEEDED",n=0;for(let e of t){var a;let s=null!==(a=T[e.status])&&void 0!==a?a:0;s>n&&(n=s,r=e.status)}return r}let z=[{label:"Name",value:"name"},{label:"User",value:"user"},{label:"Workspace",value:"workspace"},{label:"Pool",value:"pool"},{label:"Labels",value:"labels"}];function O(e,s){if(!s||""===s.trim())return e;let t=s.toLowerCase().trim();return e.filter(e=>(e.name||"").toLowerCase().includes(t))}function F(e,s){return s&&"ALL_WORKSPACES"!==s?e.filter(e=>(e.workspace||"default").toLowerCase()===s.toLowerCase()):e}function U(e,s){return s&&"ALL_USERS"!==s?e.filter(e=>(e.user_hash||e.user)===s):e}function W(e,s){if(!s||""===s.trim())return e;let t=s.toLowerCase().trim();return e.filter(e=>(e.pool||"").toLowerCase().includes(t))}let q=e=>{if(!e)return"-";let s=e instanceof Date?e:new Date(1e3*e);return(0,r.jsx)(h.Zg,{date:s})};function B(){let e=(0,a.useRouter)(),[s,t]=(0,n.useState)(!1),[l,c]=(0,n.useState)(!0),[o,d]=(0,n.useState)(!0),u=n.useRef(null),x=n.useRef(null),[j,g]=(0,n.useState)([]),[b,N]=(0,n.useState)([]),[v,w]=(0,n.useState)({name:[],user:[],workspace:[],pool:[],labels:[]}),[y,k]=(0,n.useState)(!1),[C,S]=(0,n.useState)(null),_=n.useCallback(async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];t(!0),!e&&o&&c(!0);try{let[e]=await Promise.all([M.ZP.get(m.vs,[{}])]);g(e.pools||[])}catch(e){console.error("Error fetching data:",e)}finally{t(!1),!e&&o&&(c(!1),d(!1))}},[o]);(0,n.useEffect)(()=>{(async()=>{try{await I.ZP.preloadForPage("jobs")}catch(e){console.error("Error preloading jobs data:",e)}finally{k(!0),S(new Date),_()}})()},[_]);let E=s=>{(0,A.eG)(e,s)},L=n.useCallback(()=>{let s=new Map;s.set("",""),s.set("status","Status"),s.set("name","Name"),s.set("user","User"),s.set("workspace","Workspace"),s.set("pool","Pool"),s.set("labels","Labels"),N((0,A.Fu)(e,s))},[e,N]);return(0,n.useEffect)(()=>{e.isReady&&L()},[e.isReady,e.query.tab,L]),(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2 mb-1",children:[(0,r.jsx)("div",{className:"text-base",children:(0,r.jsx)(i(),{href:"/jobs",className:"text-sky-blue hover:underline leading-none",children:"Managed Jobs"})}),(0,r.jsx)("div",{className:"w-full sm:w-auto",children:(0,r.jsx)(A.ML,{propertyList:z,valueList:v,setFilters:N,updateURLParams:E,placeholder:"Filter jobs"})})]}),(0,r.jsx)(A.x$,{filters:b,setFilters:N,updateURLParams:E}),(0,r.jsx)(G,{refreshInterval:h.yc,setLoading:t,refreshDataRef:u,filters:b,onRefresh:()=>{p.Z.invalidateCache(),M.ZP.invalidate(m.vs,[{}]),M.ZP.invalidate(f.getWorkspaces),k(!1),I.ZP.preloadForPage("jobs",{force:!0}).then(()=>{k(!0),S(new Date),u.current&&u.current(),x.current&&x.current()})},poolsData:j,poolsLoading:l,setValueList:w,preloadingComplete:y,lastFetchedTime:C}),(0,r.jsx)("div",{className:"mb-4",children:(0,r.jsx)(Y,{refreshInterval:h.yc,setLoading:t,refreshDataRef:x})})]})}function G(e){let{refreshInterval:s,setLoading:t,refreshDataRef:a,filters:l,onRefresh:f,poolsData:v,poolsLoading:y,setValueList:k,preloadingComplete:I,lastFetchedTime:T}=e,[z,O]=(0,n.useState)({key:null,direction:"ascending"}),[F,U]=(0,n.useState)(!1),[W,B]=(0,n.useState)(!0),[G,K]=(0,n.useState)(1),[Y,X]=(0,n.useState)(10),[Q,ee]=(0,n.useState)(null),es=(0,n.useRef)(null),[et,er]=(0,n.useState)(new Set),[en,ea]=(0,n.useState)([]),[el,ei]=(0,n.useState)({}),[ec,eo]=(0,n.useState)(!1),[ed,eu]=(0,n.useState)(!1),[eh,ex]=(0,n.useState)(!1),[em,ep]=(0,n.useState)("all"),[ej,ef]=(0,n.useState)(!0),[eg,eb]=(0,n.useState)({isOpen:!1,title:"",message:"",onConfirm:null}),eN=(0,R.X)(),ev=(0,n.useRef)(0),[ew,ey]=(0,n.useState)([]),[ek,eC]=(0,n.useState)(0),[eS,e_]=(0,n.useState)(0),[eE,eL]=(0,n.useState)(!1),eR=n.useMemo(()=>en.length>0?en:ej?"active"===em?Z.active:"finished"===em?Z.finished:[]:[],[en,ej,em]),eM=n.useMemo(()=>z.key||"submitted_at",[z.key]),eI=n.useMemo(()=>z.key&&"ascending"===z.direction?"asc":"desc",[z.key,z.direction]),eD=n.useMemo(()=>{if(!ew||0===ew.length)return!1;let e=new Set(ew.map(e=>e.workspace||"default"));return e.size>1||1===e.size&&!e.has("default")},[ew]),eP=n.useMemo(()=>v&&v.length>0,[v]),eA=async()=>{eb({isOpen:!0,title:"Restart Controller",message:"Are you sure you want to restart the controller?",onConfirm:async()=>{try{ex(!0),U(!0),await (0,m.Ce)("restartcontroller"),await eZ()}catch(e){console.error("Error restarting controller:",e)}finally{ex(!1),U(!1)}}})},eZ=n.useCallback(async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},s=!1!==e.includeStatus,r=ev.current+1;ev.current=r,U(!0),t(!0);try{let e=e=>{let s=(l||[]).find(s=>(s.property||"").toLowerCase()===e);return s&&s.value?String(s.value):void 0},t={allUsers:!0,nameMatch:e("name"),userMatch:e("user"),workspaceMatch:e("workspace"),poolMatch:e("pool"),statuses:eR.length>0?eR:void 0,page:G,limit:Y,sortBy:eM,sortOrder:eI};console.log("[ManagedJobsTable] Fetching jobs with params:",t);let n=await p.Z.getPaginatedJobs(t);if(r===ev.current&&(n.controllerStopped?(eL(!0),ey([]),eC(0),e_(0),ei({})):(eL(!1),ey(n.jobs||[]),eC(n.total||0),e_(n.totalNoFilter||n.total||0),ei(n.statusCounts||{})),n.hasNext&&p.Z.prefetchNextPage(t).catch(()=>{})),s)try{let e=await M.ZP.get(j.getClusters),s=!1,t=!1;if(e){let r=null==e?void 0:e.find(e=>(0,S.Ym)(e.cluster)),a=r?r.status:"NOT_FOUND";"STOPPED"===a&&n.controllerStopped&&(s=!0),"LAUNCHING"===a&&(t=!0)}r===ev.current&&(eo(!!s),eu(!!t))}catch(e){console.error("Error fetching clusters:",e)}r===ev.current&&B(!1)}catch(e){console.error("Error fetching data:",e),r===ev.current&&(ey([]),eC(0),e_(0),ei({}),eo(!1),B(!1))}finally{r===ev.current&&(U(!1),t(!1))}},[t,l,G,Y,eR,eM,eI]);n.useEffect(()=>{a&&(a.current=eZ)},[a,eZ]);let eT=n.useRef(eZ);n.useEffect(()=>{eT.current=eZ},[eZ]);let eH=n.useRef(!0);n.useEffect(()=>{eZ({includeStatus:!0}),eH.current=!1},[]),n.useEffect(()=>{!eH.current&&I&&eZ({includeStatus:!1})},[G,eZ,I]),n.useEffect(()=>{!eH.current&&I&&eZ({includeStatus:!0})},[l,Y,eZ,I]),n.useEffect(()=>{!eH.current&&I&&eZ({includeStatus:!0})},[em,en,ej,eZ,I]),n.useEffect(()=>{!eH.current&&I&&eZ({includeStatus:!1})},[z,eZ,I]),(0,n.useEffect)(()=>{if(!I)return;let e=setInterval(()=>{eT.current&&"visible"===window.document.visibilityState&&eT.current({includeStatus:!0})},s);return()=>{clearInterval(e)}},[s,I]),(0,n.useEffect)(()=>{K(1)},[em]),(0,n.useEffect)(()=>{K(1)},[l,Y]),(0,n.useEffect)(()=>{K(1)},[z]),(0,n.useEffect)(()=>{ea([]),ef(!0)},[em]),(0,n.useEffect)(()=>{if(!k)return;let e=new Set,s=new Set,t=new Set,r=new Set,n=new Set;ew.forEach(a=>{a.name&&e.add(a.name),a.user&&s.add(a.user),a.workspace&&t.add(a.workspace),a.pool&&r.add(a.pool),Object.entries(a.labels||{}).forEach(e=>{let[s,t]=e;n.add("".concat(s,":").concat(t))})}),v&&Array.isArray(v)&&v.forEach(e=>{if(!e.name)return;let s=e.jobCounts&&Object.keys(e.jobCounts).length>0,t=null!==e.uptime&&void 0!==e.uptime&&e.uptime>0&&e.uptime<86400;(s||t)&&r.add(e.name)}),k({name:Array.from(e).sort(),user:Array.from(s).sort(),workspace:Array.from(t).sort(),pool:Array.from(r).sort(),labels:Array.from(n).sort()})},[ew,v,k]);let ez=n.useCallback(e=>{let s="ascending";z.key===e&&"ascending"===z.direction&&(s="descending"),O({key:e,direction:s})},[z]),eO=n.useCallback(e=>z.key===e?"ascending"===z.direction?" ↑":" ↓":"",[z]);n.useMemo(()=>{let e=ew||[];return{active:e.filter(e=>Z.active.includes(e.status)).length,finished:e.filter(e=>Z.finished.includes(e.status)).length}},[ew]);let eF=e=>en.length>0?en.includes(e):"all"===em||Z[em].includes(e),eU=n.useMemo(()=>{let e=ew,s=null==l?void 0:l.find(e=>"labels"===(e.property||"").toLowerCase());return s&&s.value&&(e=e.filter(e=>(0,A.mu)(e,s))),e},[ew,l]),eW=n.useMemo(()=>z.key?[...eU].sort((e,s)=>e[z.key]<s[z.key]?"ascending"===z.direction?-1:1:e[z.key]>s[z.key]?"ascending"===z.direction?1:-1:0):eU,[eU,z]),eq=(G-1)*Y,eB=ek>0?Math.ceil(ek/Y):0,eG=n.useMemo(()=>{let e=new Map;return eW.forEach(s=>{let t=s.id;e.has(t)||e.set(t,[]),e.get(t).push(s)}),e},[eW]),eJ=n.useMemo(()=>{let e=new Map;return eG.forEach((s,t)=>{if(s.length>1){let r=s.some(e=>!1===e.is_primary_in_job_group),n=H(s),a=r?"Task statuses:\n".concat(s.map((e,s)=>{let t=!0===e.is_primary_in_job_group;return"Task ".concat(s).concat(t?" ★":"",": ").concat(e.status)}).join("\n"),"\n\n★ = Primary task"):"Task statuses:\n".concat(s.map((e,s)=>"Task ".concat(s,": ").concat(e.status)).join("\n")),l=s.map(e=>e.requested_resources||e.resources_str).filter(Boolean),i=[...new Set(l)],c=0===l.length?"-":1===i.length?i[0]:"".concat(i[0]," (+").concat(s.length-1," more)"),o=0===l.length?null:"Aggregated from ".concat(s.length," tasks:\n").concat(l.map((e,s)=>"Task ".concat(s,": ").concat(e)).join("\n")),d=s.reduce((e,s)=>e+(s.recoveries||0),0);e.set(t,{aggregatedStatus:n,statusTooltip:a,resourcesDisplay:c,resourcesTooltip:o,totalRecoveries:d})}}),e},[eG]),eK=n.useMemo(()=>Array.from(eG.values()).some(e=>e.length>1),[eG]),eV=e=>{er(s=>{let t=new Set(s);return t.has(e)?t.delete(e):t.add(e),t})},e$=e=>et.has(e),eY=e=>{if(en.includes(e)){let s=en.filter(s=>s!==e);0===s.length?(ef(!0),ea([])):(ea(s),ef(!1))}else ea([...en,e]),ef(!1);K(1)},eX=n.useMemo(()=>[{id:"id",order:0,renderHeader:()=>(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>ez("id"),children:["ID",eO("id")]}),renderCell:(e,s)=>{let{renderMode:t,jobId:n,taskIndex:a,isExpanded:l,toggleJobGroup:c,hasAnyJobGroups:o}=s||{};return"groupParent"===t?(0,r.jsx)(u.pj,{children:(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("button",{onClick:()=>c(n),className:"p-1 hover:bg-gray-200 rounded mr-1",children:l?(0,r.jsx)(g.Z,{className:"w-4 h-4 text-gray-500"}):(0,r.jsx)(b.Z,{className:"w-4 h-4 text-gray-500"})}),(0,r.jsx)(i(),{href:"/jobs/".concat(n),className:"text-blue-600",children:n})]})}):"groupChild"===t?(0,r.jsxs)(u.pj,{className:"whitespace-nowrap relative",children:[(0,r.jsx)("div",{className:"absolute left-0 top-0 bottom-0 w-0.5 bg-blue-300"}),(0,r.jsx)("span",{className:"text-gray-500 pl-6",children:a})]}):(0,r.jsx)(u.pj,{children:o?(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:"w-6 mr-1","aria-hidden":"true"}),(0,r.jsx)(i(),{href:"/jobs/".concat(e.id),className:"text-blue-600",children:e.id})]}):(0,r.jsx)(i(),{href:"/jobs/".concat(e.id),className:"text-blue-600",children:e.id})})}},{id:"name",order:1,renderHeader:()=>(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>ez("name"),children:["Name",eO("name")]}),renderCell:(e,s)=>{let{renderMode:t,jobId:n,tasks:a,taskIndex:l,toggleJobGroup:c}=s||{};if("groupParent"===t)return(0,r.jsx)(u.pj,{className:"whitespace-nowrap",children:(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(i(),{href:"/jobs/".concat(n),className:"text-blue-600",children:e.name}),(0,r.jsxs)("button",{onClick:()=>c(n),className:"ml-2 text-xs font-medium bg-gray-200 text-gray-700 hover:bg-gray-300 px-1.5 py-0.5 rounded cursor-pointer whitespace-nowrap",children:["JobGroup: ",a.length," tasks"]})]})});if("groupChild"===t){let s=a.some(e=>!1===e.is_primary_in_job_group);return(0,r.jsxs)(u.pj,{className:"whitespace-nowrap",children:[(0,r.jsx)(i(),{href:"/jobs/".concat(e.id,"/").concat(l),className:"text-blue-600 hover:underline",children:e.task||"Task ".concat(l)}),s&&!0===e.is_primary_in_job_group&&(0,r.jsx)("span",{className:"ml-1.5",children:(0,r.jsx)(E.N,{})})]})}return(0,r.jsx)(u.pj,{className:"whitespace-nowrap",children:(0,r.jsx)(i(),{href:"/jobs/".concat(e.id),className:"text-blue-600",children:e.name})})}},{id:"user",order:2,renderHeader:()=>(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>ez("user"),children:["User",eO("user")]}),renderCell:e=>(0,r.jsx)(u.pj,{children:(0,r.jsx)(L.H,{username:e.user,userHash:e.user_hash})})},{id:"workspace",order:2.5,conditional:!0,renderHeader:()=>eD?(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>ez("workspace"),children:["Workspace",eO("workspace")]}):null,renderCell:e=>eD?(0,r.jsx)(u.pj,{children:(0,r.jsx)(i(),{href:"/workspaces",className:"text-gray-700 hover:text-blue-600 hover:underline",children:e.workspace||"default"})}):null},{id:"submitted",order:3,renderHeader:()=>(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>ez("submitted_at"),children:["Submitted",eO("submitted_at")]}),renderCell:e=>(0,r.jsx)(u.pj,{children:q(e.submitted_at)})},{id:"duration",order:4,renderHeader:()=>(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>ez("job_duration"),children:["Duration",eO("job_duration")]}),renderCell:e=>(0,r.jsx)(u.pj,{children:(0,h.LU)(e.job_duration)})},{id:"status",order:5,renderHeader:()=>(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>ez("status"),children:["Status",eO("status")]}),renderCell:(e,s)=>{let{renderMode:t,aggregates:n}=s||{};return"groupParent"===t?(0,r.jsx)(u.pj,{children:(0,r.jsx)(h.Md,{content:null==n?void 0:n.statusTooltip,className:"text-sm text-muted-foreground",children:(0,r.jsx)("span",{children:(0,r.jsx)(_.OE,{status:null==n?void 0:n.aggregatedStatus})})})}):(0,r.jsx)(u.pj,{children:(0,r.jsx)(D.j,{name:"jobs.table.status.badge",context:e,fallback:(0,r.jsx)(_.OE,{status:e.status,statusTooltip:e.statusTooltip})})})}},{id:"infra",order:6,renderHeader:()=>(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>ez("infra"),children:["Infra",eO("infra")]}),renderCell:(e,s)=>{let{renderMode:t}=s||{};return"groupParent"===t?(0,r.jsx)(u.pj,{children:e.infra&&"-"!==e.infra?(0,r.jsx)("span",{children:e.cloud||e.infra.split("(")[0].trim()}):(0,r.jsx)("span",{children:"-"})}):(0,r.jsx)(u.pj,{children:e.infra&&"-"!==e.infra?(0,r.jsx)(h.Md,{content:e.full_infra||e.infra,className:"text-sm text-muted-foreground",children:(0,r.jsxs)("span",{children:[(0,r.jsx)(i(),{href:"/infra",className:"text-blue-600 hover:underline",children:e.cloud||e.infra.split("(")[0].trim()}),e.infra.includes("(")&&(0,r.jsx)("span",{children:" "+(()=>{let s=x.MO.NAME_TRUNCATE_LENGTH,t=e.infra.substring(e.infra.indexOf("(")),r=t.substring(1,t.length-1);if(r.length<=s)return t;let n="".concat(r.substring(0,Math.floor((s-3)/2)),"...").concat(r.substring(r.length-Math.ceil((s-3)/2)));return"(".concat(n,")")})()})]})}):(0,r.jsx)("span",{children:e.infra||"-"})})}},{id:"requested_resources",order:7,renderHeader:()=>(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>ez("cluster"),children:["Requested Resources",eO("cluster")]}),renderCell:(e,s)=>{let{renderMode:t,aggregates:n}=s||{};return"groupParent"===t?(0,r.jsx)(u.pj,{children:(null==n?void 0:n.resourcesTooltip)?(0,r.jsx)(h.Md,{content:n.resourcesTooltip,className:"text-sm text-muted-foreground",children:(0,r.jsx)("span",{children:n.resourcesDisplay})}):(0,r.jsx)("span",{children:null==n?void 0:n.resourcesDisplay})}):(0,r.jsx)(u.pj,{children:(0,r.jsx)(h.Md,{content:e.requested_resources||e.resources_str_full||e.resources_str||"-",className:"text-sm text-muted-foreground",children:(0,r.jsx)("span",{children:e.requested_resources||e.resources_str||"-"})})})}},{id:"recoveries",order:8,renderHeader:()=>(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>ez("recoveries"),children:["Recoveries",eO("recoveries")]}),renderCell:(e,s)=>{let{renderMode:t,aggregates:n}=s||{};return"groupParent"===t?(0,r.jsx)(u.pj,{children:null==n?void 0:n.totalRecoveries}):(0,r.jsx)(u.pj,{children:e.recoveries})}},{id:"pool",order:9.5,conditional:!0,renderHeader:()=>eP?(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>ez("pool"),children:["Pool",eO("pool")]}):null,renderCell:e=>eP?(0,r.jsx)(u.pj,{children:(0,r.jsx)("div",{className:y?"blur-sm transition-all duration-300":"",children:y?"-":(0,h.os)(e.pool,e.pool_hash,v)})}):null},{id:"details",order:10,renderHeader:()=>(0,r.jsx)(u.ss,{children:"Details"}),renderCell:(e,s)=>{let{renderMode:t}=s||{};if("groupParent"===t)return(0,r.jsx)(u.pj,{children:"-"});let n=(null==s?void 0:s.renderMode)==="groupChild"?e.task_job_id:e.id;return(0,r.jsx)(u.pj,{children:e.details?(0,r.jsx)($,{text:e.details,rowId:n,expandedRowId:Q,setExpandedRowId:ee}):"-"})}},{id:"logs",order:11,renderHeader:()=>(0,r.jsx)(u.ss,{children:"Logs"}),renderCell:(e,s)=>{let{renderMode:t,jobId:n}=s||{},a="groupParent"===t?n:e.id;return(0,r.jsx)(u.pj,{children:(0,r.jsx)(J,{jobParent:"/jobs",jobId:a,managed:!0,workspace:e.workspace})})}}],[ez,eO,eD,eP,Q,y,v]),eQ=n.useCallback(e=>({id:e.id,order:e.header.order,isPlugin:!0,pluginColumn:e,renderHeader:()=>{let s=e.header.sortKey?"sortable whitespace-nowrap":"whitespace-nowrap",t="".concat(s).concat(e.header.className?" "+e.header.className:"");return(0,r.jsxs)(u.ss,{className:t,onClick:e.header.sortKey?()=>ez(e.header.sortKey):void 0,children:[e.header.label,e.header.sortKey?eO(e.header.sortKey):""]})},renderCell:(s,t)=>{let n={item:s,shouldShowWorkspace:eD,shouldShowPool:eP,expandedRowId:Q,setExpandedRowId:ee,expandedRowRef:es,...t||{}},a=e.cell.render(s,n);return(0,r.jsx)(u.pj,{className:e.cell.className||"",children:a})}}),[ez,eO,eD,eP,Q,ee,es]),e0=(0,P.V$)("jobs",eX,{shouldShowColumn:e=>"workspace"===e?eD:"pool"!==e||eP},eQ),e1=e0.length;return(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)("div",{className:"flex flex-col space-y-1 mb-1",children:(0,r.jsxs)("div",{className:"flex items-center justify-between text-sm mb-1",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center min-w-0",children:[(0,r.jsx)("span",{className:"mr-2 text-sm font-medium",children:"Statuses:"}),(0,r.jsxs)("div",{className:"flex flex-wrap gap-2 items-center",children:[!F&&0===eS&&!W&&(0,r.jsx)("span",{className:"text-gray-500 mr-2",children:"No jobs found"}),Object.entries(el).map(e=>{let[s,t]=e;return(0,r.jsxs)("button",{onClick:()=>eY(s),className:"px-3 py-0.5 rounded-full flex items-center space-x-2 ".concat(eF(s)||en.includes(s)?(0,_.Cl)(s):"bg-gray-50 text-gray-600 hover:bg-gray-100"),children:[(0,r.jsx)("span",{children:s}),(0,r.jsx)("span",{className:"text-xs ".concat(eF(s)||en.includes(s)?"bg-white/50":"bg-gray-200"," px-1.5 py-0.5 rounded"),children:t})]},s)}),eS>0&&(0,r.jsxs)("div",{className:"flex items-center ml-2 gap-2",children:[(0,r.jsx)("span",{className:"text-gray-500",children:"("}),(0,r.jsx)("button",{onClick:()=>{n.startTransition(()=>{ep("all"),ea([]),ef(!0),K(1)})},className:"text-sm font-medium ".concat("all"===em&&ej?"text-purple-700 underline":"text-gray-600 hover:text-purple-700 hover:underline"),children:"show all jobs"}),(0,r.jsx)("span",{className:"text-gray-500 mx-1",children:"|"}),(0,r.jsx)("button",{onClick:()=>{n.startTransition(()=>{ep("active"),ea([]),ef(!0),K(1)})},className:"text-sm font-medium ".concat("active"===em&&ej?"text-green-700 underline":"text-gray-600 hover:text-green-700 hover:underline"),children:"show all active jobs"}),(0,r.jsx)("span",{className:"text-gray-500 mx-1",children:"|"}),(0,r.jsx)("button",{onClick:()=>{n.startTransition(()=>{ep("finished"),ea([]),ef(!0),K(1)})},className:"text-sm font-medium ".concat("finished"===em&&ej?"text-blue-700 underline":"text-gray-600 hover:text-blue-700 hover:underline"),children:"show all finished jobs"}),(0,r.jsx)("span",{className:"text-gray-500",children:")"})]})]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2 shrink-0 ml-2",children:[F&&(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(c.Z,{size:15,className:"mt-0"}),(0,r.jsx)("span",{className:"ml-2 text-gray-500 text-sm",children:"Loading..."})]}),!F&&T&&(0,r.jsx)(h.$3,{timestamp:T}),(0,r.jsxs)("button",{onClick:()=>{f&&f()},disabled:F,className:"text-sky-blue hover:text-sky-blue-bright flex items-center text-sm",children:[(0,r.jsx)(N.Z,{className:"h-4 w-4 mr-1.5"}),(0,r.jsx)("span",{children:"Refresh"})]})]})]})}),eN&&ec&&0===eW.length&&!F&&!W&&(0,r.jsx)("div",{className:"mb-4 p-4 bg-gray-50 rounded-lg border",children:(0,r.jsxs)("div",{className:"flex flex-col items-center space-y-3",children:[(0,r.jsxs)("p",{className:"text-gray-700 text-center text-sm",children:["Job controller stopped.",(0,r.jsx)("br",{}),"Restart to check status."]}),(0,r.jsx)(o.z,{variant:"outline",size:"sm",onClick:eA,className:"text-sky-blue hover:text-sky-blue-bright",disabled:F||eh,children:eh?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(c.Z,{size:12,className:"mr-2"}),"Restarting..."]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(w,{className:"h-4 w-4 mr-2"}),"Restart"]})})]})}),(0,r.jsx)(d.Zb,{className:"overflow-hidden",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)(u.iA,{className:"min-w-full border-collapse",children:[(0,r.jsx)(u.xD,{children:(0,r.jsx)(u.SC,{children:e0.map(e=>n.cloneElement(e.renderHeader(),{key:e.id}))})}),(0,r.jsx)(u.RM,{children:F&&W?(0,r.jsx)(u.SC,{children:(0,r.jsx)(u.pj,{colSpan:e1,className:"text-center py-6 text-gray-500",children:(0,r.jsxs)("div",{className:"flex justify-center items-center",children:[(0,r.jsx)(c.Z,{size:20,className:"mr-2"}),(0,r.jsx)("span",{children:"Loading..."})]})})}):eW.length>0?(0,r.jsx)(r.Fragment,{children:Array.from(eG.entries()).map(e=>{let[s,t]=e,a=t.length>1,l=e$(s),i=t[0];if(!a){let e={renderMode:"single",hasAnyJobGroups:eK};return(0,r.jsxs)(n.Fragment,{children:[(0,r.jsx)(u.SC,{children:e0.map(s=>{let t=s.renderCell(i,e);return t?n.cloneElement(t,{key:s.id}):null})}),Q===i.id&&(0,r.jsx)(V,{text:i.details,colSpan:e1,innerRef:es})]},i.task_job_id)}let c=eJ.get(s)||{},o={renderMode:"groupParent",jobId:s,tasks:t,aggregates:c,isExpanded:l,toggleJobGroup:eV,hasAnyJobGroups:eK};return(0,r.jsxs)(n.Fragment,{children:[(0,r.jsx)(u.SC,{className:"hover:bg-gray-50",children:e0.map(e=>{let s=e.renderCell(i,o);return s?n.cloneElement(s,{key:e.id}):null})}),l&&t.map((e,a)=>{let i={renderMode:"groupChild",jobId:s,tasks:t,taskIndex:a,aggregates:c,isExpanded:l,toggleJobGroup:eV,hasAnyJobGroups:eK};return(0,r.jsxs)(n.Fragment,{children:[(0,r.jsx)(u.SC,{className:"bg-gray-50/50",children:e0.map(s=>{let t=s.renderCell(e,i);return t?n.cloneElement(t,{key:s.id}):null})}),Q===e.task_job_id&&(0,r.jsx)(V,{text:e.details,colSpan:e1,innerRef:es})]},e.task_job_id)})]},"group-".concat(s))})}):(0,r.jsx)(u.SC,{children:(0,r.jsx)(u.pj,{colSpan:e1,className:"text-center py-6",children:(0,r.jsxs)("div",{className:"flex flex-col items-center space-y-4",children:[ed&&(0,r.jsxs)("div",{className:"flex flex-col items-center space-y-2",children:[(0,r.jsx)("p",{className:"text-gray-700",children:"The managed job controller is launching. It will be ready shortly."}),(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(c.Z,{size:12,className:"mr-2"}),(0,r.jsx)("span",{className:"text-gray-500",children:"Launching..."})]})]}),!ec&&!ed&&(0,r.jsx)("p",{className:"text-gray-500",children:"No active jobs"}),!eN&&ec&&(0,r.jsxs)("div",{className:"flex flex-col items-center space-y-3 px-4",children:[(0,r.jsx)("p",{className:"text-gray-700 text-center text-sm sm:text-base max-w-md",children:"The managed job controller has been stopped. Restart to check the latest job status."}),(0,r.jsx)(o.z,{variant:"outline",size:"sm",onClick:eA,className:"text-sky-blue hover:text-sky-blue-bright",disabled:F||eh,children:eh?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(c.Z,{size:12,className:"mr-2"}),"Restarting..."]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(w,{className:"h-4 w-4 mr-2"}),"Restart Controller"]})})]})]})})})})]})})}),(0,r.jsx)("div",{className:"flex justify-end items-center py-2 px-4 text-sm text-gray-700",children:(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:"mr-2",children:"Jobs per page:"}),(0,r.jsxs)("div",{className:"relative inline-block",children:[(0,r.jsxs)("select",{value:Y,onChange:e=>{X(parseInt(e.target.value,10)),K(1)},className:"py-1 pl-2 pr-6 appearance-none outline-none cursor-pointer border-none bg-transparent",style:{minWidth:"40px"},children:[(0,r.jsx)("option",{value:10,children:"10"}),(0,r.jsx)("option",{value:30,children:"30"}),(0,r.jsx)("option",{value:50,children:"50"}),(0,r.jsx)("option",{value:100,children:"100"}),(0,r.jsx)("option",{value:200,children:"200"})]}),(0,r.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 text-gray-500 absolute right-0 top-1/2 transform -translate-y-1/2 pointer-events-none",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]})]}),(0,r.jsx)("div",{children:ek>0?"".concat(eq+1," – ").concat(Math.min(eq+eG.size,ek)," of ").concat(ek):"0 – 0 of 0"}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)(o.z,{variant:"ghost",size:"icon",onClick:()=>{K(e=>Math.max(e-1,1))},disabled:1===G||!eW||0===eW.length,className:"text-gray-500 h-8 w-8 p-0",children:(0,r.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"chevron-left",children:(0,r.jsx)("path",{d:"M15 18l-6-6 6-6"})})}),(0,r.jsx)(o.z,{variant:"ghost",size:"icon",onClick:()=>{eB>0&&G<eB&&K(e=>e+1)},disabled:0===eB||G>=eB||!eW||0===eW.length,className:"text-gray-500 h-8 w-8 p-0",children:(0,r.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"chevron-right",children:(0,r.jsx)("path",{d:"M9 18l6-6-6-6"})})})]})]})}),(0,r.jsx)(C.cV,{isOpen:eg.isOpen,onClose:()=>eb({...eg,isOpen:!1}),onConfirm:eg.onConfirm,title:eg.title,message:eg.message,confirmClassName:"bg-blue-600 hover:bg-blue-700 text-white"})]})}function J(e){let{withLabel:s=!1,jobParent:t,jobId:n,managed:l,workspace:i="default"}=e,c=(0,a.useRouter)(),o=(e,s)=>{e.preventDefault(),e.stopPropagation(),c.push({pathname:"".concat(t,"/").concat(n),query:{tab:s}})},d=function(e){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(e.preventDefault(),e.stopPropagation(),l)(0,m.jh)({jobId:parseInt(n),controller:s});else{let e=t.match(/\/clusters\/(.+)/);if(e){let s=e[1];(0,j.GH)({clusterName:s,jobIds:[n],workspace:i})}}};return(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)(h.WH,{content:"View Job Logs",className:"capitalize text-sm text-muted-foreground",children:(0,r.jsxs)("button",{onClick:e=>o(e,"logs"),className:"text-sky-blue hover:text-sky-blue-bright font-medium inline-flex items-center h-8",children:[(0,r.jsx)(y,{className:"w-4 h-4"}),s&&(0,r.jsx)("span",{className:"ml-1.5",children:"Logs"})]})},"logs"),(0,r.jsx)(h.WH,{content:"Download All Task Logs (zip)",className:"capitalize text-sm text-muted-foreground",children:(0,r.jsxs)("button",{onClick:e=>d(e,!1),className:"text-sky-blue hover:text-sky-blue-bright font-medium inline-flex items-center h-8",children:[(0,r.jsx)(k.Z,{className:"w-4 h-4"}),s&&(0,r.jsx)("span",{className:"ml-1.5",children:"Download"})]})},"downloadlogs")]})}function K(e){let{clusterName:s,clusterJobData:t,loading:a,refreshClusterJobsOnly:l,userFilter:x=null,nameFilter:m=null,workspace:p="default"}=e,[j,f]=(0,n.useState)(null),[g,b]=(0,n.useState)({key:null,direction:"ascending"}),[v,w]=(0,n.useState)(1),[y,k]=(0,n.useState)(10),C=(0,n.useRef)(null),[S,E]=(0,n.useState)(null);(0,n.useEffect)(()=>{let e=e=>{j&&C.current&&!C.current.contains(e.target)&&f(null)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[j]);let R=n.useMemo(()=>{let e=t||[];return x&&"ALL_USERS"!==x&&(e=U(e,x)),m&&(e=O(e,m)),e},[t,x,m]);(0,n.useEffect)(()=>{JSON.stringify(t)!==JSON.stringify(S)&&E(t)},[t,S]);let M=n.useMemo(()=>g.key?[...R].sort((e,s)=>e[g.key]<s[g.key]?"ascending"===g.direction?-1:1:e[g.key]>s[g.key]?"ascending"===g.direction?1:-1:0):R,[R,g]),I=e=>{let s="ascending";g.key===e&&"ascending"===g.direction&&(s="descending"),b({key:e,direction:s})},D=e=>g.key===e?"ascending"===g.direction?" ↑":" ↓":"",P=Math.ceil(M.length/y),A=(v-1)*y,Z=A+y,T=M.slice(A,Z);return(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsxs)(d.Zb,{children:[(0,r.jsxs)("div",{className:"flex items-center justify-between p-4",children:[(0,r.jsx)("h3",{className:"text-lg font-semibold",children:"Cluster Jobs"}),(0,r.jsx)("div",{className:"flex items-center",children:l&&(0,r.jsxs)("button",{onClick:l,disabled:a,className:"text-sky-blue hover:text-sky-blue-bright font-medium inline-flex items-center text-sm ml-2",children:[(0,r.jsx)(N.Z,{className:"w-4 h-4 mr-1"}),"Refresh Jobs"]})})]}),(0,r.jsxs)(u.iA,{children:[(0,r.jsx)(u.xD,{children:(0,r.jsxs)(u.SC,{children:[(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>I("id"),children:["ID",D("id")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>I("job"),children:["Name",D("job")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>I("user"),children:["User",D("user")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>I("submitted_at"),children:["Submitted",D("submitted_at")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>I("job_duration"),children:["Duration",D("job_duration")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>I("status"),children:["Status",D("status")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>I("resources"),children:["Resources",D("resources")]}),(0,r.jsx)(u.ss,{className:"whitespace-nowrap",children:"Logs"})]})}),(0,r.jsx)(u.RM,{children:a?(0,r.jsx)(u.SC,{children:(0,r.jsx)(u.pj,{colSpan:8,className:"text-center py-12 text-gray-500",children:(0,r.jsxs)("div",{className:"flex justify-center items-center",children:[(0,r.jsx)(c.Z,{size:24,className:"mr-2"}),(0,r.jsx)("span",{children:"Loading cluster jobs..."})]})})}):T.length>0?T.map(e=>(0,r.jsxs)(n.Fragment,{children:[(0,r.jsxs)(u.SC,{className:j===e.id?"selected-row":"",children:[(0,r.jsx)(u.pj,{children:(0,r.jsx)(i(),{href:"/clusters/".concat(s,"/").concat(e.id),className:"text-blue-600",children:e.id})}),(0,r.jsx)(u.pj,{children:(0,r.jsx)(i(),{href:"/clusters/".concat(s,"/").concat(e.id),className:"text-blue-600",children:(0,r.jsx)($,{text:e.job||"Unnamed job",rowId:e.id,expandedRowId:j,setExpandedRowId:f})})}),(0,r.jsx)(u.pj,{children:(0,r.jsx)(L.H,{username:e.user,userHash:e.user_hash})}),(0,r.jsx)(u.pj,{children:q(e.submitted_at)}),(0,r.jsx)(u.pj,{children:(0,h.LU)(e.job_duration)}),(0,r.jsx)(u.pj,{children:(0,r.jsx)(_.OE,{status:e.status})}),(0,r.jsx)(u.pj,{children:e.resources}),(0,r.jsx)(u.pj,{className:"flex content-center items-center",children:(0,r.jsx)(J,{jobParent:"/clusters/".concat(s),jobId:e.id,managed:!1,workspace:p})})]}),j===e.id&&(0,r.jsx)(V,{text:e.job||"Unnamed job",colSpan:8,innerRef:C})]},e.id)):(0,r.jsx)(u.SC,{children:(0,r.jsx)(u.pj,{colSpan:8,className:"text-center py-6 text-gray-500",children:"No jobs found"})})})]})]}),M&&M.length>0&&(0,r.jsx)("div",{className:"flex justify-end items-center py-2 px-4 text-sm text-gray-700",children:(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:"mr-2",children:"Rows per page:"}),(0,r.jsxs)("div",{className:"relative inline-block",children:[(0,r.jsxs)("select",{value:y,onChange:e=>{k(parseInt(e.target.value,10)),w(1)},className:"py-1 pl-2 pr-6 appearance-none outline-none cursor-pointer border-none bg-transparent",style:{minWidth:"40px"},children:[(0,r.jsx)("option",{value:5,children:"5"}),(0,r.jsx)("option",{value:10,children:"10"}),(0,r.jsx)("option",{value:20,children:"20"}),(0,r.jsx)("option",{value:50,children:"50"})]}),(0,r.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 text-gray-500 absolute right-0 top-1/2 transform -translate-y-1/2 pointer-events-none",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]})]}),(0,r.jsxs)("div",{children:[A+1," – ",Math.min(Z,M.length)," of"," ",M.length]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)(o.z,{variant:"ghost",size:"icon",onClick:()=>{w(e=>Math.max(e-1,1))},disabled:1===v,className:"text-gray-500 h-8 w-8 p-0",children:(0,r.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"chevron-left",children:(0,r.jsx)("path",{d:"M15 18l-6-6 6-6"})})}),(0,r.jsx)(o.z,{variant:"ghost",size:"icon",onClick:()=>{w(e=>Math.min(e+1,P))},disabled:v===P||0===P,className:"text-gray-500 h-8 w-8 p-0",children:(0,r.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"chevron-right",children:(0,r.jsx)("path",{d:"M9 18l6-6-6-6"})})})]})]})})]})}function V(e){let{text:s,colSpan:t,innerRef:n}=e;return(0,r.jsx)(u.SC,{className:"expanded-details",children:(0,r.jsx)(u.pj,{colSpan:t,children:(0,r.jsx)("div",{className:"p-4 bg-gray-50 rounded-md border border-gray-200",ref:n,children:(0,r.jsx)("div",{className:"flex justify-between items-start",children:(0,r.jsxs)("div",{className:"flex-1",children:[(0,r.jsx)("p",{className:"text-sm font-medium text-gray-900",children:"Full Details"}),(0,r.jsx)("p",{className:"mt-1 text-sm text-gray-700",style:{whiteSpace:"pre-wrap"},children:s})]})})})})})}function $(e){let{text:s,rowId:t,expandedRowId:a,setExpandedRowId:l}=e,i=s||"",c=i.length>50,o=a===t,d=c?"".concat(i.substring(0,50)):i,u=(0,n.useRef)(null);return(0,r.jsxs)("div",{className:"truncated-details relative max-w-full flex items-center",children:[(0,r.jsx)("span",{className:"truncate",children:d}),c&&(0,r.jsx)("button",{ref:u,type:"button",onClick:e=>{e.preventDefault(),e.stopPropagation(),l(o?null:t)},className:"text-blue-600 hover:text-blue-800 font-medium ml-1 flex-shrink-0","data-button-type":"show-more-less",children:o?"... show less":"... show more"})]})}function Y(e){let{refreshInterval:s,setLoading:t,refreshDataRef:a}=e,[l,o]=(0,n.useState)([]),[x,p]=(0,n.useState)({key:null,direction:"ascending"}),[j,f]=(0,n.useState)(!1),[g,b]=(0,n.useState)(!0),[N,v]=(0,n.useState)(1),[w,y]=(0,n.useState)(10),k=n.useCallback(async()=>{f(!0),t(!0);try{let{pools:e=[]}=await M.ZP.get(m.vs,[{}])||{};o(e),b(!1)}catch(e){console.error("Error fetching pools data:",e),o([]),b(!1)}finally{f(!1),t(!1)}},[t]);n.useEffect(()=>{a&&(a.current=k)},[a,k]),(0,n.useEffect)(()=>{o([]);let e=!0;k();let t=setInterval(()=>{e&&"visible"===window.document.visibilityState&&k()},s);return()=>{e=!1,clearInterval(t)}},[s,k]);let C=e=>{let s="ascending";x.key===e&&"ascending"===x.direction&&(s="descending"),p({key:e,direction:s})},S=e=>x.key===e?"ascending"===x.direction?" ↑":" ↓":"",E=n.useMemo(()=>x.key?[...l].sort((e,s)=>e[x.key]<s[x.key]?"ascending"===x.direction?-1:1:e[x.key]>s[x.key]?"ascending"===x.direction?1:-1:0):l,[l,x]),L=Math.ceil(E.length/w),R=(N-1)*w,I=R+w,D=E.slice(R,I),P=e=>{if(!e||!e.replica_info||0===e.replica_info.length)return"0 (target: 0)";let s=e.replica_info.filter(e=>"READY"===e.status).length,t=e.target_num_replicas||0;return"".concat(s," (target: ").concat(t,")")},Z=e=>{let{jobCounts:s}=e;return(0,r.jsx)(h.x9,{jobCounts:s,getStatusStyle:_.Cl})},T=e=>{let{replicaInfo:s}=e;return(0,r.jsx)(h.Kl,{replicaInfo:s})};return(0,r.jsxs)(d.Zb,{children:[(0,r.jsx)("div",{className:"overflow-x-auto rounded-lg",children:(0,r.jsxs)(u.iA,{className:"min-w-full table-fixed",children:[(0,r.jsx)(u.xD,{children:(0,r.jsxs)(u.SC,{children:[(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap w-32",onClick:()=>C("name"),children:["Pool",S("name")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap w-40",onClick:()=>C("job_counts"),children:["Jobs",S("job_counts")]}),(0,r.jsx)(u.ss,{className:"whitespace-nowrap w-20",children:"Workers"}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap w-36",onClick:()=>C("requested_resources_str"),children:["Worker Details",S("requested_resources_str")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap w-40",onClick:()=>C("requested_resources_str"),children:["Worker Resources",S("requested_resources_str")]})]})}),(0,r.jsx)(u.RM,{children:j&&g?(0,r.jsx)(u.SC,{children:(0,r.jsx)(u.pj,{colSpan:5,className:"text-center py-6 text-gray-500",children:(0,r.jsxs)("div",{className:"flex justify-center items-center",children:[(0,r.jsx)(c.Z,{size:20,className:"mr-2"}),(0,r.jsx)("span",{children:"Loading..."})]})})}):D.length>0?D.map(e=>(0,r.jsxs)(u.SC,{children:[(0,r.jsx)(u.pj,{children:(0,r.jsx)(i(),{href:"/jobs/pools/".concat(e.name),className:"text-blue-600 hover:text-blue-800",children:e.name})}),(0,r.jsx)(u.pj,{children:(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,r.jsx)(Z,{jobCounts:e.jobCounts}),(0,r.jsx)(i(),{href:(0,A.P2)("/jobs","pool",":",e.name),className:"text-blue-600 hover:text-blue-800 text-xs",children:"See all jobs"})]})}),(0,r.jsx)(u.pj,{children:P(e)}),(0,r.jsx)(u.pj,{children:(0,r.jsx)(T,{replicaInfo:e.replica_info})}),(0,r.jsx)(u.pj,{children:e.requested_resources_str||"-"})]},e.name)):(0,r.jsx)(u.SC,{children:(0,r.jsx)(u.pj,{colSpan:5,className:"text-center py-6 text-gray-500",children:"No pools found"})})})]})}),D.length>0&&L>1&&(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-t border-gray-200",children:[(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)("span",{className:"text-sm text-gray-700",children:"Rows per page:"}),(0,r.jsxs)("select",{value:w,onChange:e=>{y(parseInt(e.target.value,10)),v(1)},className:"border border-gray-300 rounded px-2 py-1 text-sm",children:[(0,r.jsx)("option",{value:5,children:"5"}),(0,r.jsx)("option",{value:10,children:"10"}),(0,r.jsx)("option",{value:25,children:"25"}),(0,r.jsx)("option",{value:50,children:"50"})]})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:[R+1,"-",Math.min(I,E.length)," of"," ",E.length]}),(0,r.jsx)("button",{onClick:()=>{v(e=>Math.max(e-1,1))},disabled:1===N,className:"px-2 py-1 text-sm border border-gray-300 rounded disabled:opacity-50 disabled:cursor-not-allowed hover:bg-gray-50",children:"Previous"}),(0,r.jsx)("button",{onClick:()=>{v(e=>Math.min(e+1,L))},disabled:N===L,className:"px-2 py-1 text-sm border border-gray-300 rounded disabled:opacity-50 disabled:cursor-not-allowed hover:bg-gray-50",children:"Next"})]})]})]})}}}]);