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