import{bJ as z,r as d,s as S,j as e,B as c,b as f,d as _,b$ as s,c as I,cE as G,aO as B,bU as H,at as $,e as P,C as D,bn as V,bx as q,b0 as J,az as Q,fG as K,g1 as U,L as W,b5 as X,eb as E,cG as Z,be as ee,c7 as se,b4 as te,by as ne,c5 as re}from"./index-C1DmWO_C.js";import{u as oe}from"./useProjectId-Cio5B8Wh.js";import{m as le}from"./index-DMOJMCC5.js";import{s as R}from"./styles-BgZBk63V.js";import{s as N,M as n,f as ie,a as ae}from"./utils-D7UIIKBL.js";import{H as ce}from"./LoadMore-ramCqe-V.js";const F=["name","latest version","author","deployed versions","description",""],de=({isFiltered:x,data:h,deployments:m,hasMore:g,isFetchingMore:y,loadMore:l=()=>{}})=>{const r=z(),C=h.length>0||x,j=d.useCallback(t=>()=>{r(S.models.overview,{mId:t})},[r]),p=d.useCallback((t,o)=>()=>{r(S.models.versionView,{mId:t,vId:o})},[r]);return e.jsxs(c,{flexDirection:"column",flex:"1 1 100%",children:[C&&e.jsx(c,{mb:"12px",justifyContent:"space-between",alignItems:"center",children:e.jsxs(c,{alignItems:"center",children:[e.jsx(f,{primary:!0,children:h.length}),e.jsx(f,{px:"5px",children:"models"})]})}),e.jsx(_,{children:e.jsxs(s,{standalone:!0,legend:F,middleColumn:F.indexOf("description"),children:[h.map(({id:t,name:o,version:a,userFullName:L,description:w})=>{const[k,M]=L.split(" ");return e.jsxs(s.Row,{children:[e.jsx(s.Cell,{children:e.jsx(I,{bold:!0,sx:{cursor:"pointer",":hover":{textDecoration:"underline"}},onClick:j(o),children:o})}),e.jsx(s.Cell,{children:e.jsx(f,{primary:!0,onClick:p(o,a.toString()),sx:{textDecoration:"underline",cursor:"pointer"},children:a})}),e.jsx(s.Cell,{children:e.jsx(_,{width:"32px",ml:"auto",mr:"auto",children:e.jsx(G,{firstName:k,lastName:M})})}),e.jsx(s.Cell,{children:e.jsx(c,{alignItems:"center",color:"labels.green",children:B(m.filter(i=>i.modelName===o).map(i=>i.modelVersion)).sort().map(i=>e.jsx(f,{mr:"4px",sx:{textDecoration:"underline",cursor:"pointer"},primary:!0,onClick:p(o,i.toString()),children:i},i))})}),e.jsx(s.Cell,{sx:{maxWidth:"400px"},children:e.jsx(I,{sx:{...H},gray:!0,children:w??"-"})}),e.jsx(s.Cell,{children:e.jsx($,{mainText:"Overview",children:e.jsx(P,{icon:D.more_zoom,onClick:j(o)})})})]},t)}),y&&e.jsx(s.Row,{children:e.jsx(s.Cell,{flex:1,colSpan:"6",children:e.jsx(V,{fontSize:"30px",color:"black"})})}),g&&!y&&e.jsx(s.Row,{children:e.jsx(s.Cell,{flex:1,colSpan:"6",children:e.jsx(ce,{onLoadMore:l})})})]})})]})},je=()=>{q(ne.mregistry);const[x,h]=d.useState(""),m=J(x,300),[g,y]=d.useState(Object.keys(N)[0]),[l,r]=d.useState(n.ALL),{data:{firstname:C,lastname:j}={}}=Q(),p=oe(),{data:t}=K({projectId:p,status:"Running"}),o=d.useMemo(()=>({pId:p,params:{filter_by:["latest_version",...m?[`NAME_LIKE:${m}`]:[]],sort_by:N[g]}}),[m,p,g]),{data:a,isFetching:L,isLoading:w,refetch:k,hasMore:M,loadMore:i,isFetchingMore:Y}=U({api:le,apiEndpointName:"getModelsList",apiArgs:o,limit:30,pollingInterval:5e3}),A=({target:v})=>{h(v.value)},O=v=>()=>{v==="deployed"?l===n.DEPLOYED_ONLY?r(n.ALL):r(n.DEPLOYED_ONLY):l===n.MY_ONLY?r(n.ALL):r(n.MY_ONLY)},b=d.useMemo(()=>!a||!t?[]:ie(ae(a,x),l,{username:`${C} ${j}`.toLowerCase()},t.all),[a,x,l,C,j,t]),u=!!m||l!==n.ALL,T=()=>{u?(h(""),r(n.ALL)):window.open(re("/generated/model-registry/model_registry_api/","hopsworks-api/"),"_blank")};return!b.length&&w?e.jsx(W,{}):e.jsxs(e.Fragment,{children:[e.jsxs(c,{alignItems:"center",mb:"20px",children:[e.jsx(X,{variant:"white",placeholder:"Find a model by name...",value:x,labelProps:{flexGrow:1,mr:"8px"},onChange:A}),e.jsxs(c,{sx:R.modelFiltersLabel,children:[e.jsx(E,{mr:"8px",width:"105px",sx:{textAlign:"center",backgroundColor:"white"},style:{whiteSpace:"nowrap"},checked:l===n.DEPLOYED_ONLY,onChange:O("deployed"),children:"deployed only"}),e.jsx(E,{width:"125px",sx:{textAlign:"center",backgroundColor:"white"},checked:l===n.MY_ONLY,onChange:O("own"),children:"my models only"})]}),e.jsx(Z,{ml:"20px",mr:"20px",mt:"0",mb:"0",width:"1px",sx:{backgroundColor:"grayShade2",height:"32px"}}),e.jsx(ee,{width:"auto",variant:"white",value:g,isLoading:w,options:Object.keys(N),label:"sort by",labelPosition:"inline",onChange:y}),e.jsx(c,{ml:"8px",sx:L?R.loading:{},children:e.jsx(P,{type:"button",intent:"primary",tooltip:"Refresh models",icon:L?D.loading:D.refresh,onClickIcon:k})})]}),!b.length&&e.jsxs(c,{flex:"1 1 100%",flexDirection:"column",justifyContent:u?"flex-start":"center",alignItems:"center",height:"100%",mt:u?"40px":0,mb:"105px",children:[e.jsx(f,{fontFamily:"Inter",fontSize:"18px",mb:"20px",sx:{color:"black"},children:u?"No models match the filters":"No models"}),e.jsx(se,{fontSize:"12px",fontFamily:"Inter",mb:"20px",sx:{color:"black"},children:u?"Change or reset filters":"Register a model using the Hopsworks Python library"}),e.jsx(te,{intent:"primary",onClick:T,children:u?"Reset filters":"See documentation ↗"})]}),!!b.length&&t&&e.jsx(de,{data:b,deployments:t.all,isFiltered:!!a&&a.length!==b.length,hasMore:M,loadMore:i,isFetchingMore:Y})]})};export{je as default};
