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