import{K as F,u as te,h as v}from"./OdysseyThemeProvider-Bh0Bu-2o.js";import{r as e}from"./index-NdkWRN8K.js";import{M as E}from"./Box-1mvP3NLW.js";import{M as B}from"./Button-BEA5U6Tg.js";import{a as I}from"./Typography-Cz6D417Y.js";import{j as o}from"./jsx-runtime-CnH95YSl.js";import{M as re,a as se}from"./ArrowRight-ChWYjNny.js";import{I as ie}from"./InputBase-DeB4_faH.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 le=({currentRowsCount:n,pageIndex:x,pageSize:M,totalRows:m})=>{const{t:p}=F();return e.useMemo(()=>{const i=M*(x-1)+1,u=i+(n-1),b=n===0?p("pagination.totalrows",{totalRows:0}):m?p("pagination.rowswithtotal",{firstRow:i,lastRow:u,totalRows:m}):p("pagination.rowswithouttotal",{firstRow:i,lastRow:u});return{firstRow:i,lastRow:u,totalRowsLabel:b}},[n,x,M,m,p])},ce=v("nav")({display:"flex",justifyContent:"space-between"}),T=v("div",{shouldForwardProp:n=>n!=="odysseyDesignTokens"})(({odysseyDesignTokens:n})=>({display:"flex",alignItems:"center",gap:n.Spacing4,"& > div":{display:"flex",alignItems:"center",gap:n.Spacing2}})),z=v(ie,{shouldForwardProp:n=>n!=="odysseyDesignTokens"})(({odysseyDesignTokens:n})=>({borderColor:n.HueNeutral200,borderRadius:n.BorderRadiusTight,height:n.Spacing6,width:"4.5714285714rem","&:hover":{borderColor:n.HueNeutral400},"&.Mui-focused:hover":{borderColor:n.PalettePrimaryMain}})),ue=v("div")({"& > *":{marginInlineStart:"0 !important"}}),pe=({currentPageLabel:n,currentRowsCount:x,hasPageInput:M=!0,hasRowCountInput:m=!0,hasRowCountLabel:p=!0,isDisabled:i,isMoreDisabled:u,lastRow:b,loadMoreLabel:D,maxPageIndex:h,maxPageSize:P,nextLabel:K,onPaginationChange:N,pageIndex:g,pageSize:f,previousLabel:A,rowsPerPageLabel:H,totalRows:t,variant:O})=>{const y=te(),{t:d}=F(),[c,C]=e.useState(g),[r,j]=e.useState(f),q=e.useRef(f),k=n??d("pagination.page"),G=D??d("pagination.loadmore"),J=K??d("pagination.next"),Q=A??d("pagination.previous"),L=H??d("pagination.rowsperpage");e.useEffect(()=>{C(g),j(f)},[g,f]);const s=e.useCallback(({pageIndex:a,pageSize:l})=>{N({pageIndex:a,pageSize:l})},[N]),{totalRowsLabel:U}=le({pageIndex:g,pageSize:f,currentRowsCount:x||0,totalRows:t}),w=e.useCallback(()=>{let a=c,l=r;if(t){const S=Math.ceil(t/l);l>t&&(l=t),a>S?a=S:a<1&&(a=1)}s({pageIndex:a,pageSize:l})},[c,r,s,t]),V=e.useCallback(a=>{a.key==="Enter"&&s({pageIndex:Number(a.currentTarget.value),pageSize:r})},[r,s]),W=e.useCallback(a=>{a.key==="Enter"&&s({pageIndex:c,pageSize:Number(a.currentTarget.value)})},[c,s]),X=e.useCallback(a=>{const l=h?Math.min(Number(a.target.value),h):Number(a.target.value);C(Math.max(1,l))},[C,h]),Y=e.useCallback(a=>{const l=P?Math.min(Number(a.target.value),P):Number(a.target.value);j(Math.max(1,l))},[j,P]),Z=e.useCallback(()=>{s({pageIndex:1,pageSize:r+q.current})},[r,s]),_=e.useCallback(()=>{s({pageIndex:c+1,pageSize:r})},[s,c,r]),$=e.useCallback(()=>{s({pageIndex:c-1,pageSize:r})},[s,c,r]),R=e.useMemo(()=>u||(t?r>=t:!1),[u,r,t]),ee=e.useMemo(()=>u||b&&(t?b>=t:!1)||i,[u,t,b,i]),ae=e.useMemo(()=>g<=1||i,[g,i]),ne=e.useMemo(()=>({"aria-label":L,max:P||t}),[P,L,t]),oe=e.useMemo(()=>({"aria-label":k,max:h}),[k,h]);return O==="paged"?o.jsxs(ce,{"aria-label":d("pagination.label"),children:[o.jsxs(T,{odysseyDesignTokens:y,children:[m&&o.jsxs(E,{children:[o.jsx(I,{color:"textSecondary",component:"span",children:L}),o.jsx(z,{disabled:i,inputProps:ne,odysseyDesignTokens:y,onBlur:w,onChange:Y,onKeyDown:W,type:"number",value:r})]}),p&&o.jsx(I,{color:"textSecondary",component:"span",children:U})]}),o.jsxs(T,{odysseyDesignTokens:y,children:[t&&M&&o.jsxs(E,{children:[o.jsx(I,{color:"textSecondary",component:"span",children:k}),o.jsx(z,{disabled:i,inputProps:oe,odysseyDesignTokens:y,onBlur:w,onChange:X,onKeyDown:V,type:"number",value:c})]}),o.jsxs(ue,{children:[o.jsx(B,{ariaLabel:Q,isDisabled:ae,onClick:$,size:"small",startIcon:o.jsx(re,{}),variant:"floating"}),o.jsx(B,{ariaLabel:J,endIcon:o.jsx(se,{}),isDisabled:ee,onClick:_,size:"small",variant:"floating"})]})]})]}):o.jsx(B,{isDisabled:R,label:G,onClick:Z,variant:"secondary"})},ge=e.memo(pe);ge.displayName="Pagination";export{ge as M,le as u};
