function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
var _excluded = ["render"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React, { useMemo } from 'react';
import Pagination from "../../../Pagination";
import "./index.less";
import { useRecordBoardContext } from "../../hooks/useRecordBoardContext";
var defaultPagination = {
  pageNumber: 1,
  pageSize: 20
};
/**
 * RecordBoard 下的分页：接入 packages/materials 的 Pagination，从 context 取 pagination / total / onPageChange；可透传 childComponentProps.pagination。
 * 当 context 中 pagination 缺失时使用默认分页，避免在 Storybook 或未完整注入 context 时报错。
 */
var RecordBoardPagination = function RecordBoardPagination(props) {
  var _ctx$pagination, _ctx$childComponentPr3;
  var ctx = useRecordBoardContext({
    displayName: 'pagination'
  });
  var render = props.render,
    rest = _objectWithoutProperties(props, _excluded);
  var pagination = (_ctx$pagination = ctx.pagination) !== null && _ctx$pagination !== void 0 ? _ctx$pagination : defaultPagination;
  var paginationProps = useMemo(function () {
    var _ctx$childComponentPr, _ctx$childComponentPr2;
    return _objectSpread({
      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。
   */
  var effectiveRender = render !== null && render !== void 0 ? render : ctx.paginationRender;
  if (typeof effectiveRender === 'function') {
    return /*#__PURE__*/React.createElement(React.Fragment, null, effectiveRender(_objectSpread(_objectSpread({}, 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));
};
export default RecordBoardPagination;