import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _objectWithoutProperties } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js";
import Pagination from "../../../Pagination/index.js";
import { useRecordBoardContext } from "../../hooks/useRecordBoardContext.js";
import React, { useMemo } from "react";
import "./index.less";
//#region src/components/pisellRecordBoard/shellFrame/Pagination/index.tsx
const _excluded = ["render"];
const defaultPagination = {
	pageNumber: 1,
	pageSize: 50
};
/**
* RecordBoard 下的分页：接入 packages/materials 的 Pagination，从 context 取 pagination / total / onPageChange；可透传 childComponentProps.pagination。
* 当 context 中 pagination 缺失时使用默认分页，避免在 Storybook 或未完整注入 context 时报错。
*/
const RecordBoardPagination = (props) => {
	var _ctx$pagination, _ctx$childComponentPr3;
	const ctx = useRecordBoardContext({ displayName: "pagination" });
	const { render } = props, rest = _objectWithoutProperties(props, _excluded);
	const pagination = (_ctx$pagination = ctx.pagination) !== null && _ctx$pagination !== void 0 ? _ctx$pagination : defaultPagination;
	const paginationProps = useMemo(() => {
		var _ctx$childComponentPr, _ctx$childComponentPr2;
		return _objectSpread2({
			current: pagination.pageNumber,
			pageSize: pagination.pageSize,
			total: ctx.total,
			onChange: ctx.onPageChange
		}, (_ctx$childComponentPr = (_ctx$childComponentPr2 = ctx.childComponentProps) === null || _ctx$childComponentPr2 === void 0 ? void 0 : _ctx$childComponentPr2.pagination) !== null && _ctx$childComponentPr !== void 0 ? _ctx$childComponentPr : {});
	}, [
		pagination.pageNumber,
		pagination.pageSize,
		ctx.total,
		ctx.onPageChange,
		(_ctx$childComponentPr3 = ctx.childComponentProps) === null || _ctx$childComponentPr3 === void 0 ? void 0 : _ctx$childComponentPr3.pagination
	]);
	/**
	* 渲染优先级：组件 `render` prop > 容器根 props 透传过来的 `ctx.paginationRender` > 默认 materials Pagination。
	* 这样业务方（如 reservation hud 抽屉）只需在 `<PisellRecordBoard paginationRender={...} />`
	* 就能彻底替换默认分页（含外层 50px 高边框容器、Previous/Next 大按钮）为 antd 原生 small Pagination。
	*/
	const effectiveRender = render !== null && render !== void 0 ? render : ctx.paginationRender;
	if (typeof effectiveRender === "function") return /* @__PURE__ */ React.createElement(React.Fragment, null, effectiveRender(_objectSpread2(_objectSpread2({}, ctx), rest)));
	if (ctx.total === 0) return /* @__PURE__ */ React.createElement("div", {
		"data-layout-slot": "pagination",
		className: "record-board-shell-frame-pagination record-board-shell-frame-pagination-placeholder",
		style: {
			marginTop: 16,
			display: "flex",
			justifyContent: "center",
			minHeight: 40
		}
	});
	return /* @__PURE__ */ React.createElement("div", {
		"data-layout-slot": "pagination",
		className: "record-board-shell-frame-pagination",
		style: {
			marginTop: 16,
			display: "flex",
			justifyContent: "center"
		}
	}, /* @__PURE__ */ React.createElement(Pagination, paginationProps));
};
//#endregion
export { RecordBoardPagination as default };
