import { isJsx } from "../utils/assertion.js";
import { runIfFn } from "../utils/function.js";
import { cs } from "../utils/styles.js";
import { useStyleConfig } from "../core/theme.js";
import vui from "../core/vui.js";
import Box from "../box/box.js";
import { PaginationProvider } from "./context.js";
import PaginationButton from "./paginationButton.js";
import PaginationEllipsis from "./paginationEllipsis.js";
import PaginationGoToPage from "./paginationGoToPage.js";
import PaginationPrevNext from "./paginationPrevNext.js";
import PaginationNavigation from "./paginationNavigation.js";
import PaginationResults from "./paginationResults.js";
import usePagination from "./usePagination.js";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";

//#region src/pagination/pagination.tsx
/**
* Displays page navigation buttons together with page and item count.
* GoToPage component is shown automatically above 10 pages.
*/
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 /* @__PURE__ */ jsx(PaginationProvider, {
		value: context,
		children: /* @__PURE__ */ jsx(Box, {
			centerV: true,
			className: cs("vui-pagination", className),
			gap: 3,
			ref,
			w: 1,
			wrap: true,
			...styles.container,
			...rest,
			children: runIfFn(children, context) ?? /* @__PURE__ */ jsxs(Fragment, { children: [
				isJsx(results) ? results : /* @__PURE__ */ jsx(PaginationResults, {}),
				isJsx(navigation) ? navigation : /* @__PURE__ */ jsx(PaginationNavigation, { ml: "auto" }),
				isJsx(goToPage) ? goToPage : paginationProps.pageCount > 10 && /* @__PURE__ */ jsx(PaginationGoToPage, {})
			] })
		})
	});
});
Pagination.Button = PaginationButton;
Pagination.Ellipsis = PaginationEllipsis;
Pagination.GoToPage = PaginationGoToPage;
Pagination.Navigation = PaginationNavigation;
Pagination.PrevNext = PaginationPrevNext;
Pagination.Results = PaginationResults;
Pagination.displayName = "Pagination";

//#endregion
export { Pagination as default };
globalThis.__vuiVersion__ = "4.0.0-beta.1"
//# sourceMappingURL=pagination.js.map