"use strict";const t=require("react/jsx-runtime"),i=require("react"),k=require("@commercetools/nimbus-icons"),u=require("./normalize-messages-CaDzkuUm.cjs.js"),w=require("./context-CyT9C4U4.cjs.js"),R=require("./stack-CIN13EDn.cjs.js"),b=require("@chakra-ui/react/flex"),I=require("./select-Dq_6o0BB.cjs.js"),M=require("./text-BtRhIklG.cjs.js"),A=require("./icon-button-CeB8_Yyr.cjs.js"),_=require("./number-input-CR1hdy-B.cjs.js");function B({totalItems:e,currentPage:x,pageSize:o=20,onPageChange:l,onPageSizeChange:h}){const[v,p]=i.useState(1),[j,z]=i.useState(o),s=x!==void 0,C=s?x:v,g=o??j,a=Math.max(1,Math.ceil(e/g)),n=Math.max(1,Math.min(C,a)),d=Math.min((n-1)*g+1,e),r=Math.min(n*g,e),c=n>1,f=n<a,P=i.useCallback(m=>{const T=Math.max(1,Math.min(m,a));s||p(T),l?.(T)},[a,s,l]),N=i.useCallback(()=>{c&&P(n-1)},[c,n,P]),q=i.useCallback(()=>{f&&P(n+1)},[f,n,P]),$=i.useCallback(m=>{const T=Math.ceil(e/m),S=Math.min(n,T);z(m),!s&&S!==n&&p(S),h?.(m),S!==n&&l?.(S)},[e,n,s,l,h]);return i.useMemo(()=>({totalItems:e,currentPage:n,pageSize:g,totalPages:a,startItem:d,endItem:r,hasPreviousPage:c,hasNextPage:f,goToPage:P,goToPreviousPage:N,goToNextPage:q,setPageSize:$}),[e,n,g,a,d,r,c,f,P,N,q,$])}const O={currentPage:"Current page",goToNextPage:"Go to next page",goToPreviousPage:"Go to previous page",itemsPerPage:"Items per page",itemsPerPageText:"items per page",ofTotalPages:e=>`of ${e.totalPages}`,page:"Page",pagination:"Pagination"},y={currentPage:"Aktuelle Seite",goToNextPage:"Weiter zur nächsten Seite",goToPreviousPage:"Zur vorherigen Seite",itemsPerPage:"Artikel pro Seite",itemsPerPageText:"Artikel pro Seite",ofTotalPages:e=>`von ${e.totalPages}`,page:"Seite",pagination:"Seitennummerierung"},D={currentPage:"Página actual",goToNextPage:"Ir a la siguiente página",goToPreviousPage:"Ir a la página anterior",itemsPerPage:"Artículos por página",itemsPerPageText:"artículos por página",ofTotalPages:e=>`de ${e.totalPages}`,page:"página",pagination:"paginación"},G={currentPage:"Page actuelle",goToNextPage:"Aller à la page suivante",goToPreviousPage:"Aller à la page précédente",itemsPerPage:"Articles par page",itemsPerPageText:"Articles par page",ofTotalPages:e=>`de ${e.totalPages}`,page:"Page",pagination:"Pagination"},L={currentPage:"Página atual",goToNextPage:"Ir para a próxima página",goToPreviousPage:"Ir para a página anterior",itemsPerPage:"Itens por página",itemsPerPageText:"Itens por página",ofTotalPages:e=>`de ${e.totalPages}`,page:"Página",pagination:"Paginação"},V={en:u.normalizeMessages(O),de:u.normalizeMessages(y),es:u.normalizeMessages(D),"fr-FR":u.normalizeMessages(G),"pt-BR":u.normalizeMessages(L)},F=e=>{const{locale:x}=w.$18f2051aff69b9bf$export$43bb16f9c6d9e3f7(),o=u.useLocalizedStringFormatter(V),{totalItems:l,currentPage:h,pageSize:v,pageSizeOptions:p=[10,20,50,100],onPageChange:j,onPageSizeChange:z,"aria-label":s,enablePageInput:C=!0,enablePageSizeSelector:g=!0}=e,a=B({totalItems:l,currentPage:h,pageSize:v,onPageChange:j,onPageSizeChange:z}),n=i.useMemo(()=>p.map(r=>({id:r.toString(),name:`${r}`})),[p]),d=r=>{if(r){const c=parseInt(r.toString(),10);a.setPageSize(c)}};return t.jsxs(R.Stack,{gap:"400",direction:{base:"column",sm:"row"},align:"center",children:[g&&t.jsxs(b.Flex,{align:"center",gap:"200",children:[t.jsx(I.Select.Root,{isClearable:!1,selectedKey:a.pageSize.toString(),onSelectionChange:d,"aria-label":o.format("itemsPerPage"),children:t.jsx(I.Select.Options,{children:n.map(r=>t.jsx(I.Select.Option,{id:r.id,children:r.name},r.id))})}),t.jsx(M.Text,{color:"neutral.12",children:o.format("itemsPerPageText")})]}),t.jsx(b.Flex,{flexGrow:"1"}),t.jsxs(b.Flex,{align:"center",gap:"200",role:"navigation","aria-label":s??o.format("pagination"),children:[t.jsx(A.IconButton,{onClick:a.goToPreviousPage,isDisabled:!a.hasPreviousPage,variant:"ghost",colorPalette:"primary","aria-label":o.format("goToPreviousPage"),children:t.jsx(k.ChevronLeft,{})}),t.jsxs(b.Flex,{align:"center",gap:"200",children:[t.jsx(M.Text,{color:"neutral.12",children:o.format("page")}),C?t.jsx(_.NumberInput,{value:a.currentPage,onChange:r=>a.goToPage(r||1),minValue:1,maxValue:a.totalPages,step:1,isDisabled:!1,width:"9ch","aria-label":o.format("currentPage"),"aria-current":"page"}):t.jsx(M.Text,{fontWeight:"semibold",color:"neutral.12","aria-current":"page",children:a.currentPage}),t.jsx(M.Text,{color:"neutral.12",children:(()=>{const r=new Intl.NumberFormat(x).format(a.totalPages);return o.format("ofTotalPages",{totalPages:r})})()})]}),t.jsx(A.IconButton,{onClick:a.goToNextPage,isDisabled:!a.hasNextPage,variant:"ghost",colorPalette:"primary","aria-label":o.format("goToNextPage"),children:t.jsx(k.ChevronRight,{})})]})]})};F.displayName="Pagination";exports.Pagination=F;
//# sourceMappingURL=pagination-BIxlGft7.cjs.js.map
