import{l as D,e as F,d as n,ay as q,m as B,r as K,j as e,ae as _,f as M,b3 as I,g as R,aZ as T,bh as U,o as E,C as H,H as Q,b as $,c as z,S as A,L as W,P as Z,q as G,F as J}from"./index-3c1b2661.js";const V=()=>{const y=D(),N=F(),u=n.useNotify(),m=q(),{project:s}=B(),[c,P]=K.useState("");if(!s)return e.jsx(e.Fragment,{children:"Missing project"});const p=s==="default",{project:L,isLoading:C}=_(),{data:o=[],error:h,isLoading:w}=M({queryKey:[G.profiles,s],queryFn:()=>J(s)});h&&u.failure("Loading profiles failed",h);const f=w||C,g=I(L);o.sort(R);const j=o.map(a=>{const t=T(s,p,a.used_by);return{name:a.name,count:t.filter(r=>r.project===s).length,total:t.length}}),i=o.filter(a=>{if(c){const t=c.toLowerCase();if(!a.name.toLowerCase().includes(t)&&!a.description.toLowerCase().includes(t))return!1}return!0}),v=[{content:"Name",sortKey:"name"},{content:"Description",sortKey:"description"},{content:"Used by",sortKey:"used_by"}],k=i.map(a=>{var x,b;const t=()=>m.openProfileSummary(a.name,s),r=((x=j.find(d=>a.name===d.name))==null?void 0:x.count)??0,S=((b=j.find(d=>a.name===d.name))==null?void 0:b.total)??0;return{className:m.profile===a.name?"u-row-selected":"u-row",columns:[{content:e.jsx("div",{className:"u-truncate",title:a.name,children:e.jsx(U,{profile:{name:a.name,project:s}})}),role:"rowheader","aria-label":"Name",onClick:t},{content:e.jsx("div",{className:"u-truncate",title:a.description,children:a.description}),role:"rowheader","aria-label":"Description",onClick:t,className:"clickable-cell"},{content:e.jsxs(e.Fragment,{children:[r," ",r===1?"instance":"instances",p&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"u-text--muted",children:[S," in all projects"]})})]}),role:"rowheader","aria-label":"Used by",onClick:t,className:"clickable-cell"}],sortData:{name:a.name.toLowerCase(),description:a.description.toLowerCase(),used_by:r}}}),l=E(k);return e.jsxs(H,{mainClassName:"profile-list",contentClassName:"profile-content",header:e.jsxs("div",{className:"p-panel__header profile-list-header",children:[e.jsxs("div",{className:"profile-header-left",children:[e.jsx("h1",{className:"p-heading--4 u-no-margin--bottom",children:e.jsx(Q,{href:`${y}/profiles/`,title:"Learn how to use profiles",children:"Profiles"})}),e.jsx(n.SearchBox,{className:"search-box margin-right u-no-margin--bottom",name:"search-profile",type:"text",onChange:a=>{P(a)},placeholder:"Search",value:c,"aria-label":"Search"})]}),g&&e.jsx(n.Button,{appearance:"positive",className:"u-no-margin--bottom",onClick:()=>N(`/ui/project/${s}/profiles/create`),children:"Create profile"})]}),children:[e.jsx($,{}),e.jsx(n.Row,{className:"no-grid-gap",children:e.jsxs(n.Col,{size:12,children:[!f&&!g&&e.jsxs(n.Notification,{severity:"caution",title:"Profiles disabled",children:["The feature has been disabled on a project level. All the available profiles are inherited from the"," ",e.jsx(z,{to:"/ui/project/default/profiles",children:"default project"}),"."]}),e.jsx(A,{dependencies:[i,u.notification],belowId:"pagination",children:e.jsx(n.MainTable,{headers:v,rows:l.pageData,sortable:!0,emptyStateMsg:f?e.jsx(W,{text:"Loading profiles..."}):e.jsx(e.Fragment,{children:"No profile found matching this search"}),onUpdateSort:l.updateSort})}),e.jsx(Z,{...l,id:"pagination",totalCount:o.length,visibleCount:i.length===o.length?l.pageData.length:i.length,keyword:"profile"})]})})]})};export{V as default};
