"use strict";const t=require("react/jsx-runtime"),d=require("react"),N=require("../tools/icons.cjs"),g=require("../tools/tools.cjs"),A=require("./pagination-basic.cjs"),b=require("./pagination-item.cjs"),f=require("./pagination-link.cjs"),M=require("./pagination-nav.cjs"),R=require("./pagination-span.cjs"),I=(p,x,P,u)=>g.generatePagination(p,x,P,u).map((h,j)=>({active:p===h,dots:typeof h=="string",hover:!1,id:j,value:h})),c=function(x){const{alignment:P,alwaysShowEllipsis:u=!1,as:h="ul",className:j,dropOldClass:B,maxVisible:v=4,navProps:w,next:E=!0,nextOption:e,onChange:m,option:n,page:K=0,previous:T=!0,previousOption:i,size:L,style:D,total:k=0,variables:_,...V}=x,[r,q]=d.useState(I(K,k,v,u)),$=d.useMemo(()=>{const a=g.classx(!B&&"pagination",L&&`pagination-${L}`,P&&`justify-content-${P}`,j),o=g.stylex((s,l)=>({tKey:g.convertBsKeyToVar(l)}),_,D);return{className:a,style:o}},[P,j,B,L,D,_]),y=d.useCallback((a,o)=>{var S;const s=((S=r.find(z=>z.active))==null?void 0:S.value)??0;let l;a==="<"?l=Math.max(s-v,0):a===">"?l=Math.min(s+v,k):l=a,q(I(l,k,v,u)),m==null||m(l,o)},[u,m,r,v,k]),C=d.useCallback(()=>{const a=r.find(o=>o.active);return a?a.value:0},[r]);if(!(k<=0))return t.jsx(M.PaginationNav,{...w,children:t.jsxs(h,{...V,...$,children:[T&&t.jsx(b.PaginationItem,{...i==null?void 0:i.itemProps,disabled:(i==null?void 0:i.disabled)??C()===r[0].value,children:t.jsx(f.PaginationLink,{...g.mergeProps(i==null?void 0:i.linkProps,{href:(i==null?void 0:i.href)??""}),onClick:a=>{a.preventDefault(),y(C()-1,"previous")},children:(i==null?void 0:i.link)??"Previous"})}),r.map((a,o)=>d.createElement(b.PaginationItem,{...n==null?void 0:n.itemProps,active:a.active,key:a.id},a.dots?t.jsx(f.PaginationLink,{...n==null?void 0:n.linkProps,href:"",onClick:s=>{s.preventDefault(),y(a.value,a.value)},onMouseEnter:()=>q(s=>(s[o].hover=!0,[...s])),onMouseLeave:()=>q(s=>(s[o].hover=!1,[...s])),children:a.hover?a.value==="<"?t.jsx(N.BiChevronDoubleLeft,{}):t.jsx(N.BiChevronDoubleRight,{}):t.jsx(N.BiThreeDots,{})}):a.active&&!(n!=null&&n.clickableActive)?t.jsx(R.PaginationSpan,{...n==null?void 0:n.spanProps,children:a.value}):t.jsx(f.PaginationLink,{...n==null?void 0:n.linkProps,href:"",onClick:s=>{s.preventDefault(),y(a.value,"page")},children:a.value}))),E&&t.jsx(b.PaginationItem,{...e==null?void 0:e.itemProps,disabled:(e==null?void 0:e.disabled)??C()===r[r.length-1].value,children:t.jsx(f.PaginationLink,{...g.mergeProps(e==null?void 0:e.linkProps,{href:(e==null?void 0:e.href)??""}),onClick:a=>{a.preventDefault(),y(C()+1,"next")},children:(e==null?void 0:e.link)??"Next"})})]})})};c.Basic=A.PaginationBasic;c.Item=b.PaginationItem;c.Nav=M.PaginationNav;c.Link=f.PaginationLink;c.Span=R.PaginationSpan;c.displayName="BRL.Pagination";exports.Pagination=c;
//# sourceMappingURL=pagination.cjs.map
