"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("../tslib.es6-C4EgNkz1.js"),l=require("react"),I=require("classnames"),A=require("../tri-state-checkbox-C06lbYBj.js"),C=require("../utils-C9NL3q0j.js"),M=require("../icons/ebay-icon-sort-down-12/index.js"),B=require("../icons/ebay-icon-sort-up-12/index.js"),D=require("../icons/ebay-icon-sort-12/index.js"),F=require("../checkbox-D4sjiLfW.js"),f=s=>{var{rowHeader:m,columnType:n,className:i,children:r}=s,b=g.__rest(s,["rowHeader","columnType","className","children"]);const S=m?"th":"td",y=n==="layout"?"div":l.Fragment;return l.createElement(S,Object.assign({className:I("table-cell",i,{[`table-cell--${n}`]:n})},b),l.createElement(y,Object.assign({},n==="layout"?{className:"table-cell__layout"}:{}),r))},O=s=>{var{columnType:m,sort:n,href:i,children:r,onSort:b}=s,S=g.__rest(s,["columnType","sort","href","children","onSort"]);const y={asc:"ascending",desc:"descending",none:"none"},E={asc:M.EbayIconSortDown12,desc:B.EbayIconSortUp12,none:D.EbayIconSort12}[n],p=n?l.createElement(l.Fragment,null," ",l.createElement(E,null)):null;let T=r;return i?T=l.createElement("a",{href:i,onClick:b},r,p):n&&(T=l.createElement("button",{type:"button",onClick:b},r,p)),l.createElement(f,Object.assign({},S,{rowHeader:!0,columnType:m,"aria-sort":n?y[n]:void 0}),T)},N=s=>{var{name:m,className:n,selected:i,mode:r,a11ySelectRowText:b,children:S,onSelect:y,__headers:c}=s,E=g.__rest(s,["name","className","selected","mode","a11ySelectRowText","children","onSelect","__headers"]);const p=C.filterByType(S,f),T=(a,{checked:u})=>{y(a,{name:m,selected:u})};return l.createElement("tr",Object.assign({className:n},E),r==="selection"&&l.createElement(f,{rowHeader:!0,key:"selection-cell"},l.createElement(F.EbayCheckbox,{checked:i,"aria-label":b||"Select row",onChange:T})),c?.map((a,u)=>l.cloneElement(p[u],{rowHeader:typeof a.props.rowHeader=="boolean"?a.props.rowHeader:p[u].props.rowHeader,columnType:typeof a.props.columnType=="string"?a.props.columnType:p[u].props.columnType})))},U=s=>{var{className:m,mode:n,allSelected:i,density:r,frozenHeader:b,a11ySelectAllText:S,a11ySelectRowText:y,onSelect:c,onSort:E,children:p}=s,T=g.__rest(s,["className","mode","allSelected","density","frozenHeader","a11ySelectAllText","a11ySelectRowText","onSelect","onSort","children"]);const a=C.filterByType(p,O),u=C.filterByType(p,N),[H,$]=l.useState(()=>a.reduce((e,t,o)=>(t.props.sort&&(e[t.props.name||`${o}`]=t.props.sort),e),{})),[v,x]=l.useState(()=>u.reduce((e,t,o)=>(e[t.props.name||`${o}`]=typeof t.props.selected=="boolean"?t.props.selected:!1,e),{}));function _(e){const t=Object.values(e).filter(Boolean).length,o=Object.values(e).length-t;return t===0?"false":o===0?"true":"mixed"}const w=typeof i<"u"?i:_(v),k=e=>{const t=u.reduce((o,d,h)=>(o[d.props.name||`${h}`]=w==="false"||w==="mixed",o),{});x(t),c?.(e,{selected:t,allSelected:_(t)})},q=(e,{name:t,selected:o})=>{const d=Object.assign(Object.assign({},v),{[t||""]:o});x(d),c?.(e,{selected:d,allSelected:_(d)})},R=(e,t)=>{const o={none:"asc",asc:"desc",desc:"none"},d=Object.entries(H).reduce((h,[j,z])=>(j===t?h[j]=o[z]:h[j]="none",h),{});$(d),E?.(e,{sorted:{[t]:d[t]}})};return l.createElement("div",Object.assign({},T,{className:I("table",m,{"table--mode-selection":n==="selection","table--frozen-header":b,[`table--density-${r}`]:r}),role:"group",tabIndex:0}),l.createElement("table",null,l.createElement("thead",null,l.createElement("tr",null,n==="selection"&&l.createElement(O,{key:"selection-all-cell"},l.createElement(A.EbayTriStateCheckbox,{"aria-label":S||"Select all rows",checked:w,onChange:k})),a.map((e,t)=>l.cloneElement(e,{sort:H[e.props.name||`${t}`],onSort:o=>R(o,e.props.name||`${t}`)})))),l.createElement("tbody",null,u.map((e,t)=>l.cloneElement(e,{mode:n,name:e.props.name||`${t}`,a11ySelectRowText:e.props.a11ySelectRowText||y,onSelect:(o,d)=>q(o,Object.assign(Object.assign({},d),{name:e.props.name||`${t}`})),selected:typeof e.props.selected=="boolean"?e.props.selected:v[e.props.name||`${t}`],__headers:a})))))};exports.EbayTable=U;exports.EbayTableCell=f;exports.EbayTableHeader=O;exports.EbayTableRow=N;
