import{o as e}from"./rolldown-runtime-BM3Ffeng.js";import{t}from"./chevron-left-Deqsuxdc.js";import{C_ as n,Gy as r,Hy as i,Nf as a,Zv as o,i_ as s,kp as c,m_ as l,mv as u,n_ as d,r_ as f,w_ as p}from"./index-DDwwBb9e.js";var m=e(r()),h=i(),g=25,_=[10,25,50,100,250],v=(e,t)=>{if(typeof e==`string`){let n=parseInt(e,10);return isNaN(n)?t:n}return t},y=e=>{if(!e)return null;try{let t=JSON.parse(atob(e));return{lastTimestamp:t.lastTimestamp,lastTraceId:t.lastTraceId,pageSize:t.pageSize,sortDirection:t.sortDirection}}catch(e){return console.warn(`Failed to decode cursor:`,e),null}},b=()=>{let e=c(),[t,n]=(0,m.useState)(0),[r,i]=(0,m.useState)(1),a=(0,m.useRef)([]),o=(0,m.useMemo)(()=>v(e.query.pageOffset,0),[e.query.pageOffset]),s=(0,m.useMemo)(()=>v(e.query.pageSize,g),[e.query.pageSize]),l=e.query.scrollId,u=!!l,d=(0,m.useMemo)(()=>y(l),[l]),f=Math.ceil(t/(d?.pageSize||s));(0,m.useEffect)(()=>{u||(i(1),a.current=[])},[u]);let p=(0,m.useCallback)(t=>{let{pageOffset:n,pageSize:r,scrollId:i,...a}=e.query,c={...a},l=t.pageOffset??o,u=t.pageSize??s,d=t.scrollId;return l!==0&&(c.pageOffset=l.toString()),u!==g&&(c.pageSize=u.toString()),d&&(c.scrollId=d),c},[e.query,o,s]),h=(0,m.useCallback)(t=>{if(t)l&&a.current.push(l),i(e=>e+1),e.push({pathname:e.pathname,query:p({scrollId:t})},void 0,{shallow:!0});else if(u)return;else e.push({pathname:e.pathname,query:p({pageOffset:o+s})},void 0,{shallow:!0})},[e,o,s,u,l,p]),_=(0,m.useCallback)(()=>{if(u){let t=a.current;if(t.length>0){let n=t.pop();i(e=>Math.max(1,e-1)),e.push({pathname:e.pathname,query:p({scrollId:n})},void 0,{shallow:!0})}else i(1),e.push({pathname:e.pathname,query:p({pageOffset:0,scrollId:null})},void 0,{shallow:!0})}else o>0&&e.push({pathname:e.pathname,query:p({pageOffset:o-s})},void 0,{shallow:!0})},[e,o,s,u,p]),b=(0,m.useCallback)(t=>{e.push({pathname:e.pathname,query:p({pageSize:t,pageOffset:0,scrollId:null})},void 0,{shallow:!0})},[e,p]),x=e=>{(0,m.useEffect)(()=>{e.isFetched&&n(e.data?.totalHits??0)},[e.data?.totalHits,e.isFetched,e.data])},S=(0,m.useRef)(e.query.query);return(0,m.useEffect)(()=>{e.query.project&&S.current!==e.query.query&&(S.current=e.query.query,e.push({pathname:e.pathname,query:p({pageOffset:0,pageSize:g,scrollId:null})},void 0,{shallow:!0}))},[e.query.query]),{totalHits:t,pageOffset:o,pageSize:s,useCursorPagination:u,cursorInfo:d,cursorPageNumber:r,estimatedTotalPages:f,nextPage:h,prevPage:_,changePageSize:b,useUpdateTotalHits:x}};function x({totalHits:e,pageOffset:r,pageSize:i,useCursorPagination:c=!1,cursorInfo:m=null,cursorPageNumber:g=1,estimatedTotalPages:v=1,nextPage:y,prevPage:b,changePageSize:x,scrollId:S}){if(e===0&&r===0&&!c)return null;let C=c?g<=1:r===0,w=c?!S:r+i>=e;return(0,h.jsxs)(l,{padding:6,gap:2,children:[(0,h.jsx)(p,{children:(0,h.jsxs)(l,{gap:3,children:[(0,h.jsx)(n,{flexShrink:0,children:`Items per page`}),(0,h.jsxs)(s,{size:`sm`,children:[(0,h.jsx)(d,{value:i.toString(),onChange:e=>x(parseInt(e.target.value,10)),borderColor:`black`,borderRadius:`lg`,children:_.map(e=>(0,h.jsx)(`option`,{value:e.toString(),children:e},e))}),(0,h.jsx)(f,{})]})]})}),(0,h.jsxs)(l,{gap:3,paddingRight:3,children:[(0,h.jsx)(o,{flexShrink:0,children:c?`Page ${g} of ~${v} (${e} total items)`:`${r+1}-${Math.min(r+i,e)} of ${e} items`}),(0,h.jsxs)(l,{gap:0,children:[(0,h.jsx)(u,{variant:`ghost`,padding:0,onClick:b,disabled:C,"aria-label":`Go to previous page`,title:`Go to previous page`,children:(0,h.jsx)(t,{})}),(0,h.jsx)(u,{variant:`ghost`,padding:0,disabled:w,onClick:()=>y(S),"aria-label":`Go to next page`,title:`Go to next page`,children:(0,h.jsx)(a,{})})]})]})]})}var S=b,C=x;export{S as n,C as t};
//# sourceMappingURL=NavigationFooter-CduKH6Fq.js.map