import{r as k,ak as C,j as a,d as t,L as T}from"./index-DET0E_3l.js";import{P as L}from"./PermissionGroupsFilter-D8fzmJ2u.js";import{S as M}from"./SelectableMainTable-Cx4QgggV.js";import{u as P}from"./useSortTableData-Dv6VLExi.js";const A=({groups:l,modifiedGroups:i,parentItemName:r,parentItems:s,selectedGroups:c,indeterminateGroups:f,setSelectedGroups:x,toggleGroup:m,scrollDependencies:d,preselectedGroups:n})=>{const[o,N]=k.useState(""),w=[{content:"Group",sortKey:"name",className:"name"},{content:"Description",sortKey:"description",className:"description"},{content:"","aria-label":"Modified status",className:"modified-status"}],S=l.filter(e=>e.name.toLowerCase().includes(o)||!o).map(e=>{var b;const p=c.has(e.name)&&i.has(e.name),y=!c.has(e.name)&&i.has(e.name),u=((s==null?void 0:s.length)||0)>1?`all selected ${C(r,2)}`:`${r} ${(b=s==null?void 0:s[0])==null?void 0:b.name}`,g=p?`Group will be added to ${u}`:y?`Group will be removed from ${u}`:"",h=()=>{m(e.name)};return{key:e.name,name:e.name,className:"u-row",columns:[{content:e.name,title:e.name,onClick:h,role:"rowheader",className:"name u-truncate clickable-cell","aria-label":"Name"},{content:a.jsx("span",{children:e.description||""}),onClick:h,role:"cell",className:"description clickable-cell","aria-label":"Description",title:e.description},{content:i.has(e.name)&&a.jsx(t.Icon,{name:"status-in-progress-small"}),role:"cell","aria-label":"Modified status",className:"modified-status u-align--right",title:r?g:void 0}],sortData:{name:e.name.toLowerCase(),description:e.description.toLowerCase(),isPreselected:n==null?void 0:n.has(e.name)}}}),{rows:j}=P({rows:S,defaultSort:n?"isPreselected":"name",defaultSortDirection:n?"descending":"ascending"});return a.jsxs(t.ScrollableContainer,{dependencies:d,belowIds:["panel-footer"],className:"group-selection",children:[a.jsx(L,{onChange:N,value:o}),l.length?a.jsx(t.ScrollableTable,{dependencies:[...d,o],tableId:"group-selection-table",belowIds:["panel-footer"],children:a.jsx(M,{id:"group-selection-table",className:"group-selection-table",headers:w,rows:j,sortable:!0,emptyStateMsg:"No groups found",itemName:"group",parentName:"",selectedNames:Array.from(c),setSelectedNames:x,disabledNames:[],filteredNames:l.map(e=>e.name),indeterminateNames:Array.from(f??new Set),onToggleRow:m,hideContextualMenu:!0})}):a.jsxs(t.EmptyState,{className:"empty-state empty-state__full-width",image:a.jsx(t.Icon,{name:"user-group",className:"empty-state-icon"}),title:"No groups found",children:[a.jsx("p",{children:"Groups are an easy way to manage the structured assignment of permissions."}),a.jsxs(T,{to:"/ui/permissions/groups?panel=create-groups",children:["Create group",a.jsx(t.Icon,{className:"external-link-icon",name:"external-link"})]})]})]})};export{A as G};
