"use client";
import { jsxs as N, jsx as e } from "react/jsx-runtime";
import { useMemo as h } from "react";
import { cn as s } from "../../utils/cn/cn.es.js";
import o from "../../components/Pagination/pagination.module.css";
import { Icon as d } from "../Icon/Icon.es.js";
import { EIconName as i } from "../Icon/constants.es.js";
import { Typography as x } from "../Typography/Typography.es.js";
const A = (r, t, a) => {
  if (t <= a)
    return Array.from({ length: t }, (c, f) => f + 1);
  const n = Math.floor(a / 2);
  let l = Math.max(1, r - n), m = l + a - 1;
  return m > t && (m = t, l = m - a + 1), Array.from({ length: a }, (c, f) => l + f);
}, k = ({ page: r, pagesCount: t, visiblePagesLimit: a, disabled: n, onPageChange: l }) => {
  const m = h(
    () => A(r, t, a),
    [r, t, a]
  );
  return /* @__PURE__ */ N("div", { className: o.root, children: [
    /* @__PURE__ */ e(
      "button",
      {
        className: s(o.arrow, o.arrowPrev),
        onClick: () => l(r - 1),
        disabled: n || r <= 1,
        "aria-label": "Previous page",
        children: /* @__PURE__ */ e(d, { name: i.ARROW_BACK, className: o.icon })
      }
    ),
    m.map((c) => /* @__PURE__ */ e(
      "button",
      {
        className: s(o.page, c === r && o.activePage),
        onClick: () => l(c),
        children: /* @__PURE__ */ e(x, { defaultVariant: "labelXl", weight: "regular", children: c.toString().padStart(2, "0") })
      },
      c
    )),
    /* @__PURE__ */ e(
      "button",
      {
        className: s(o.arrow, o.arrowNext),
        onClick: () => l(r + 1),
        disabled: n || r >= t,
        "aria-label": "Next page",
        children: /* @__PURE__ */ e(d, { name: i.ARROW_FORWARD, className: o.icon })
      }
    )
  ] });
};
export {
  k as Pagination
};
