"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("../../_virtual/jsx-runtime.js"),c=require("react"),e=require("./styles.js"),f=require("../Button/index.js"),P=require("../../utils/index.js"),q=require("./components/MainHeader.js"),I=require("./components/TableHeader.js"),y=require("./components/TableBody.js"),C=require("./components/PaginatedFooter.js"),A=require("./components/TableFoot.js");function _({variant:g="wide",header:u,actionsBar:o,columns:m,rows:x,footer:a,selectableRows:t,additionalRows:j,"data-testid":h,"data-trackid":k}){const n=P.getId(h),d=P.getId(k),i=a&&a.variant==="pagination"&&a.pagination,[s,v]=c.useState(i&&i.currentPage||1);c.useEffect(()=>{i&&i.controlledPagination&&v(i.currentPage||1)},[x]);const E=i&&i.controlledPagination?x.slice(s*i.rowsPerPage-i.rowsPerPage,s*i.rowsPerPage):x;return r.jsxRuntimeExports.jsxs(e.DataTableWrapper,{"data-testid":n(),"data-trackid":d(),children:[u&&r.jsxRuntimeExports.jsx(q.default,{variant:g,headerVariant:u.variant||"subtle",title:u.title,secondaryText:u.secondaryText,"data-testid":n("main-header"),"data-trackid":d("main-header")}),o&&r.jsxRuntimeExports.jsxs(e.ActionBar,{"data-testid":n("action-bar"),"data-trackid":d("action-bar"),children:[o.text&&t&&r.jsxRuntimeExports.jsxs(e.SelectedItemsInfo,{children:[t.selectedRows.length," ",o.text]}),r.jsxRuntimeExports.jsx(e.ActionButtons,{children:o.actionButtons.map((p,T)=>r.jsxRuntimeExports.jsx(f.Button,{variant:"inverse-ghost",size:"small-expressive",iconPosition:"trailing",icon:p.icon,disabled:!!p.disabled,onClick:()=>p.onClick(),role:"button",children:p.text},`action_button_${T}`))})]}),r.jsxRuntimeExports.jsx(e.ResponsiveTableWrapper,{children:r.jsxRuntimeExports.jsxs(e.Table,{role:"table",children:[r.jsxRuntimeExports.jsx(I.default,{columns:m,rows:x,selectAllRows:t==null?void 0:t.onSelectAll,selectedRows:t==null?void 0:t.selectedRows,rowIdentifier:t==null?void 0:t.rowId,"data-testid":n("table-header"),"data-trackid":d("table-header")}),r.jsxRuntimeExports.jsx(y.default,{filteredRows:E,onRowClick:t==null?void 0:t.onRowClick,selectedRows:t==null?void 0:t.selectedRows,disabledRows:t==null?void 0:t.disabledRows,columns:m,rowIdentifier:t==null?void 0:t.rowId,"data-testid":n("table-body"),"data-trackid":d("table-body")}),j&&j.length>0&&r.jsxRuntimeExports.jsx(A.default,{"data-testid":n("table-foot"),"data-trackid":d("table-foot"),additionalRows:j})]})}),a&&r.jsxRuntimeExports.jsxs(e.Footer,{"data-testid":n("footer"),"data-trackid":d("footer"),children:[a.variant==="pagination"&&r.jsxRuntimeExports.jsx(C.default,{footer:a,currentPage:s,setCurrentPage:v,numberOfRows:x.length,variant:g,"data-testid":n("pagination"),"data-trackid":d("pagination")}),a.variant==="custom"&&a.content]})]})}exports.DataTable=_;
