import{K as A,T as V,u as ma,h as ua,N as ga}from"./OdysseyThemeProvider-Bh0Bu-2o.js";import{u as pa,a as fa}from"./index.esm-DTxqsiYY.js";import{r as a}from"./index-NdkWRN8K.js";import{M as I}from"./Box-1mvP3NLW.js";import{M as xa}from"./Button-BEA5U6Tg.js";import{M as H}from"./MenuButton-B3T7c15t.js";import{M as ha}from"./Callout-FZxPpigF.js";import{M as Ca}from"./EmptyState-CpBEzmap.js";import{M as Sa}from"./DataFilters-BnT_U3-o.js";import{u as Ta,M as ya}from"./Pagination-CB1wBW8Q.js";import{M as w}from"./MenuItem-CmSG6PNu.js";import{j as e}from"./jsx-runtime-CnH95YSl.js";import{B as ja}from"./Box-BcMTQ_R2.js";import{M as Ia,a as Ma,b as Ce,c as Da,d as za,e as he,f as ka}from"./List-UlX1tusJ.js";import{M as $}from"./More-DLQ2RjWn.js";import{C as va}from"./Checkbox-vZwuXtzm.js";import{M as wa}from"./Show-BnmQFsN6.js";import{u as Ea,a as Fa}from"./useScrollIndication-mYI-g6xa.js";/*!
 * Copyright (c) 2023-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 Se=["comfortable","spacious","compact"],Ba=({row:t,rowIndex:r,rowActionButtons:o,rowActionMenuItems:c,totalRows:b,updateRowOrder:i})=>{const{t:p}=A(),f=a.useCallback(()=>{i&&i({rowId:t.id,newRowIndex:0})},[t.id,i]),x=a.useCallback(()=>{i&&i({rowId:t.id,newRowIndex:Math.max(0,r-1)})},[t.id,r,i]),E=a.useCallback(()=>{i&&i({rowId:t.id,newRowIndex:r+1})},[t.id,r,i]),M=a.useCallback(()=>{i&&i({rowId:t.id,newRowIndex:b?b-1:r})},[t.id,r,b,i]);return e.jsxs(ja,{display:"flex",children:[o==null?void 0:o(t),(c||i)&&e.jsxs(H,{ariaLabel:p("table.moreactions.arialabel"),buttonVariant:"floating",endIcon:e.jsx($,{}),menuAlignment:"right",size:"small",children:[c&&e.jsx(e.Fragment,{children:c(t)}),c&&i&&e.jsx("hr",{}),i&&e.jsxs(e.Fragment,{children:[e.jsxs(w,{isDisabled:r<=0,onClick:f,children:[e.jsx(Ia,{})," ",e.jsx(V,{i18nKey:"table.reorder.tofront"})]}),e.jsxs(w,{isDisabled:r<=0,onClick:x,children:[e.jsx(Ma,{})," ",e.jsx(V,{i18nKey:"table.reorder.forward"})]}),e.jsxs(w,{isDisabled:b?r>=b-1:!1,onClick:E,children:[e.jsx(Ce,{})," ",e.jsx(V,{i18nKey:"table.reorder.backward"})]}),b&&e.jsxs(w,{isDisabled:r>=b-1,onClick:M,children:[e.jsx(Da,{})," ",e.jsx(V,{i18nKey:"table.reorder.toback"})]})]})]})]})},Te=a.memo(Ba);Te.displayName="DataTableRowActions";const Pa=({hasChangeableDensity:t,rowDensity:r,setRowDensity:o,hasColumnVisibility:c,columns:b,columnVisibility:i,setColumnVisibility:p})=>{const{t:f}=A(),x=a.useCallback(l=>S=>{o(l)},[o]),E=a.useCallback(l=>S=>{p(g=>({...g,[l]:g?g[l]===!1:!1}))},[p]),M=a.useMemo(()=>b.reduce((l,S)=>{const g=i?i[S.accessorKey]!==!1:!0;return l[S.accessorKey]=g,l},{}),[b,i]);return e.jsxs(e.Fragment,{children:[t&&e.jsx(H,{ariaLabel:f("table.density.arialabel"),endIcon:e.jsx(za,{}),menuAlignment:"right",shouldCloseOnSelect:!1,children:e.jsx(e.Fragment,{children:Se.map(l=>e.jsx(w,{isSelected:r===l,onClick:x(l),children:f(`table.density.${l}`)},l))})}),c&&e.jsx(H,{ariaLabel:f("table.columnvisibility.arialabel"),endIcon:e.jsx(wa,{}),menuAlignment:"right",shouldCloseOnSelect:!1,children:e.jsx(e.Fragment,{children:b.filter(l=>l.enableHiding!==!1).map(l=>e.jsxs(w,{onClick:E(l.id),children:[e.jsx(va,{checked:M[l.accessorKey]}),l.header]},l.accessorKey))})})]})},ye=a.memo(Pa);ye.displayName="DataTableSettings";/*!
 * Copyright (c) 2023-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 Ha=ua("div",{shouldForwardProp:t=>t!=="odysseyDesignTokens"&&t!=="isScrollableStart"&&t!=="isScrollableEnd"})(({odysseyDesignTokens:t,isScrollableStart:r,isScrollableEnd:o})=>({marginBlockEnd:t.Spacing4,position:"relative",borderInlineStartColor:r?t.HueNeutral200:"transparent",borderInlineStartStyle:"solid",borderInlineStartWidth:t.BorderWidthMain,"::before":{background:"linear-gradient(-90deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.33) 50%, rgba(0, 0, 0, 1) 100%)",content:'""',opacity:r?"0.075":"0",pointerEvents:"none",position:"absolute",top:0,left:0,bottom:0,width:t.Spacing6,zIndex:100,transition:`opacity ${t.TransitionDurationMain} ${t.TransitionTimingMain}`},borderInlineEndColor:o?t.HueNeutral200:"transparent",borderInlineEndStyle:"solid",borderInlineEndWidth:t.BorderWidthMain,"::after":{background:"linear-gradient(90deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.33) 50%, rgba(0, 0, 0, 1) 100%)",content:'""',opacity:o?"0.075":"0",pointerEvents:"none",position:"absolute",top:0,right:0,bottom:0,width:t.Spacing6,transition:`opacity ${t.TransitionDurationMain} ${t.TransitionTimingMain}`}})),Ka=t=>t.id,Na=({additionalActionButton:t,additionalActionMenuItems:r,bulkActionMenuItems:o,columns:c,currentPage:b=1,emptyPlaceholder:i,errorMessage:p,filters:f,getData:x,getRowId:E=Ka,hasChangeableDensity:M,hasColumnResizing:l,hasColumnVisibility:S,hasFilters:g,hasPagination:je,hasRowReordering:T,hasRowSelection:Ie,hasSearch:q,hasSearchSubmitButton:Me,hasSorting:De,initialDensity:ze=Se[0],initialSearchValue:J="",isPaginationMoreDisabled:ke,noResultsPlaceholder:Q,onChangeRowSelection:K,onReorderRows:h,paginationType:X="paged",renderDetailPanel:ve,resultsPerPage:_=20,maxResultsPerPage:we,maxPages:Ee,rowActionButtons:D,rowActionMenuItems:F,searchDelayTime:Fe,selectedRows:Be,totalRows:B})=>{const{t:m}=A(),[z,Y]=a.useState([]),[d,Z]=a.useState({pageIndex:b,pageSize:_}),[y,Pe]=a.useState(),[He,Ke]=a.useState(!0),[Ne,We]=a.useState(!0),[R,Le]=a.useState("100%"),ee=a.useRef(null),ae=a.useRef(null),Ve=a.useRef(null),[P,$e]=a.useState([]),[ne,_e]=a.useState(),[N,Ge]=a.useState(ze),[k,Oe]=a.useState(J),[j,Ue]=a.useState(),[G,Ae]=a.useState(),[qe,te]=a.useState(!0),[W,Je]=a.useState(),[se,ie]=a.useState(p),[Qe,Xe]=a.useState({}),v=Be||Qe;Ea({tableOuterContainer:ee.current,tableInnerContainer:ae.current,setIsTableContainerScrolledToStart:Ke,setIsTableContainerScrolledToEnd:We,setTableInnerContainerWidth:Le});const O=ma(),{dragHandleStyles:le,dragHandleText:re,draggableTableBodyRowClassName:oe,handleDragHandleKeyDown:ce,handleDragHandleOnDragCapture:de,handleDragHandleOnDragEnd:be,resetDraggingAndHoveredRow:me,updateRowOrder:ue}=Fa({totalRows:B,onReorderRows:h,data:z,setData:Y,draggingRow:y,setDraggingRow:Pe,resultsPerPage:d.pageSize,page:d.pageIndex}),ge=a.useMemo(()=>N==="spacious"?"MuiTableBody-spacious":N==="compact"?"MuiTableBody-compact":"MuiTableBody-default",[N]),Ye=a.useCallback(({row:n})=>{const s=n.index+(d.pageIndex-1)*d.pageSize;return e.jsx(Te,{row:n,rowActionButtons:D,rowActionMenuItems:F,rowIndex:s,totalRows:B,updateRowOrder:T&&h?ue:void 0})},[d,D,F,T,h,B,ue]),pe=a.useCallback(n=>n==null?void 0:n.map(s=>typeof s=="string"?{label:s,value:s}:{label:s.label??s.value,value:s.value??s.label}),[]),U=a.useCallback(n=>n.enableColumnFilter!==!1&&n.accessorKey?{id:n.accessorKey,label:n.header,variant:n.filterVariant,options:pe(n.filterSelectOptions)}:null,[pe]),Ze=a.useMemo(()=>(f||c).reduce((s,u)=>{if(typeof u=="string"){const C=c.find(L=>L.accessorKey===u);if(C){const L=U(C);if(L)return s.concat(L)}}else if("accessorKey"in u){const C=U(u);if(C)return s.concat(C)}else if("label"in u)return s.concat(u);return s},[]),[c,f,U]),Re=a.useCallback(({cell:n})=>{const s=n.getValue();return n.column.columnDef.hasTextWrapping||n.column.columnDef.enableWrapping?s:e.jsx(I,{sx:{whiteSpace:"nowrap",textOverflow:"ellipsis",overflow:"hidden"},children:s})},[]),ea=a.useCallback(()=>{const n=Q||e.jsx(Ca,{description:m("table.noresults.text"),heading:m("table.noresults.heading")}),s=i&&W?i:n;return e.jsx(I,{sx:{width:R},children:s})},[i,W,Q,m,R]),fe=a.useMemo(()=>c.map(n=>n.accessorKey),[c]),aa=a.useMemo(()=>["mrt-row-drag","mrt-row-select","mrt-row-expand",...fe,"mrt-row-actions"],[fe]),xe=a.useMemo(()=>!!(T===!0&&h||D||F),[T,h,D,F]),na=a.useCallback(()=>({className:ge}),[ge]),ta=a.useCallback(({column:n})=>({className:n.getIsResizing()?"isResizing":"",sx:{overflowWrap:"anywhere"}}),[]),sa=a.useCallback(({row:n})=>({sx:{paddingBlock:n.getIsExpanded()?`${O.Spacing3} !important`:void 0}}),[O.Spacing3]),ia=a.useCallback(({table:n,row:s,isDetailPanel:u})=>{var C;return{className:oe({currentRowId:s.id,draggingRowId:y==null?void 0:y.id,hoveredRowId:(C=n.getState().hoveredRow)==null?void 0:C.id}),sx:{...u&&{paddingBlock:"0 !important",border:0,"&:hover":{backgroundColor:"transparent !important"}}}}},[oe,y==null?void 0:y.id]),la=a.useCallback(({table:n,row:s})=>({onKeyDown:u=>ce({table:n,row:s,event:u}),onBlur:()=>me(n),onDragEnd:()=>be(n),onDragCapture:()=>de(n),sx:le,...re}),[le,re,ce,me,be,de]),ra=a.useCallback(({column:n})=>({className:P.find(s=>s.id===n.id)?"isSorted":"isUnsorted"}),[P]),oa=a.useMemo(()=>c.some(n=>n.grow===!0),[c]),ca=pa({columns:c,data:z,getRowId:E,state:{sorting:P,globalFilter:k,columnVisibility:ne,isLoading:qe,rowSelection:v,columnOrder:aa},icons:{ArrowDownwardIcon:Ce,DragHandleIcon:he,SyncAltIcon:ka,ExpandMoreIcon:ga},enableColumnActions:!1,enableColumnResizing:l,enableDensityToggle:!1,enableFilters:!1,enableFullScreenToggle:!1,enableGlobalFilter:!1,enableHiding:!1,enablePagination:!1,layoutMode:"grid-no-grow",manualFiltering:!0,manualSorting:!0,muiTablePaperProps:{elevation:0,sx:{overflow:"visible"}},selectAllMode:"all",displayColumnDefOptions:{"mrt-row-actions":{header:"",grow:!0,muiTableBodyCellProps:{align:"right",sx:{overflow:"visible",width:"unset"},className:"ods-actions-cell"},muiTableHeadCellProps:{align:"right",sx:{width:"unset"},className:"ods-actions-cell",children:e.jsxs(I,{sx:{display:"flex",visibility:"hidden"},children:[D&&D({id:null}),(T&&h||F)&&e.jsx(I,{children:e.jsx(xa,{ariaLabel:m("table.moreactions.arialabel"),endIcon:e.jsx($,{}),isDisabled:!0,size:"small",variant:"floating"})})]})}},"mrt-row-drag":{header:"",muiTableBodyCellProps:{sx:{minWidth:0,width:"auto"},className:"ods-drag-handle"},muiTableHeadCellProps:{sx:{minWidth:0,width:"auto"},children:e.jsx(I,{sx:{marginInline:"-0.1rem"},children:e.jsx(he,{sx:{marginInline:1,opacity:0}})})}},"mrt-row-select":{muiTableHeadCellProps:{padding:"checkbox"},muiTableBodyCellProps:{padding:"checkbox"}},"mrt-row-expand":{header:""}},muiTableBodyProps:na,defaultColumn:{Cell:Re},muiTableBodyCellProps:ta,enableRowOrdering:T&&!!h,enableRowDragging:T&&!!h,muiDetailPanelProps:sa,muiTableBodyRowProps:ia,muiRowDragHandleProps:la,enableRowActions:xe,positionActionsColumn:"last",renderRowActions:({row:n})=>Ye({row:n}),enableRowSelection:Ie,onRowSelectionChange:Xe,enableSorting:De,onSortingChange:$e,muiTableHeadCellProps:ra,enableRowVirtualization:X!=="loadMore"&&d.pageSize>50,rowVirtualizerInstanceRef:a.useRef(null),rowVirtualizerOptions:{overscan:4},renderEmptyRowsFallback:ea,muiTableProps:{ref:Ve,className:!xe&&l?oa?"ods-hide-spacer-column":"ods-hide-spacer-column ods-column-grow":""},muiTableContainerProps:{ref:ae},enableExpandAll:!1,renderDetailPanel:ve}),da=a.useMemo(()=>e.jsx(e.Fragment,{children:e.jsx(H,{ariaLabel:"More actions",buttonVariant:"secondary",endIcon:e.jsx($,{}),isDisabled:Object.keys(v).length===0,children:o==null?void 0:o(v)})}),[o,v]);a.useEffect(()=>{(async()=>{te(!0),ie(p);try{const n=await(x==null?void 0:x({page:d.pageIndex,resultsPerPage:d.pageSize,search:k,filters:j,sort:P}));Y(n)}catch(n){ie(typeof n=="string"?n:m("table.error"))}finally{te(!1)}})()},[P,p,j,x,d,k,m]),a.useEffect(()=>{!G&&j&&Ae(j),Je(d.pageIndex===b&&d.pageSize===_&&k===""&&j===G&&z.length===0)},[j,d,k,z,b,G,_]),a.useEffect(()=>{Z(n=>({pageIndex:1,pageSize:n.pageSize}))},[j,k]),a.useEffect(()=>{K==null||K(v)},[v,K]);const{lastRow:ba}=Ta({currentRowsCount:z.length,pageIndex:d.pageIndex,pageSize:d.pageSize,totalRows:B});return e.jsxs(e.Fragment,{children:[(q||g||M||S||o||t||r)&&e.jsx(I,{sx:{marginBottom:5},children:e.jsx(Sa,{additionalActions:e.jsxs(e.Fragment,{children:[e.jsx(ye,{columns:c,columnVisibility:ne,hasChangeableDensity:M,hasColumnVisibility:S,rowDensity:N,setColumnVisibility:_e,setRowDensity:Ge}),o&&da,t,r&&e.jsx(H,{ariaLabel:m("table.moreactions.arialabel"),buttonVariant:"secondary",endIcon:e.jsx($,{}),menuAlignment:"right",children:r})]}),defaultSearchTerm:J,filters:g?Ze:void 0,hasSearchSubmitButton:Me,isDisabled:W,onChangeFilters:g?Ue:void 0,onChangeSearch:q?Oe:void 0,searchDelayTime:Fe})}),se&&e.jsx(I,{sx:{marginBlockEnd:2},children:e.jsx(ha,{severity:"error",text:se})}),e.jsx(Ha,{isScrollableEnd:!Ne,isScrollableStart:!He,odysseyDesignTokens:O,ref:ee,children:e.jsx(fa,{table:ca})}),je&&e.jsx(ya,{currentPageLabel:m("pagination.page"),currentRowsCount:z.length,isDisabled:W,isMoreDisabled:ke,lastRow:ba,loadMoreLabel:m("pagination.loadmore"),maxPageIndex:Ee,maxPageSize:we,nextLabel:m("pagination.next"),onPaginationChange:Z,pageIndex:d.pageIndex,pageSize:d.pageSize,previousLabel:m("pagination.previous"),rowsPerPageLabel:m("pagination.rowsperpage"),totalRows:B,variant:X})]})},Wa=a.memo(Na);Wa.displayName="DataTable";export{Wa as M,Se as d};
