import{r as C,a2 as b,j as a,d as t,e as y}from"./index-DRe7Uehz.js";import{P as k,M}from"./ModifiedStatusAction-CKiWqomp.js";import{S as A}from"./ScrollableContainer-i2n9yzu7.js";import{S as $}from"./ScrollableTable-tzQTcMDf.js";import{S as z}from"./SelectableMainTable-OcbCdGGs.js";import{u as T}from"./useSortTableData-APK7_dI2.js";const F=({groups:s,modifiedGroups:n,parentItemName:l,parentItems:o,selectedGroups:r,indeterminateGroups:d,setSelectedGroups:i,toggleGroup:c,scrollDependencies:u})=>{const[m,x]=C.useState(""),N=[{content:"Group name",sortKey:"name",className:"name",role:"rowheader"},{content:"Description",sortKey:"description",className:"description",role:"rowheader"},{content:"",role:"rowheader","aria-label":"Modified status",className:"modified-status"}],f=s.filter(e=>e.name.toLowerCase().includes(m)||!m).map(e=>{const w=r.has(e.name)&&n.has(e.name),j=!r.has(e.name)&&n.has(e.name),p=((o==null?void 0:o.length)||0)>1?`all selected ${b(l,2)}`:`${l} ${o==null?void 0:o[0].name}`,S=w?`Group will be added to ${p}`:j?`Group will be removed from ${p}`:"",h=()=>{c(e.name)};return{name:e.name,className:"u-row",columns:[{content:e.name,onClick:h,role:"cell",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:n.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:l?S:void 0}],sortData:{name:e.name.toLowerCase(),description:e.description.toLowerCase()}}}),{rows:g}=T({rows:f,defaultSort:"name"});return a.jsxs(A,{dependencies:u,belowIds:["panel-footer"],className:"group-selection",children:[a.jsx(k,{onChange:x,value:m}),s.length?a.jsx($,{dependencies:[...u,m],tableId:"group-selection-table",belowIds:["panel-footer"],children:a.jsx(z,{id:"group-selection-table",className:"group-selection-table",headers:N,rows:g,sortable:!0,emptyStateMsg:"No groups found",itemName:"group",parentName:"",selectedNames:Array.from(r),setSelectedNames:i,processingNames:[],filteredNames:s.map(e=>e.name),indeterminateNames:Array.from(d??new Set),onToggleRow:c,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",children:[a.jsx("p",{children:"No groups found."}),a.jsxs(y,{to:"/ui/permissions/groups",children:["Create groups",a.jsx(t.Icon,{className:"external-link-icon",name:"external-link"})]})]})]})},K=({modifiedGroups:s,undoChange:n,closePanel:l,onSubmit:o,loading:r,disabled:d,actionText:i})=>{const c=s.size?`Apply ${s.size} group ${b("change",s.size)}`:"Modify groups";return a.jsxs(a.Fragment,{children:[s.size?a.jsx(M,{modifiedCount:s.size,onUndoChange:n,itemName:"group",actionText:i}):null,a.jsx(t.Button,{appearance:"base",onClick:l,className:"u-no-margin--bottom",children:"Cancel"}),a.jsx(t.ActionButton,{appearance:"positive",onClick:o,className:"u-no-margin--bottom",disabled:d,loading:r,children:i?"Confirm":c})]})};export{F as G,K as a};
