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/list/components/Pagination/Pagination.tsx
var Pagination_exports = {};
__export(Pagination_exports, {
  default: () => Pagination_default
});
module.exports = __toCommonJS(Pagination_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_materials = require("@pisell/materials");
var import_locales = __toESM(require("../../locales"));
var import_useEngineContext = __toESM(require("../../../../hooks/useEngineContext"));
var import_Pagination = require("./Pagination.less");
var LeftArrowIcon = ({ disabled = false }) => /* @__PURE__ */ import_react.default.createElement(
  import_materials.Iconfont,
  {
    type: "pisell2-arrow-left",
    style: {
      fontSize: "20px",
      color: disabled ? "#98A2B3" : "#344054"
    }
  }
);
var RightArrowIcon = ({ disabled = false }) => /* @__PURE__ */ import_react.default.createElement(
  import_materials.Iconfont,
  {
    type: "pisell2-arrow-right",
    style: {
      fontSize: "20px",
      color: disabled ? "#98A2B3" : "#344054"
    }
  }
);
var DropdownIcon = () => /* @__PURE__ */ import_react.default.createElement("div", { style: { width: 20, height: 20, position: "relative", overflow: "hidden" } }, /* @__PURE__ */ import_react.default.createElement("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none" }, /* @__PURE__ */ import_react.default.createElement(
  "path",
  {
    d: "M5 7.5L10 12.5L15 7.5",
    stroke: "#344054",
    strokeWidth: "1.67",
    strokeLinecap: "round",
    strokeLinejoin: "round"
  }
)));
var Pagination = ({
  current = 1,
  pageSize = 10,
  total = 0,
  totalPages: propTotalPages,
  onChange,
  onShowSizeChange,
  showSizeChanger = true,
  pageSizeOptions = ["10", "20", "50", "100"],
  showQuickJumper = false,
  showTotal,
  className = "",
  disabled = false
}) => {
  const context = (0, import_useEngineContext.default)();
  const getCurrentLanguage = () => {
    var _a, _b, _c, _d, _e, _f, _g, _h, _i;
    const appLocale = (_f = (_e = (_d = (_c = (_b = (_a = context.appHelper) == null ? void 0 : _a.utils) == null ? void 0 : _b.getApp) == null ? void 0 : _c.call(_b)) == null ? void 0 : _d.locales) == null ? void 0 : _e.getLocale) == null ? void 0 : _f.call(_e);
    const storageLocale = (_i = (_h = (_g = context.appHelper) == null ? void 0 : _g.utils) == null ? void 0 : _h.storage) == null ? void 0 : _i.get("umi_locale");
    let finalLang = appLocale || storageLocale;
    if (!finalLang && typeof window !== "undefined") {
      finalLang = localStorage.getItem("umi_locale");
    }
    return finalLang || "en";
  };
  const getLocalText = (key) => {
    var _a;
    const currentLang = getCurrentLanguage();
    const localText = (_a = import_locales.default[currentLang]) == null ? void 0 : _a[key];
    if (typeof localText === "function" || typeof localText === "string") {
      return localText;
    }
    return key;
  };
  const totalPages = propTotalPages ?? Math.ceil((total || 0) / pageSize);
  const startIndex = (current - 1) * pageSize + 1;
  const endIndex = propTotalPages ? current * pageSize : Math.min(current * pageSize, total || 0);
  const handlePageChange = (page) => {
    if (page < 1 || page > totalPages || disabled) return;
    onChange == null ? void 0 : onChange(page, pageSize);
  };
  const handleSizeChange = (size) => {
    const newCurrent = propTotalPages ? 1 : Math.ceil((current - 1) * pageSize / size) + 1;
    onShowSizeChange == null ? void 0 : onShowSizeChange(newCurrent, size);
    onChange == null ? void 0 : onChange(newCurrent, size);
  };
  const getPageNumbers = () => {
    const pages = [];
    const showPages = 7;
    if (totalPages <= showPages) {
      for (let i = 1; i <= totalPages; i++) {
        pages.push(i);
      }
    } else {
      const half = Math.floor(showPages / 2);
      let start = Math.max(1, current - half);
      let end = Math.min(totalPages, current + half);
      if (current <= half + 1) {
        end = showPages - 1;
      } else if (current >= totalPages - half) {
        start = totalPages - showPages + 2;
      }
      if (start > 1) {
        pages.push(1);
        if (start > 2) {
          pages.push("...");
        }
      }
      for (let i = start; i <= end; i++) {
        pages.push(i);
      }
      if (end < totalPages) {
        if (end < totalPages - 1) {
          pages.push("...");
        }
        pages.push(totalPages);
      }
    }
    return pages;
  };
  const pageNumbers = getPageNumbers();
  return /* @__PURE__ */ import_react.default.createElement("div", { className: `pisell-pagination ${className} ${disabled ? "disabled" : ""}` }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pagination-info" }, (() => {
    const pageOfFunc = getLocalText("pisell-list-pagination-page-of");
    if (typeof pageOfFunc === "function") {
      return pageOfFunc(current, totalPages);
    }
    return `Page ${current} of ${totalPages}`;
  })()), /* @__PURE__ */ import_react.default.createElement("div", { className: "pagination-controls" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pagination-group" }, /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      className: `pagination-btn pagination-prev ${current <= 1 ? "disabled" : ""}`,
      onClick: () => handlePageChange(current - 1),
      disabled: current <= 1 || disabled
    },
    /* @__PURE__ */ import_react.default.createElement(LeftArrowIcon, { disabled: current <= 1 }),
    /* @__PURE__ */ import_react.default.createElement("span", null, getLocalText("pisell-list-pagination-previous") || "Previous")
  ), pageNumbers.map((page, index) => {
    if (page === "...") {
      return /* @__PURE__ */ import_react.default.createElement("div", { key: `ellipsis-${index}`, className: "pagination-ellipsis" }, /* @__PURE__ */ import_react.default.createElement("span", null, "..."));
    }
    return /* @__PURE__ */ import_react.default.createElement(
      "button",
      {
        key: page,
        className: `pagination-page ${current === page ? "active" : ""}`,
        onClick: () => handlePageChange(page),
        disabled
      },
      page
    );
  }), /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      className: `pagination-btn pagination-next ${current >= totalPages ? "disabled" : ""}`,
      onClick: () => handlePageChange(current + 1),
      disabled: current >= totalPages || disabled
    },
    /* @__PURE__ */ import_react.default.createElement("span", null, getLocalText("pisell-list-pagination-next") || "Next"),
    /* @__PURE__ */ import_react.default.createElement(RightArrowIcon, { disabled: current >= totalPages })
  )), showSizeChanger && /* @__PURE__ */ import_react.default.createElement("div", { className: "pagination-size-selector" }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Select,
    {
      value: pageSize,
      onChange: handleSizeChange,
      disabled,
      style: { width: 88 },
      suffixIcon: /* @__PURE__ */ import_react.default.createElement(DropdownIcon, null),
      options: pageSizeOptions.map((option) => ({
        label: option,
        value: parseInt(option, 10)
      }))
    }
  ))));
};
var Pagination_default = Pagination;
