import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import Box from '../box';
import { useStyleConfig, vui } from '../core';
import { cs, isJsx, runIfFn } from '../utils';
import { PaginationProvider } from './context';
import PaginationButton from './paginationButton';
import PaginationEllipsis from './paginationEllipsis';
import PaginationGoToPage from './paginationGoToPage';
import PaginationNavigation from './paginationNavigation';
import PaginationPrevNext from './paginationPrevNext';
import PaginationResults from './paginationResults';
import usePagination from './usePagination';
/**
 * Displays page navigation buttons together with page and item count.
 * GoToPage component is shown automatically above 10 pages.
 */
export const Pagination = vui((props, ref) => {
    const { children, className, count, defaultPage, goToPage, items: itemsProp = [], navigation, onPageChange, page: pageProp, pageSize, results, size, variant, ...rest } = props;
    const styles = useStyleConfig('Pagination', props);
    const { items = itemsProp, ...paginationProps } = usePagination({
        count,
        defaultPage,
        onPageChange,
        page: pageProp,
        pageSize,
    });
    const context = { ...paginationProps, items, size, variant };
    return (_jsx(PaginationProvider, { value: context, children: _jsx(Box, { centerV: true, className: cs('vui-pagination', className), gap: 3, ref: ref, w: 1, wrap: true, ...styles.container, ...rest, children: runIfFn(children, context) ?? (_jsxs(_Fragment, { children: [isJsx(results) ? results : _jsx(PaginationResults, {}), isJsx(navigation) ? navigation : _jsx(PaginationNavigation, { ml: "auto" }), isJsx(goToPage) ? goToPage : paginationProps.pageCount > 10 && _jsx(PaginationGoToPage, {})] })) }) }));
});
Pagination.Button = PaginationButton;
Pagination.Ellipsis = PaginationEllipsis;
Pagination.GoToPage = PaginationGoToPage;
Pagination.Navigation = PaginationNavigation;
Pagination.PrevNext = PaginationPrevNext;
Pagination.Results = PaginationResults;
Pagination.displayName = 'Pagination';
export default Pagination;
//# sourceMappingURL=pagination.js.map