var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/Pagination/index.tsx
var Pagination_exports = {};
__export(Pagination_exports, {
  FormPagination: () => FormPagination,
  default: () => Pagination_default,
  paginationConfig: () => paginationConfig
});
module.exports = __toCommonJS(Pagination_exports);
var import_react = __toESM(require("react"));
var import_ArrowRight = __toESM(require("@pisell/icon/es/ArrowRight"));
var import_ArrowLeft = __toESM(require("@pisell/icon/es/ArrowLeft"));
var import_antd = require("antd");
var import_classnames = __toESM(require("classnames"));
var import_index = require("./index.less");
var import_utils = require("@pisell/utils");
var import_locales = require("../../locales");
var import_useIsMobileTable = __toESM(require("../table/hooks/useIsMobileTable"));
function getPaginationText(key) {
  const fullKey = `pisell2.salesManagement.pagination.${key}`;
  const fromUtils = import_utils.locales.getText(fullKey);
  if (fromUtils !== fullKey) return fromUtils;
  return (0, import_locales.getText)(fullKey) ?? (0, import_locales.getText)(`table-pagination-${key}`);
}
var Pagination = (props) => {
  const show = (0, import_react.useMemo)(() => {
    return Object.keys(props).length;
  }, [props]);
  const isMiniPagination = (0, import_useIsMobileTable.default)();
  const effectiveConfig = (0, import_react.useMemo)(() => {
    const prevText = getPaginationText("previous");
    const nextText = getPaginationText("next");
    const showTotalFn = getPaginationText("showTotal");
    const itemRenderFn = (_, type, originalElement) => {
      if (type === "prev") {
        return /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("paginator-page-btn", "left") }, /* @__PURE__ */ import_react.default.createElement(import_ArrowLeft.default, { className: "paginator-page-btn-left-icon" }), /* @__PURE__ */ import_react.default.createElement("span", { className: "paginator-page-btn-text" }, prevText));
      }
      if (type === "next") {
        return /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("paginator-page-btn", "right") }, /* @__PURE__ */ import_react.default.createElement("span", { className: "paginator-page-btn-text" }, nextText), /* @__PURE__ */ import_react.default.createElement(import_ArrowRight.default, { className: "paginator-page-btn-right-icon" }));
      }
      return originalElement;
    };
    const showTotal = typeof showTotalFn === "function" ? (total, range) => showTotalFn(range[0], range[1]) : (total, range) => `Page ${range[0]} of ${range[1]}`;
    return {
      className: "materials-grid-paginator",
      defaultCurrent: 1,
      showTotal,
      itemRender: itemRenderFn,
      responsive: true,
      size: "small"
    };
  }, []);
  const content = (0, import_react.useMemo)(() => {
    if (!show) {
      return null;
    }
    let Com = import_antd.Pagination;
    if (isMiniPagination) {
      Com = MiniPagination;
    }
    return /* @__PURE__ */ import_react.default.createElement(Com, { ...effectiveConfig, ...props });
  }, [show, effectiveConfig, props, isMiniPagination]);
  return content;
};
var paginationConfig = {
  className: "materials-grid-paginator",
  defaultCurrent: 1,
  showTotal: (total, range) => `Page ${range[0]} of ${range[1]}`,
  responsive: true,
  size: "small"
};
var Pagination_default = Pagination;
var MiniPagination = (props) => {
  const { current = 1, pageSize = 10, total = 0 } = props;
  const MAX = (0, import_react.useMemo)(() => {
    return Math.ceil(total / pageSize);
  }, [total, pageSize]);
  const MIN = (0, import_react.useMemo)(() => {
    return 1;
  }, []);
  const onChange = (type) => {
    let currentPage = current;
    if (type === "prev") {
      currentPage = current - 1;
    }
    if (type === "next") {
      currentPage = current + 1;
    }
    props.onChange && props.onChange(currentPage, pageSize || 10);
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "materials-grid-paginator" }, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "pisell-lowcode-pagination-prev",
      onClick: () => {
        if (current <= MIN) {
          return;
        }
        onChange("prev");
      }
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("paginator-page-btn", "left") }, /* @__PURE__ */ import_react.default.createElement(import_ArrowLeft.default, { className: "paginator-page-btn-left-icon" }))
  ), /* @__PURE__ */ import_react.default.createElement("div", { className: "materials-grid-paginator-center" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "materials-grid-paginator-center-text" }, (() => {
    const totalFn = getPaginationText("total");
    return typeof totalFn === "function" ? totalFn(current, MAX) : `${current} / ${MAX}`;
  })())), /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "pisell-lowcode-pagination-next",
      onClick: () => {
        if (current >= MAX) {
          return;
        }
        onChange("next");
      }
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("paginator-page-btn", "right") }, /* @__PURE__ */ import_react.default.createElement(import_ArrowRight.default, { className: "paginator-page-btn-right-icon" }))
  ));
};
var FormPagination = ({
  value = {},
  onChange,
  page,
  pageSize,
  ...other
}) => {
  const [_p, _setP] = (0, import_react.useState)(page || 1);
  const [_ps, _setPs] = (0, import_react.useState)(pageSize || 10);
  const _onChange = (p, ps) => {
    onChange && onChange({
      page: ps === _ps ? p : 1,
      size: ps
    });
  };
  (0, import_react.useEffect)(() => {
    const _page = (value == null ? void 0 : value.page) || page || 1;
    const _size = (value == null ? void 0 : value.size) || pageSize || 10;
    _setP(_page);
    _setPs(_size);
  }, [value, page, pageSize]);
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    Pagination,
    {
      ...other,
      pageSize: _ps,
      current: _p,
      onChange: _onChange,
      onShowSizeChange: _onChange
    }
  ));
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  FormPagination,
  paginationConfig
});
