import{r as O,D as Q,j as n,d as c,a2 as L,z as A}from"./index-Cziemgsu.js";const X=({filteredNames:g,itemName:p,parentName:E,selectedNames:t,setSelectedNames:o,processingNames:I,rows:i,headers:M,indeterminateNames:x=[],disableSelect:r=!1,onToggleRow:b,hideContextualMenu:f,defaultSortKey:y,...N})=>{const[m,a]=O.useState(),k=t.length===g.length&&t.length>0,S=t.length+x.length>0,R=e=>e.className==="p-checkbox__label";Q("mousedown",e=>{e.shiftKey&&R(e.target)&&e.preventDefault()});const D=()=>{o(g),a(void 0)},C=()=>{const e=i.filter(s=>!!s.name).map(s=>s.name??"");o(e),a(void 0)},P=()=>{o([],!0),a(void 0)},$=[{content:n.jsxs(n.Fragment,{children:[n.jsx(c.CheckboxInput,{label:n.jsx("div",{className:"u-off-screen",children:"Select all"}),labelClassName:"multiselect-checkbox",checked:k,indeterminate:S&&!k,onChange:S?P:C,disabled:r}),!f&&n.jsx(c.ContextualMenu,{className:"select-context-menu",position:"left",title:"Multiselect",toggleAppearance:"base",toggleClassName:"has-icon u-no-margin--bottom",toggleLabel:n.jsx(c.Icon,{name:"chevron-down"}),toggleProps:{"aria-label":"multiselect rows",disabled:r},links:[{children:`Select all ${L(p,2)} on this page`,onClick:C},{children:`Select all ${E} ${L(p,2)}`,onClick:D}]})]}),className:A("select select-header",{"no-menu":f}),"aria-label":"select"},...M??[]],w=new Set(t),z=new Set(I),K=new Set(x),T=i.map((e,s)=>{const l=w.has(e.name??""),j=z.has(e.name??""),U=K.has(e.name??""),W=q=>{if(b){b(e.name??"");return}if(q.nativeEvent.shiftKey&&m!==void 0&&!l){const h=new Set(t),v=[...t],H=Math.min(s,m),J=Math.max(s,m);for(let u=H;u<J+1;u++){const d=i[u].name;d&&!h.has(d)&&v.push(d)}o(v),a(s);return}const G=l?t.filter(h=>h!==e.name):[...t,e.name??""];o(G),a(l?void 0:s)},_=[{content:n.jsx(c.CheckboxInput,{label:n.jsxs("div",{className:"u-off-screen",children:["Select ",e.name??"row"]}),labelClassName:"u-no-margin--bottom",checked:l,onChange:W,disabled:j||!e.name||r,indeterminate:U&&!l}),role:"rowheader",className:"select"},...e.columns??[]],B=A(e.className,{"selected-row":l,"processing-row":j}),F=e.key??e.name;return{...e,className:B,key:F,columns:_}});return n.jsx(c.MainTable,{expanding:!0,headers:$,rows:[...T],defaultSort:y,defaultSortDirection:"descending",...N})};export{X as S};
