import{j as i}from"./jsx-runtime-CnH95YSl.js";import{f as A}from"./index-BJMTVygn.js";import{r as e}from"./index-NdkWRN8K.js";import{O as pe}from"./OdysseyStorybookThemeDecorator-BuDiOG2V.js";import{u as fe,M as Ne}from"./index.esm-DTxqsiYY.js";import{K as ge,T as j}from"./OdysseyThemeProvider-Bh0Bu-2o.js";import{M as z}from"./Typography-Cz6D417Y.js";import{M as ye}from"./Button-BEA5U6Tg.js";import"./_commonjsHelpers-gnU0ypJ3.js";import"./index-BJTM6NaI.js";import"./OdysseyProvider-qIn9QVYS.js";import"./createSvgIcon-ClUWwDzL.js";import"./createChainedFunction-BO_9K8Jh.js";import"./debounce-Be36O1Ab.js";import"./ListItem-C0ExFtXb.js";import"./utils-iop7lDec.js";import"./useFormControl-BMISTZuX.js";import"./FormLabel-CiGre9wK.js";import"./List-CmjR1pNu.js";import"./useIsFocusVisible-DH0qxT5e.js";import"./isHostComponent-DVu5iVWx.js";import"./ButtonBase-BNqa2TMD.js";import"./assertThisInitialized-B9jnkVVz.js";import"./inheritsLoose-CJ6Ie9dp.js";import"./TransitionGroupContext-DAL84N7p.js";import"./ownerDocument-DW-IO8s5.js";import"./ownerWindow-HkKU3E4x.js";import"./useControlled-NQulfz4l.js";import"./index-B5xazMy1.js";import"./index-DieBXP3Z.js";import"./utils-kUZVaD1e.js";import"./Stack-B7OGvu7C.js";import"./createStyled-D6bTcpHC.js";import"./useThemeProps-DwvbKxez.js";import"./Tooltip-Cq2rQGbD.js";import"./Grow-C8kUeGCY.js";import"./getReactElementRef-DsIevm5t.js";import"./resolveComponentProps-DXQ8X87i.js";import"./Popper-BARIxJrI.js";import"./popper-BVOCD5jc.js";import"./Portal-C6D59xAE.js";import"./Paper-D-_O-EjU.js";import"./Box-BcMTQ_R2.js";import"./createBox-Dxawkfow.js";import"./CircularProgress-HbIdZLBB.js";import"./DialogContent-Cwn-I-C_.js";import"./Fade-dUgBN8rJ.js";import"./Modal-CSDyCVCf.js";import"./getScrollbarSize-Bqq2hMjQ.js";import"./dialogActionsClasses-ZEPlxVw-.js";import"./DialogTitle-C-K7jEio.js";import"./Typography-ClQ35Rr-.js";import"./Menu-K9lpVvDG.js";import"./MenuList-BMOesnfs.js";import"./colorManipulator-DKifQsuo.js";import"./IconButton-5qShmnSr.js";import"./Radio-B4gVvwps.js";import"./SwitchBase-CefEM0OA.js";import"./Checkbox-vZwuXtzm.js";import"./useMobilePicker-DZhX9dEQ.js";import"./Select-DZTigpTO.js";import"./ArrowDropDown-DdemyKZU.js";import"./InputBase-DeB4_faH.js";import"./FormHelperText-CsNAE1E3.js";import"./useThemeProps-BPvYx-mf.js";import"./InputAdornment-CdR3XT6f.js";import"./visuallyHidden-Dan1xhjv.js";import"./Button-BzIwUmSM.js";import"./Chip-CXnMieIl.js";import"./MenuItem-vhp8G-Nb.js";import"./Collapse-DfdoVIdP.js";import"./AlertTitle-q6ff_Zkl.js";import"./useSlot-CvpE2t6D.js";import"./Close-OXBt1nIe.js";import"./Skeleton-BPjIT6NG.js";import"./Divider-Ln3VaO81.js";import"./Autocomplete-CxtGbb8j.js";import"./ListSubheader-CQJAAOsd.js";import"./tableSortLabelClasses-CkKrbp1R.js";import"./FormControlLabel-0BBemR80.js";import"./DateTimePicker-B7a9bgL6.js";import"./Tabs-CQz87GHd.js";import"./DatePicker-BwDkz3WT.js";import"./BaseButton-DYZHKnV3.js";import"./MuiPropsContext-DhRylJZk.js";import"./Tooltip-CsVWtVfL.js";/*!
 * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.
 * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
 *
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and limitations under the License.
 */const be=({columns:a=[],data:r=[],fetchMoreData:o,getRowId:d,hasError:p,hasRowSelection:f,initialState:n,isFetching:w,onGlobalFilterChange:N,onPaginationChange:g,onRowSelectionChange:y,rowsPerPage:ee=10,state:C,ToolbarButtons:E})=>{const{t:L}=ge(),v=e.useRef(null),[J,ae]=e.useState([]),[c,te]=e.useState();e.useEffect(()=>{c!==void 0&&(N==null||N(c))},[c,N]),e.useEffect(()=>{var s,m;try{(m=(s=v.current)==null?void 0:s.scrollToIndex)==null||m.call(s,0)}catch(u){console.error(u)}},[J,c]);const l=r.length??0,se=e.useCallback(()=>o?i.jsx(z,{children:i.jsx(j,{count:l,i18nKey:"table.fetchedrows.text",values:{totalRows:l}})}):i.jsx(z,{children:i.jsx(j,{count:l,i18nKey:"table.rows.text",values:{totalRows:l}})}),[o,l]),re=e.useCallback(({table:s})=>i.jsx(i.Fragment,{children:E&&i.jsx(E,{table:s})}),[E]),[b,oe]=e.useState({});e.useEffect(()=>{y==null||y(b)},[y,b]);const[t,ie]=e.useState((n==null?void 0:n.pagination)||{pageIndex:0,pageSize:ee}),K=e.useRef(r.length),ne=e.useCallback(s=>{r.length===K.current?ie(m=>s(m)):K.current=r.length},[r.length]);e.useEffect(()=>{const s=Math.floor(r.length/t.pageSize);!w&&t.pageIndex>s-1&&(o==null||o())},[r.length,o,w,t.pageIndex,t.pageSize]),e.useEffect(()=>{g==null||g({pageIndex:t.pageIndex,pageSize:t.pageSize})},[g,t.pageIndex,t.pageSize]);const me=e.useMemo(()=>({pagination:t,...n}),[n,t]),de=e.useMemo(()=>({pagination:{pageIndex:t.pageIndex,pageSize:t.pageSize},rowSelection:b,globalFilter:c,columnFilters:J,...C}),[t.pageIndex,t.pageSize,b,c,J,C]),ce=e.useMemo(()=>p?{children:L("table.error"),severity:"error"}:{},[p,L]),le=e.useMemo(()=>({rowsPerPageOptions:[],showFirstButton:!1,showLastButton:!1}),[]),O=e.useCallback(s=>{var m,u,M,V,B,h,P;return typeof((M=(u=(m=s.components)==null?void 0:m.MuiCheckbox)==null?void 0:u.styleOverrides)==null?void 0:M.root)=="function"?(P=(h=(B=(V=s.components)==null?void 0:V.MuiCheckbox)==null?void 0:B.styleOverrides)==null?void 0:h.root)==null?void 0:P.call(h,{ownerState:{},theme:s}):""},[]),ue=fe({columns:a,data:r,enableMultiRowSelection:f,enablePagination:!0,enableRowSelection:f,enableSorting:!1,getRowId:d,initialState:me,muiSelectAllCheckboxProps:{sx:O},muiSelectCheckboxProps:{sx:O},muiPaginationProps:le,muiToolbarAlertBannerProps:ce,onColumnFiltersChange:ae,onGlobalFilterChange:te,onPaginationChange:ne,onRowSelectionChange:oe,renderBottomToolbarCustomActions:se,renderTopToolbarCustomActions:re,rowVirtualizerInstanceRef:v,rowVirtualizerOptions:{overscan:4},state:de});return i.jsx(Ne,{table:ue})},I=e.memo(be);I.displayName="PaginatedTable";const Ya={component:I,decorators:[pe],argTypes:{columns:{control:"object",type:{required:!0,name:"other",value:"MaterialReactTableProps<TData>"}},data:{control:"object",type:{required:!0,name:"other",value:"MaterialReactTableProps<TData>"}},getRowId:{},fetchMoreData:{},hasError:{control:"boolean"},hasRowSelection:{control:"boolean"},initialState:{control:"object"},isFetching:{control:"boolean"},onGlobalFilterChange:{},onPaginationChange:{},onRowSelectionChange:{},state:{control:"object"},ToolbarButtons:{},rowsPerPage:{table:{defaultValue:{summary:"10"}}}},args:{onPaginationChange:A(),onRowSelectionChange:A()}},T=[{accessorKey:"name.firstName",header:"First Name"},{accessorKey:"name.lastName",header:"Last Name"},{accessorKey:"address",Cell:({cell:a})=>a.getValue().concat(","),header:"Address"},{accessorKey:"city",header:"City"},{accessorKey:"state",header:"State"}],x=[{address:"261 Erdman Ford",city:"East Daphne",id:"234823773",name:{firstName:"John",lastName:"Doe"},state:"Kentucky"},{address:"769 Dominic Grove",city:"Columbus",id:"234823774",name:{firstName:"Jane",lastName:"Doe"},state:"Ohio"},{address:"566 Brakus Inlet",city:"South Linda",id:"234823775",name:{firstName:"Joe",lastName:"Doe"},state:"West Virginia"},{address:"722 Emie Stream",city:"Lincoln",id:"234823776",name:{firstName:"Kevin",lastName:"Vandy"},state:"Nebraska"},{address:"32188 Larkin Turnpike",city:"Omaha",id:"234823777",name:{firstName:"Joshua",lastName:"Rolluffs"},state:"Nebraska"},{address:"261 Erdman Ford",city:"East Daphne",id:"334823773",name:{firstName:"John",lastName:"Doe"},state:"Kentucky"},{address:"769 Dominic Grove",city:"Columbus",id:"334823774",name:{firstName:"Jane",lastName:"Doe"},state:"Ohio"},{address:"566 Brakus Inlet",city:"South Linda",id:"334823775",name:{firstName:"Joe",lastName:"Doe"},state:"West Virginia"},{address:"722 Emie Stream",city:"Lincoln",id:"334823776",name:{firstName:"Kevin",lastName:"Vandy"},state:"Nebraska"},{address:"32188 Larkin Turnpike",city:"Omaha",id:"334823777",name:{firstName:"Joshua",lastName:"Rolluffs"},state:"Nebraska"},{address:"261 Erdman Ford",city:"East Daphne",id:"434823773",name:{firstName:"John",lastName:"Doe"},state:"Kentucky"},{address:"769 Dominic Grove",city:"Columbus",id:"434823774",name:{firstName:"Jane",lastName:"Doe"},state:"Ohio"},{address:"566 Brakus Inlet",city:"South Linda",id:"434823775",name:{firstName:"Joe",lastName:"Doe"},state:"West Virginia"},{address:"722 Emie Stream",city:"Lincoln",id:"434823776",name:{firstName:"Kevin",lastName:"Vandy"},state:"Nebraska"},{address:"32188 Larkin Turnpike",city:"Omaha",id:"434823777",name:{firstName:"Joshua",lastName:"Rolluffs"},state:"Nebraska"},{address:"261 Erdman Ford",city:"East Daphne",id:"534823773",name:{firstName:"John",lastName:"Doe"},state:"Kentucky"},{address:"769 Dominic Grove",city:"Columbus",id:"534823774",name:{firstName:"Jane",lastName:"Doe"},state:"Ohio"},{address:"566 Brakus Inlet",city:"South Linda",id:"534823775",name:{firstName:"Joe",lastName:"Doe"},state:"West Virginia"},{address:"722 Emie Stream",city:"Lincoln",id:"534823776",name:{firstName:"Kevin",lastName:"Vandy"},state:"Nebraska"},{address:"32188 Larkin Turnpike",city:"Omaha",id:"534823777",name:{firstName:"Joshua",lastName:"Rolluffs"},state:"Nebraska"},{address:"261 Erdman Ford",city:"East Daphne",id:"634823773",name:{firstName:"John",lastName:"Doe"},state:"Kentucky"},{address:"769 Dominic Grove",city:"Columbus",id:"634823774",name:{firstName:"Jane",lastName:"Doe"},state:"Ohio"},{address:"566 Brakus Inlet",city:"South Linda",id:"634823775",name:{firstName:"Joe",lastName:"Doe"},state:"West Virginia"},{address:"722 Emie Stream",city:"Lincoln",id:"634823776",name:{firstName:"Kevin",lastName:"Vandy"},state:"Nebraska"},{address:"32188 Larkin Turnpike",city:"Omaha",id:"634823777",name:{firstName:"Joshua",lastName:"Rolluffs"},state:"Nebraska"},{address:"261 Erdman Ford",city:"East Daphne",id:"734823773",name:{firstName:"John",lastName:"Doe"},state:"Kentucky"},{address:"769 Dominic Grove",city:"Columbus",id:"734823774",name:{firstName:"Jane",lastName:"Doe"},state:"Ohio"},{address:"566 Brakus Inlet",city:"South Linda",id:"734823775",name:{firstName:"Joe",lastName:"Doe"},state:"West Virginia"},{address:"722 Emie Stream",city:"Lincoln",id:"734823776",name:{firstName:"Kevin",lastName:"Vandy"},state:"Nebraska"},{address:"32188 Larkin Turnpike",city:"Omaha",id:"734823777",name:{firstName:"Joshua",lastName:"Rolluffs"},state:"Nebraska"},{address:"261 Erdman Ford",city:"East Daphne",id:"834823773",name:{firstName:"John",lastName:"Doe"},state:"Kentucky"},{address:"769 Dominic Grove",city:"Columbus",id:"834823774",name:{firstName:"Jane",lastName:"Doe"},state:"Ohio"},{address:"566 Brakus Inlet",city:"South Linda",id:"834823775",name:{firstName:"Joe",lastName:"Doe"},state:"West Virginia"},{address:"722 Emie Stream",city:"Lincoln",id:"834823776",name:{firstName:"Kevin",lastName:"Vandy"},state:"Nebraska"},{address:"32188 Larkin Turnpike",city:"Omaha",id:"834823777",name:{firstName:"Joshua",lastName:"Rolluffs"},state:"Nebraska"},{address:"261 Erdman Ford",city:"East Daphne",id:"934823773",name:{firstName:"John",lastName:"Doe"},state:"Kentucky"},{address:"769 Dominic Grove",city:"Columbus",id:"934823774",name:{firstName:"Jane",lastName:"Doe"},state:"Ohio"},{address:"566 Brakus Inlet",city:"South Linda",id:"934823775",name:{firstName:"Joe",lastName:"Doe"},state:"West Virginia"},{address:"722 Emie Stream",city:"Lincoln",id:"934823776",name:{firstName:"Kevin",lastName:"Vandy"},state:"Nebraska"},{address:"32188 Larkin Turnpike",city:"Omaha",id:"934823777",name:{firstName:"Joshua",lastName:"Rolluffs"},state:"Nebraska"}],k={args:{columns:T,data:x,getRowId:({id:a})=>a}},S={args:{columns:T,data:x,getRowId:({id:a})=>a},render:function(r){const o=e.useRef(15),d=e.useMemo(()=>r.data??[],[r]),[p,f]=e.useState(d.slice(0,o.current)),n=e.useCallback(()=>{o.current=o.current+10,f(d.slice(0,Math.min(o.current,d.length)))},[d]);return i.jsx(I,{...r,data:p,fetchMoreData:n})}},D={args:{columns:T,data:x,getRowId:({id:a})=>a,hasRowSelection:!0}},R={args:{columns:T,data:x,getRowId:({id:a})=>a,ToolbarButtons:({table:a})=>i.jsx(ye,{label:"New Action",onClick:()=>console.info(a.getState()),variant:"primary"})}};var F,W,G;k.parameters={...k.parameters,docs:{...(F=k.parameters)==null?void 0:F.docs,source:{originalSource:`{
  args: {
    columns,
    data,
    getRowId: ({
      id
    }: {
      id: string;
    }) => id
  }
}`,...(G=(W=k.parameters)==null?void 0:W.docs)==null?void 0:G.source}}};var q,U,_;S.parameters={...S.parameters,docs:{...(q=S.parameters)==null?void 0:q.docs,source:{originalSource:`{
  args: {
    columns,
    data,
    getRowId: ({
      id
    }: {
      id: string;
    }) => id
  },
  render: function C(args) {
    const countRef = useRef(15);
    const dataArg = useMemo(() => args.data ?? [], [args]);
    const [data, setData] = useState(dataArg.slice(0, countRef.current));
    const fetchMoreData = useCallback(() => {
      countRef.current = countRef.current + 10;
      setData(dataArg.slice(0, Math.min(countRef.current, dataArg.length)));
    }, [dataArg]);
    return <PaginatedTable {...args} data={data} fetchMoreData={fetchMoreData} />;
  }
}`,...(_=(U=S.parameters)==null?void 0:U.docs)==null?void 0:_.source}}};var H,Q,X;D.parameters={...D.parameters,docs:{...(H=D.parameters)==null?void 0:H.docs,source:{originalSource:`{
  args: {
    columns,
    data,
    getRowId: ({
      id
    }: {
      id: string;
    }) => id,
    hasRowSelection: true
  }
}`,...(X=(Q=D.parameters)==null?void 0:Q.docs)==null?void 0:X.source}}};var Y,Z,$;R.parameters={...R.parameters,docs:{...(Y=R.parameters)==null?void 0:Y.docs,source:{originalSource:`{
  args: {
    columns,
    data,
    getRowId: ({
      id
    }: {
      id: string;
    }) => id,
    ToolbarButtons: ({
      table
    }) => <Button label="New Action" onClick={() => console.info(table.getState())} variant="primary" />
  }
}`,...($=(Z=R.parameters)==null?void 0:Z.docs)==null?void 0:$.source}}};const Za=["BasicUsage","Pagination","Selection","CustomToolbar"];export{k as BasicUsage,R as CustomToolbar,S as Pagination,D as Selection,Za as __namedExportsOrder,Ya as default};
