import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";var _excluded=["items","value","onChange","size","form","type","containerEventListener","getTotalLabel","outerMostArrows","arrows","hotKeys","showFirstPage","showLastPage","visibleCount","className"];import"./Pagination.css";import React,{forwardRef,useMemo}from"react";import{useForkRef}from"../../hooks/useForkRef";import{cnMixFlex}from"../../mixs/MixFlex";import{cn}from"../../utils/bem";import{defaultGetItemClickable,defaultGetItemKey,defaultGetItemLabel,getListValue,paginationArrowIconsMap}from"./helpers";import{PaginationArrow}from"./PaginationArrow";import{PaginationList}from"./PaginationList";import{PaginationNumberInput}from"./PaginationNumberInput";import{paginationPropFormDefault,paginationPropSizeDefault,paginationPropTypeDefault}from"./types";import{usePaginationItems}from"./usePaginationItems";var cnPagination=cn("Pagination"),PaginationRender=function(a,b){var c=a.items,d=void 0===c?0:c,e=a.value,f=a.onChange,g=a.size,h=void 0===g?paginationPropSizeDefault:g,i=a.form,j=void 0===i?paginationPropFormDefault:i,k=a.type,l=void 0===k?paginationPropTypeDefault:k,m=a.containerEventListener,n=void 0===m?window:m,o=a.getTotalLabel,p=a.outerMostArrows,q=a.arrows,r=a.hotKeys,s=a.showFirstPage,t=a.showLastPage,u=a.visibleCount,v=a.className,w=_objectWithoutProperties(a,_excluded),x=Math.max(null!==e&&void 0!==e?e:0,0),y=function(a,b,c,e,f){var g="first"===b||"previous"===b?1<x:x<d,i="first"===b||"previous"===b?"start":"end";if("object"==typeof a){var k=a.label,l=a.icon,m=void 0===l?paginationArrowIconsMap[b]:l;return React.createElement(PaginationArrow,{label:k,icon:m,disabled:!g,size:h,form:j,ref:c,orientation:i,caption:null===e||void 0===e?void 0:e.label,onClick:f})}return React.createElement(PaginationArrow,{orientation:i,icon:"function"==typeof a?a:paginationArrowIconsMap[b],disabled:!g,size:h,form:j,ref:c,onClick:f})},z=function(a){return function(b){var c=d;"first"===a&&(c=1),"previous"===a&&(c=Math.max(x-1,1)),"next"===a&&(c=Math.min(x+1,d)),null===f||void 0===f?void 0:f(c,{e:b})}},A=usePaginationItems({showFirstPage:s,showLastPage:t,items:d,visibleCount:u,size:h,value:x,containerEventListener:n,hotKeys:r}),B=A.pages,C=A.wrapperRef,D=A.buttonRefs,E=useForkRef([b,C]),F=useMemo(function(){return getListValue(x)},[x]);return 0===d?null:React.createElement("nav",Object.assign({className:cnPagination({size:h,form:j},[v,cnMixFlex({wrap:"nowrap",gap:"input"===l?"xs":"3xs"})]),ref:E},w),(null===p||void 0===p?void 0:p[0])&&y(p[0],"first",D[0],void 0,z("first")),(null===q||void 0===q?void 0:q[0])&&y(q[0],"previous",D[1],null===r||void 0===r?void 0:r[0],z("previous")),"default"===l?React.createElement(PaginationList,{items:B,form:j,size:h,value:F,getItemKey:defaultGetItemKey,getItemLabel:defaultGetItemLabel,getItemClickable:defaultGetItemClickable,onItemClick:function onItemClick(a,b){var c=a.page,d=b.e;c!==x&&(null===f||void 0===f?void 0:f(c,{e:d}))}}):React.createElement(PaginationNumberInput,{form:j,size:h,total:d,value:e?x:void 0,onChange:f,getTotalLabel:o}),(null===q||void 0===q?void 0:q[1])&&y(q[1],"next",D[2],null===r||void 0===r?void 0:r[1],z("next")),(null===p||void 0===p?void 0:p[1])&&y(p[1],"last",D[3],void 0,z("last")))};export var Pagination=forwardRef(PaginationRender);
//# sourceMappingURL=Pagination.js.map