"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2109],{16826:function(e,t,s){s.d(t,{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,s(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"}]])},2109:function(e,t,s){s.r(t),s.d(t,{ClusterJobs:function(){return W},ManagedJobs:function(){return U},ManagedJobsTable:function(){return O},Status2Actions:function(){return J},filterJobsByName:function(){return F},filterJobsByPool:function(){return z},filterJobsByUser:function(){return A},filterJobsByWorkspace:function(){return I},statusGroups:function(){return R}});var r=s(85893),a=s(67294),n=s(11163),l=s(41664),i=s.n(l),c=s(55739),o=s(30803),d=s(37673),u=s(68764),h=s(36989),x=s(51214),m=s(68969),p=s(6378);class j{_generateFilterKey(e){let{allUsers:t=!0,nameMatch:s,userMatch:r,workspaceMatch:a,poolMatch:n,statuses:l}=e;return["allUsers:".concat(t),s?"name:".concat(s):"",r?"user:".concat(r):"",a?"workspace:".concat(a):"",n?"pool:".concat(n):"",l&&l.length>0?"statuses:".concat(l.sort().join(",")):""].filter(Boolean).join("|")||"default"}_getCacheStatus(e){let t=this.fullDataCache.get(e),s=Date.now();if(!t)return{isCached:!1,isFresh:!1,age:0,maxAge:12e4,hasData:!1};let r=s-t.timestamp;return{isCached:!0,isFresh:r<12e4,age:r,maxAge:12e4,hasData:t.jobs&&Array.isArray(t.jobs),data:t}}async getPaginatedJobs(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{page:t=1,limit:s=10,...r}=e,a=this._generateFilterKey(r);try{let e=this._getCacheStatus(a);if(e.isCached&&e.hasData){let n=e.data;if(!n.jobs||Array.isArray(n.jobs)&&0===n.jobs.length){if(!this.prefetching.has(a)){let e=this._loadFullDataset(r,a).catch(()=>{}).finally(()=>this.prefetching.delete(a));this.prefetching.set(a,e)}}else{let l=(t-1)*s,i=n.jobs.slice(l,l+s);if(!this.prefetching.has(a)&&(!e.isFresh||e.age>e.maxAge/2)){let e=this._loadFullDataset(r,a).catch(()=>{}).finally(()=>this.prefetching.delete(a));this.prefetching.set(a,e)}return{jobs:i,total:n.total,totalNoFilter:n.totalNoFilter||n.total,controllerStopped:n.controllerStopped,statusCounts:n.statusCounts||{},fromCache:!0,cacheStatus:e.isFresh?"local_cache_hit":"local_cache_stale_hit"}}}let n=await p.default.get(m.getManagedJobs,[{...r,page:t,limit:s}]),l=(null==n?void 0:n.jobs)||[],i="number"==typeof(null==n?void 0:n.total)?n.total:l.length,c=!!(null==n?void 0:n.controllerStopped);if(!this.prefetching.has(a)){let e=this._loadFullDataset(r,a).catch(e=>{console.warn("Background prefetch of full jobs failed:",e)}).finally(()=>{this.prefetching.delete(a)});this.prefetching.set(a,e)}return{jobs:l,total:i,totalNoFilter:(null==n?void 0:n.totalNoFilter)||i,controllerStopped:c,statusCounts:(null==n?void 0:n.statusCounts)||{},fromCache:!1,cacheStatus:"server_page_fetch"}}catch(e){throw console.error("Error in getPaginatedJobs:",e),e}}async _loadFullDataset(e,t){let s=await p.default.get(m.getManagedJobs,[e]);if(s&&s.__skipCache||s.controllerStopped||!s.jobs)return s;let r={jobs:s.jobs,total:s.jobs.length,totalNoFilter:s.totalNoFilter||s.jobs.length,controllerStopped:!1,statusCounts:s.statusCounts||{},timestamp:Date.now()};return this.fullDataCache.set(t,r),r}isDataLoading(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this._generateFilterKey(e);return this.isLoading.has(t)||this.prefetching.has(t)}isDataCached(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this._generateFilterKey(e),s=this._getCacheStatus(t);return s.isCached&&s.isFresh&&s.hasData}getCacheStatus(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this._generateFilterKey(e);return this._getCacheStatus(t)}invalidateCache(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(e){let t=this._generateFilterKey(e);this.fullDataCache.delete(t),this.isLoading.delete(t),this.prefetching.delete(t)}else this.fullDataCache.clear(),this.isLoading.clear(),this.prefetching.clear();p.default.invalidateFunction(m.getManagedJobs)}getCacheStats(){let e={cachedFilters:Array.from(this.fullDataCache.keys()),loadingFilters:Array.from(this.isLoading.keys()),prefetchingFilters:Array.from(this.prefetching.keys()),cacheSize:this.fullDataCache.size,loadingCount:this.isLoading.size,prefetchingCount:this.prefetching.size};for(let[t,s]of(e.detailedStatus={},this.fullDataCache.entries())){let r=this._getCacheStatus(t);e.detailedStatus[t]={age:r.age,isFresh:r.isFresh,hasData:r.hasData,jobCount:s.jobs?s.jobs.length:0}}return e}constructor(){this.fullDataCache=new Map,this.isLoading=new Map,this.prefetching=new Map}}let f=new j;var g=s(23266),b=s(17324),v=s(13626),y=s(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,y.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"}]]),N=(0,y.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=s(16826),C=s(92128),S=s(94545),L=s(99307),_=s(20546),E=s(23001),M=s(10546);let R={active:["PENDING","RUNNING","RECOVERING","SUBMITTED","STARTING","CANCELLING"],finished:["SUCCEEDED","FAILED","CANCELLED","FAILED_SETUP","FAILED_PRECHECKS","FAILED_NO_RESOURCE","FAILED_CONTROLLER"]},D=[{label:"Name",value:"name"},{label:"User",value:"user"},{label:"Workspace",value:"workspace"},{label:"Pool",value:"pool"}];function F(e,t){if(!t||""===t.trim())return e;let s=t.toLowerCase().trim();return e.filter(e=>(e.name||"").toLowerCase().includes(s))}function I(e,t){return t&&"ALL_WORKSPACES"!==t?e.filter(e=>(e.workspace||"default").toLowerCase()===t.toLowerCase()):e}function A(e,t){return t&&"ALL_USERS"!==t?e.filter(e=>(e.user_hash||e.user)===t):e}function z(e,t){if(!t||""===t.trim())return e;let s=t.toLowerCase().trim();return e.filter(e=>(e.pool||"").toLowerCase().includes(s))}let P=e=>{if(!e)return"-";let t=e instanceof Date?e:new Date(1e3*e);return(0,r.jsx)(h.Zg,{date:t})};function U(){let e=(0,n.useRouter)(),[t,s]=(0,a.useState)(!1),[l,c]=(0,a.useState)(!0),[o,d]=(0,a.useState)(!0),u=a.useRef(null),x=a.useRef(null),[j,g]=(0,a.useState)([]),[v,y]=(0,a.useState)([]),[w,N]=(0,a.useState)({name:[],user:[],workspace:[],pool:[]}),k=a.useCallback(async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];s(!0),!e&&o&&c(!0);try{let[e]=await Promise.all([p.default.get(m.vs,[{}])]);g(e.pools||[])}catch(e){console.error("Error fetching data:",e)}finally{s(!1),!e&&o&&(c(!1),d(!1))}},[o]);(0,a.useEffect)(()=>{k()},[k]);let C=t=>{(0,M.eG)(e,t)},S=a.useCallback(()=>{let t=new Map;t.set("",""),t.set("status","Status"),t.set("name","Name"),t.set("user","User"),t.set("workspace","Workspace"),t.set("pool","Pool"),y((0,M.Fu)(e,t))},[e,y]);return(0,a.useEffect)(()=>{e.isReady&&S()},[e.isReady,e.query.tab,S]),(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)(M.ML,{propertyList:D,valueList:w,setFilters:y,updateURLParams:C,placeholder:"Filter jobs"})})]}),(0,r.jsx)(M.x$,{filters:v,setFilters:y,updateURLParams:C}),(0,r.jsx)(O,{refreshInterval:h.yc,setLoading:s,refreshDataRef:u,filters:v,onRefresh:()=>{f.invalidateCache(),p.default.invalidate(m.vs,[{}]),p.default.invalidate(b.getWorkspaces),u.current&&u.current(),x.current&&x.current()},poolsData:j,poolsLoading:l,setValueList:N}),(0,r.jsx)("div",{className:"mb-4",children:(0,r.jsx)(B,{refreshInterval:h.yc,setLoading:s,refreshDataRef:x})})]})}function O(e){let{refreshInterval:t,setLoading:s,refreshDataRef:n,filters:l,onRefresh:j,poolsData:b,poolsLoading:y,setValueList:N}=e,[k,M]=(0,a.useState)([]),[D,F]=(0,a.useState)(0),[I,A]=(0,a.useState)(0),[z,U]=(0,a.useState)({key:null,direction:"ascending"}),[O,W]=(0,a.useState)(!1),[B,q]=(0,a.useState)(!0),[H,G]=(0,a.useState)(1),[K,V]=(0,a.useState)(10),[Y,$]=(0,a.useState)(null),Q=(0,a.useRef)(null),[X,ee]=(0,a.useState)([]),[et,es]=(0,a.useState)({}),[er,ea]=(0,a.useState)({}),[en,el]=(0,a.useState)(!1),[ei,ec]=(0,a.useState)(!1),[eo,ed]=(0,a.useState)(!1),[eu,eh]=(0,a.useState)("all"),[ex,em]=(0,a.useState)(!0),[ep,ej]=(0,a.useState)({isOpen:!1,title:"",message:"",onConfirm:null}),ef=(0,E.X)(),eg=(0,a.useRef)(0),eb=a.useMemo(()=>{if(!k||0===k.length)return!1;let e=new Set(k.map(e=>e.workspace||"default"));return e.size>1||1===e.size&&!e.has("default")},[k]),ev=a.useMemo(()=>b&&b.length>0,[b]),ey=async()=>{ej({isOpen:!0,title:"Restart Controller",message:"Are you sure you want to restart the controller?",onConfirm:async()=>{try{ed(!0),W(!0),await (0,m.Ce)("restartcontroller"),await ew()}catch(e){console.error("Error restarting controller:",e)}finally{ed(!1),W(!1)}}})},ew=a.useCallback(async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=!1!==e.includeStatus,r=eg.current+1;eg.current=r,W(!0),s(!0);try{let e;let s=e=>{let t=(l||[]).find(t=>(t.property||"").toLowerCase()===e);return t&&t.value?String(t.value):void 0};X.length>0?e=X:ex?"active"===eu?e=R.active:"finished"===eu&&(e=R.finished):e=[];let a={allUsers:!0,nameMatch:s("name"),userMatch:s("user"),workspaceMatch:s("workspace"),poolMatch:s("pool"),statuses:e,page:H,limit:K},n=null;if(f.isDataCached(a),f.isDataLoading(a),t)try{n=await p.default.get(g.getClusters)}catch(e){console.error("Error fetching clusters:",e)}let{jobs:i=[],total:c=0,totalNoFilter:o=0,controllerStopped:d=!1,cacheStatus:u="unknown",statusCounts:h={}}=await f.getPaginatedJobs(a)||{},x=!1,m=!1;if(t&&n){let e=null==n?void 0:n.find(e=>(0,S.Ym)(e.cluster)),t=e?e.status:"NOT_FOUND";"STOPPED"==t&&d&&(x=!0),"LAUNCHING"==t&&(m=!0)}r===eg.current&&(M(i),F(c||0),A(o||0),el(!!x),ec(!!m),ea(h),q(!1))}catch(e){console.error("Error fetching data:",e),r===eg.current&&(M([]),el(!1),q(!1))}finally{r===eg.current&&(W(!1),s(!1))}},[s,l,H,K,X,ex,eu]);a.useEffect(()=>{n&&(n.current=ew)},[n,ew]);let eN=a.useRef(ew);a.useEffect(()=>{eN.current=ew},[ew]);let ek=a.useRef(!0);a.useEffect(()=>{ew({includeStatus:!0}),ek.current=!1},[ew]),a.useEffect(()=>{ek.current||ew({includeStatus:!1})},[H,ew]),a.useEffect(()=>{ek.current||ew({includeStatus:!0})},[l,K,ew]),a.useEffect(()=>{ek.current||ew({includeStatus:!0})},[eu,X,ex,ew]),(0,a.useEffect)(()=>{let e=setInterval(()=>{eN.current&&"visible"===window.document.visibilityState&&eN.current({includeStatus:!0})},t);return()=>{clearInterval(e)}},[t]),(0,a.useEffect)(()=>{G(1)},[eu]),(0,a.useEffect)(()=>{G(1)},[l,K]),(0,a.useEffect)(()=>{ee([]),em(!0)},[eu]),(0,a.useEffect)(()=>{if(!N)return;let e=new Set,t=new Set,s=new Set,r=new Set;k.forEach(a=>{a.name&&e.add(a.name),a.user&&t.add(a.user),a.workspace&&s.add(a.workspace),a.pool&&r.add(a.pool)}),b&&Array.isArray(b)&&b.forEach(e=>{if(!e.name)return;let t=e.jobCounts&&Object.keys(e.jobCounts).length>0,s=null!==e.uptime&&void 0!==e.uptime&&e.uptime>0&&e.uptime<86400;(t||s)&&r.add(e.name)}),N({name:Array.from(e).sort(),user:Array.from(t).sort(),workspace:Array.from(s).sort(),pool:Array.from(r).sort()})},[k,b,N]);let eC=e=>{let t="ascending";z.key===e&&"ascending"===z.direction&&(t="descending"),U({key:e,direction:t})},eS=e=>z.key===e?"ascending"===z.direction?" ↑":" ↓":"";a.useMemo(()=>{let e=k||[];return{active:e.filter(e=>R.active.includes(e.status)).length,finished:e.filter(e=>R.finished.includes(e.status)).length}},[k]);let eL=e=>X.length>0?X.includes(e):"all"===eu||R[eu].includes(e),e_=a.useMemo(()=>k,[k]),eE=a.useMemo(()=>z.key?[...e_].sort((e,t)=>e[z.key]<t[z.key]?"ascending"===z.direction?-1:1:e[z.key]>t[z.key]?"ascending"===z.direction?1:-1:0):e_,[e_,z]),eM=(H-1)*K,eR=D>0?Math.ceil(D/K):0,eD=D>0?Math.min(eM+eE.length,D):0,eF=e=>{if(X.includes(e)){let t=X.filter(t=>t!==e);0===t.length?(em(!0),ee([])):(ee(t),em(!1))}else ee([...X,e]),em(!1);G(1)};return(0,a.useEffect)(()=>{es(er)},[er]),(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 flex-wrap items-center justify-between text-sm mb-1",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center",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:[!O&&0===I&&!B&&(0,r.jsx)("span",{className:"text-gray-500 mr-2",children:"No jobs found"}),Object.entries(et).map(e=>{let[t,s]=e;return(0,r.jsxs)("button",{onClick:()=>eF(t),className:"px-3 py-0.5 rounded-full flex items-center space-x-2 ".concat(eL(t)||X.includes(t)?(0,L.Cl)(t):"bg-gray-50 text-gray-600 hover:bg-gray-100"),children:[(0,r.jsx)("span",{children:t}),(0,r.jsx)("span",{className:"text-xs ".concat(eL(t)||X.includes(t)?"bg-white/50":"bg-gray-200"," px-1.5 py-0.5 rounded"),children:s})]},t)}),I>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:()=>{a.startTransition(()=>{eh("all"),ee([]),em(!0),G(1)})},className:"text-sm font-medium ".concat("all"===eu&&ex?"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:()=>{a.startTransition(()=>{eh("active"),ee([]),em(!0),G(1)})},className:"text-sm font-medium ".concat("active"===eu&&ex?"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:()=>{a.startTransition(()=>{eh("finished"),ee([]),em(!0),G(1)})},className:"text-sm font-medium ".concat("finished"===eu&&ex?"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",children:[O&&(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..."})]}),(0,r.jsxs)("button",{onClick:()=>{j&&j()},disabled:O,className:"text-sky-blue hover:text-sky-blue-bright flex items-center text-sm",children:[(0,r.jsx)(v.Z,{className:"h-4 w-4 mr-1.5"}),(0,r.jsx)("span",{children:"Refresh"})]})]})]})}),ef&&en&&0===eE.length&&!O&&!B&&(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:ey,className:"text-sky-blue hover:text-sky-blue-bright",disabled:O||eo,children:eo?(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,{children:(0,r.jsx)("div",{className:"overflow-x-auto rounded-lg",children:(0,r.jsxs)(u.iA,{className:"min-w-full",children:[(0,r.jsx)(u.xD,{children:(0,r.jsxs)(u.SC,{children:[(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>eC("id"),children:["ID",eS("id")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>eC("name"),children:["Name",eS("name")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>eC("user"),children:["User",eS("user")]}),eb&&(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>eC("workspace"),children:["Workspace",eS("workspace")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>eC("submitted_at"),children:["Submitted",eS("submitted_at")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>eC("job_duration"),children:["Duration",eS("job_duration")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>eC("status"),children:["Status",eS("status")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>eC("infra"),children:["Infra",eS("infra")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>eC("cluster"),children:["Resources",eS("cluster")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>eC("recoveries"),children:["Recoveries",eS("recoveries")]}),ev&&(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>eC("pool"),children:["Pool",eS("pool")]}),(0,r.jsx)(u.ss,{children:"Details"}),(0,r.jsx)(u.ss,{children:"Logs"})]})}),(0,r.jsx)(u.RM,{children:O&&B?(0,r.jsx)(u.SC,{children:(0,r.jsx)(u.pj,{colSpan:11+(eb?1:0)+(ev?1:0),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..."})]})})}):eE.length>0?(0,r.jsx)(r.Fragment,{children:eE.map(e=>(0,r.jsxs)(a.Fragment,{children:[(0,r.jsxs)(u.SC,{children:[(0,r.jsx)(u.pj,{children:(0,r.jsx)(i(),{href:"/jobs/".concat(e.id),className:"text-blue-600",children:e.id})}),(0,r.jsx)(u.pj,{children:(0,r.jsx)(i(),{href:"/jobs/".concat(e.id),className:"text-blue-600",children:e.name})}),(0,r.jsx)(u.pj,{children:(0,r.jsx)(_.H,{username:e.user,userHash:e.user_hash})}),eb&&(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"})}),(0,r.jsx)(u.pj,{children:P(e.submitted_at)}),(0,r.jsx)(u.pj,{children:(0,h.LU)(e.job_duration)}),(0,r.jsx)(u.pj,{children:(0,r.jsx)(L.OE,{status:e.status})}),(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 t=x.MO.NAME_TRUNCATE_LENGTH,s=e.infra.substring(e.infra.indexOf("(")),r=s.substring(1,s.length-1);if(r.length<=t)return s;let a="".concat(r.substring(0,Math.floor((t-3)/2)),"...").concat(r.substring(r.length-Math.ceil((t-3)/2)));return"(".concat(a,")")})()})]})}):(0,r.jsx)("span",{children:e.infra||"-"})}),(0,r.jsx)(u.pj,{children:(0,r.jsx)(h.Md,{content:e.resources_str_full||e.resources_str,className:"text-sm text-muted-foreground",children:(0,r.jsx)("span",{children:e.resources_str})})}),(0,r.jsx)(u.pj,{children:e.recoveries}),ev&&(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,b)})}),(0,r.jsx)(u.pj,{children:e.details?(0,r.jsx)(T,{text:e.details,rowId:e.id,expandedRowId:Y,setExpandedRowId:$}):"-"}),(0,r.jsx)(u.pj,{children:(0,r.jsx)(J,{jobParent:"/jobs",jobId:e.id,managed:!0,workspace:e.workspace})})]}),Y===e.id&&(0,r.jsx)(Z,{text:e.details,colSpan:11+(eb?1:0)+(ev?1:0),innerRef:Q})]},e.task_job_id))}):(0,r.jsx)(u.SC,{children:(0,r.jsx)(u.pj,{colSpan:11+(eb?1:0)+(ev?1:0),className:"text-center py-6",children:(0,r.jsxs)("div",{className:"flex flex-col items-center space-y-4",children:[ei&&(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..."})]})]}),!en&&!ei&&(0,r.jsx)("p",{className:"text-gray-500",children:"No active jobs"}),!ef&&en&&(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:ey,className:"text-sky-blue hover:text-sky-blue-bright",disabled:O||eo,children:eo?(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:"Rows per page:"}),(0,r.jsxs)("div",{className:"relative inline-block",children:[(0,r.jsxs)("select",{value:K,onChange:e=>{V(parseInt(e.target.value,10)),G(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:D>0?"".concat(eM+1," – ").concat(eD," of ").concat(D):"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:()=>{G(e=>Math.max(e-1,1))},disabled:1===H||!eE||0===eE.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:()=>{eR>0&&H<eR&&G(e=>e+1)},disabled:0===eR||H>=eR||!eE||0===eE.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:ep.isOpen,onClose:()=>ej({...ep,isOpen:!1}),onConfirm:ep.onConfirm,title:ep.title,message:ep.message,confirmClassName:"bg-blue-600 hover:bg-blue-700 text-white"})]})}function J(e){let{withLabel:t=!1,jobParent:s,jobId:a,managed:l,workspace:i="default"}=e,c=(0,n.useRouter)(),o=(e,t)=>{e.preventDefault(),e.stopPropagation(),c.push({pathname:"".concat(s,"/").concat(a),query:{tab:t}})},d=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(e.preventDefault(),e.stopPropagation(),l)(0,m.jh)({jobId:parseInt(a),controller:t});else{let e=s.match(/\/clusters\/(.+)/);if(e){let t=e[1];(0,g.GH)({clusterName:t,jobIds:[a],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)(N,{className:"w-4 h-4"}),t&&(0,r.jsx)("span",{className:"ml-1.5",children:"Logs"})]})},"logs"),(0,r.jsx)(h.WH,{content:"Download Job Logs",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"}),t&&(0,r.jsx)("span",{className:"ml-1.5",children:"Download"})]})},"downloadlogs")]})}function W(e){let{clusterName:t,clusterJobData:s,loading:n,refreshClusterJobsOnly:l,userFilter:x=null,nameFilter:m=null,workspace:p="default"}=e,[j,f]=(0,a.useState)(null),[g,b]=(0,a.useState)({key:null,direction:"ascending"}),[y,w]=(0,a.useState)(1),[N,k]=(0,a.useState)(10),C=(0,a.useRef)(null),[S,E]=(0,a.useState)(null);(0,a.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 M=a.useMemo(()=>{let e=s||[];return x&&"ALL_USERS"!==x&&(e=A(e,x)),m&&(e=F(e,m)),e},[s,x,m]);(0,a.useEffect)(()=>{JSON.stringify(s)!==JSON.stringify(S)&&E(s)},[s,S]);let R=a.useMemo(()=>g.key?[...M].sort((e,t)=>e[g.key]<t[g.key]?"ascending"===g.direction?-1:1:e[g.key]>t[g.key]?"ascending"===g.direction?1:-1:0):M,[M,g]),D=e=>{let t="ascending";g.key===e&&"ascending"===g.direction&&(t="descending"),b({key:e,direction:t})},I=e=>g.key===e?"ascending"===g.direction?" ↑":" ↓":"",z=Math.ceil(R.length/N),U=(y-1)*N,O=U+N,W=R.slice(U,O);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:n,className:"text-sky-blue hover:text-sky-blue-bright font-medium inline-flex items-center text-sm ml-2",children:[(0,r.jsx)(v.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:()=>D("id"),children:["ID",I("id")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>D("job"),children:["Name",I("job")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>D("user"),children:["User",I("user")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>D("submitted_at"),children:["Submitted",I("submitted_at")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>D("job_duration"),children:["Duration",I("job_duration")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>D("status"),children:["Status",I("status")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap",onClick:()=>D("resources"),children:["Resources",I("resources")]}),(0,r.jsx)(u.ss,{className:"whitespace-nowrap",children:"Logs"})]})}),(0,r.jsx)(u.RM,{children:n?(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..."})]})})}):W.length>0?W.map(e=>(0,r.jsxs)(a.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(t,"/").concat(e.id),className:"text-blue-600",children:e.id})}),(0,r.jsx)(u.pj,{children:(0,r.jsx)(i(),{href:"/clusters/".concat(t,"/").concat(e.id),className:"text-blue-600",children:(0,r.jsx)(T,{text:e.job||"Unnamed job",rowId:e.id,expandedRowId:j,setExpandedRowId:f})})}),(0,r.jsx)(u.pj,{children:(0,r.jsx)(_.H,{username:e.user,userHash:e.user_hash})}),(0,r.jsx)(u.pj,{children:P(e.submitted_at)}),(0,r.jsx)(u.pj,{children:(0,h.LU)(e.job_duration)}),(0,r.jsx)(u.pj,{children:(0,r.jsx)(L.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(t),jobId:e.id,managed:!1,workspace:p})})]}),j===e.id&&(0,r.jsx)(Z,{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"})})})]})]}),R&&R.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:N,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:[U+1," – ",Math.min(O,R.length)," of"," ",R.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===y,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,z))},disabled:y===z||0===z,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 Z(e){let{text:t,colSpan:s,innerRef:a}=e;return(0,r.jsx)(u.SC,{className:"expanded-details",children:(0,r.jsx)(u.pj,{colSpan:s,children:(0,r.jsx)("div",{className:"p-4 bg-gray-50 rounded-md border border-gray-200",ref:a,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:t})]})})})})})}function T(e){let{text:t,rowId:s,expandedRowId:n,setExpandedRowId:l}=e,i=t||"",c=i.length>50,o=n===s,d=c?"".concat(i.substring(0,50)):i,u=(0,a.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:s)},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 B(e){let{refreshInterval:t,setLoading:s,refreshDataRef:n}=e,[l,o]=(0,a.useState)([]),[x,j]=(0,a.useState)({key:null,direction:"ascending"}),[f,g]=(0,a.useState)(!1),[b,v]=(0,a.useState)(!0),[y,w]=(0,a.useState)(1),[N,k]=(0,a.useState)(10),C=a.useCallback(async()=>{g(!0),s(!0);try{let{pools:e=[]}=await p.default.get(m.vs,[{}])||{};o(e),v(!1)}catch(e){console.error("Error fetching pools data:",e),o([]),v(!1)}finally{g(!1),s(!1)}},[s]);a.useEffect(()=>{n&&(n.current=C)},[n,C]),(0,a.useEffect)(()=>{o([]);let e=!0;C();let s=setInterval(()=>{e&&"visible"===window.document.visibilityState&&C()},t);return()=>{e=!1,clearInterval(s)}},[t,C]);let S=e=>{let t="ascending";x.key===e&&"ascending"===x.direction&&(t="descending"),j({key:e,direction:t})},_=e=>x.key===e?"ascending"===x.direction?" ↑":" ↓":"",E=a.useMemo(()=>x.key?[...l].sort((e,t)=>e[x.key]<t[x.key]?"ascending"===x.direction?-1:1:e[x.key]>t[x.key]?"ascending"===x.direction?1:-1:0):l,[l,x]),R=Math.ceil(E.length/N),D=(y-1)*N,F=D+N,I=E.slice(D,F),A=e=>{if(!e||!e.replica_info||0===e.replica_info.length)return"0 (target: 0)";let t=e.replica_info.filter(e=>"READY"===e.status).length,s=e.target_num_replicas||0;return"".concat(t," (target: ").concat(s,")")},z=e=>{let{jobCounts:t}=e;return(0,r.jsx)(h.x9,{jobCounts:t,getStatusStyle:L.Cl})},P=e=>{let{replicaInfo:t}=e;return(0,r.jsx)(h.Kl,{replicaInfo:t})};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:()=>S("name"),children:["Pool",_("name")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap w-40",onClick:()=>S("job_counts"),children:["Jobs",_("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:()=>S("requested_resources_str"),children:["Worker Details",_("requested_resources_str")]}),(0,r.jsxs)(u.ss,{className:"sortable whitespace-nowrap w-40",onClick:()=>S("requested_resources_str"),children:["Worker Resources",_("requested_resources_str")]})]})}),(0,r.jsx)(u.RM,{children:f&&b?(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..."})]})})}):I.length>0?I.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,M.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:A(e)}),(0,r.jsx)(u.pj,{children:(0,r.jsx)(P,{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"})})})]})}),I.length>0&&R>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:N,onChange:e=>{k(parseInt(e.target.value,10)),w(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:[D+1,"-",Math.min(F,E.length)," of"," ",E.length]}),(0,r.jsx)("button",{onClick:()=>{w(e=>Math.max(e-1,1))},disabled:1===y,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:()=>{w(e=>Math.min(e+1,R))},disabled:y===R,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"})]})]})]})}},10546:function(e,t,s){s.d(t,{Fu:function(){return o},ML:function(){return u},P2:function(){return d},cm:function(){return i},eG:function(){return c},x$:function(){return h}});var r=s(85893),a=s(67294),n=s(88950);let l=(e,t)=>{var s;let{property:r,operator:a,value:n}=t;if(!n)return!0;if(!r){let t=n.toLowerCase();return Object.values(e).some(e=>null==e?void 0:e.toString().toLowerCase().includes(t))}let l=null===(s=e[r.toLowerCase()])||void 0===s?void 0:s.toString().toLowerCase(),i=n.toString().toLowerCase();switch(a){case"=":return l===i;case":":return null==l?void 0:l.includes(i);default:return!0}},i=(e,t)=>0===t.length?e:e.filter(e=>{let s=null;for(let r=0;r<t.length;r++){let a=l(e,t[r]);s=null===s?a:s&&a}return s}),c=(e,t)=>{let s={...e.query},r=[],a=[],n=[];t.map((e,t)=>{var s;r.push(null!==(s=e.property.toLowerCase())&&void 0!==s?s:""),a.push(e.operator),n.push(e.value)}),s.property=r,s.operator=a,s.value=n,e.replace({pathname:e.pathname,query:s},void 0,{shallow:!0})},o=(e,t)=>{let s={...e.query},r=s.property,a=s.operator,n=s.value;if(void 0===r)return[];let l=[],i=Array.isArray(r)?r.length:1;if(1===i)l.push({property:t.get(r),operator:a,value:n});else for(let e=0;e<i;e++)l.push({property:t.get(r[e]),operator:a[e],value:n[e]});return l},d=(e,t,s,r)=>{if(!r)return e;let a=new URLSearchParams({property:t.toLowerCase(),operator:s,value:r});return"".concat(e,"?").concat(a.toString())},u=e=>{var t,s;let{propertyList:l=[],valueList:i,setFilters:c,updateURLParams:o,placeholder:d="Filter items"}=e,u=(0,a.useRef)(null),h=(0,a.useRef)(null),[x,m]=(0,a.useState)(!1),[p,j]=(0,a.useState)(""),[f,g]=(0,a.useState)((null===(t=l[0])||void 0===t?void 0:t.value)||"status"),[b,v]=(0,a.useState)([]);(0,a.useEffect)(()=>{let e=e=>{h.current&&!h.current.contains(e.target)&&u.current&&!u.current.contains(e.target)&&m(!1)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[]),(0,a.useEffect)(()=>{let e=[];i&&"object"==typeof i&&(e=i[f]||[]),""!==p.trim()&&(e=e.filter(e=>e&&e.toString().toLowerCase().includes(p.toLowerCase()))),v(e)},[f,i,p]);let y=e=>{let t=l.find(t=>t.value===e);return t?t.label:e},w=e=>{c(t=>{let s=[...t,{property:y(f),operator:":",value:e}];return o(s),s}),m(!1),j(""),u.current.focus()};return(0,r.jsxs)("div",{className:"flex flex-row border border-gray-300 rounded-md overflow-visible bg-white",children:[(0,r.jsx)("div",{className:"border-r border-gray-300 flex-shrink-0",children:(0,r.jsxs)(n.Ph,{onValueChange:g,value:f,children:[(0,r.jsx)(n.i4,{"aria-label":"Filter Property",className:"focus:ring-0 focus:ring-offset-0 border-none rounded-l-md rounded-r-none w-20 sm:w-24 md:w-32 h-8 text-xs sm:text-sm bg-white",children:(0,r.jsx)(n.ki,{placeholder:(null===(s=l[0])||void 0===s?void 0:s.label)||"Status"})}),(0,r.jsx)(n.Bw,{children:l.map((e,t)=>(0,r.jsx)(n.Ql,{value:e.value,children:e.label},"property-item-".concat(t)))})]})}),(0,r.jsxs)("div",{className:"relative flex-1",children:[(0,r.jsx)("input",{type:"text",ref:u,placeholder:d,value:p,onChange:e=>{j(e.target.value),x||m(!0)},onFocus:()=>{m(!0)},onKeyDown:e=>{"Enter"===e.key&&""!==p.trim()?(c(e=>{let t=[...e,{property:y(f),operator:":",value:p}];return o(t),t}),j(""),m(!1)):"Escape"===e.key&&(m(!1),u.current.blur())},className:"h-8 w-full px-3 pr-8 text-sm border-none rounded-l-none rounded-r-md focus:ring-0 focus:outline-none",autoComplete:"off"}),p&&(0,r.jsx)("button",{onClick:()=>{j(""),m(!1)},className:"absolute right-2 top-1/2 transform -translate-y-1/2 text-gray-400 hover:text-gray-600",title:"Clear filter",tabIndex:-1,children:(0,r.jsx)("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),x&&b.length>0&&(0,r.jsx)("div",{ref:h,className:"absolute z-50 mt-1 w-full bg-white border border-gray-200 rounded-md shadow-lg max-h-60 overflow-y-auto",style:{zIndex:9999},children:b.map((e,t)=>(0,r.jsx)("div",{className:"px-3 py-2 cursor-pointer hover:bg-gray-50 text-sm ".concat(t!==b.length-1?"border-b border-gray-100":""),onClick:()=>w(e),children:(0,r.jsx)("span",{className:"text-sm text-gray-700",children:e})},"".concat(e,"-").concat(t)))})]})]})},h=e=>{let{filters:t=[],setFilters:s,updateURLParams:a}=e,n=e=>{s(t=>{let s=t.filter((t,s)=>s!==e);return a(s),s})};return(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("div",{className:"flex items-center gap-4 py-2 px-2",children:(0,r.jsxs)("div",{className:"flex flex-wrap items-content gap-2",children:[t.map((e,t)=>(0,r.jsx)(x,{filter:e,onRemove:()=>n(t)},"filteritem-".concat(t))),t.length>0&&(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("button",{onClick:()=>{a([]),s([])},className:"rounded-full px-4 py-1 text-sm text-gray-700 bg-gray-200 hover:bg-gray-300",children:"Clear filters"})})]})})})},x=e=>{let{filter:t,onRemove:s}=e;return(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)("div",{className:"flex items-center text-blue-600 bg-blue-100 px-1 py-1 rounded-full text-sm",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1 px-2",children:[(0,r.jsx)("span",{children:"".concat(t.property," ")}),(0,r.jsx)("span",{children:"".concat(t.operator," ")}),(0,r.jsx)("span",{children:" ".concat(t.value)})]}),(0,r.jsx)("button",{onClick:()=>s(),className:"p-0.5 ml-1 transform text-gray-400 hover:text-gray-600 bg-blue-500 hover:bg-blue-600 rounded-full flex flex-col items-center",title:"Clear filter",children:(0,r.jsx)("svg",{className:"h-3 w-3",fill:"none",stroke:"white",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:5,d:"M6 18L18 6M6 6l12 12"})})})]})})}}}]);