import { jsxs as p, jsx as t } from "react/jsx-runtime";
import { useCallback as f, useMemo as k } from "react";
import { Pagination as I, PaginationContent as E, PaginationItem as h, PaginationPrevious as L, PaginationEllipsis as S, PaginationLink as H, PaginationNext as j } from "./components/PaginationPrimitives.js";
import { c as M } from "../../index-BtlgVD4m.js";
const d = "start-ellipsis", P = "end-ellipsis", _ = ({
  total: u,
  page: e,
  pageSize: v = 10,
  onPageChange: b,
  previousText: C = "Zurück",
  nextText: x = "Weiter",
  showTotal: o
}) => {
  const n = Math.max(1, Math.ceil(u / v)), a = f(() => {
    const i = [];
    if (n <= 7) {
      for (let s = 1; s <= n; s++)
        i.push(s);
      return i;
    }
    if (i.push(1), e <= 4) {
      for (let s = 2; s <= 5; s++)
        i.push(s);
      i.push(P);
    } else if (e >= n - 3) {
      i.push(d);
      for (let s = n - 4; s < n; s++)
        i.push(s);
    } else
      i.push(d), i.push(e - 1), i.push(e), i.push(e + 1), i.push(P);
    return n > 1 && i.push(n), i;
  }, [e, n])(), r = f(
    (i) => {
      i !== e && i >= 1 && i <= n && b(i);
    },
    [e, n, b]
  ), g = f(
    (i) => {
      if (i === d) {
        const s = a[2], c = 2, l = s - 1;
        l - c + 1 < 3 ? r(c) : r(l - 1);
      } else if (i === P) {
        const c = a[a.length - 3] + 1, l = n - 1;
        l - c + 1 < 3 ? r(l) : r(c + 1);
      }
    },
    [n, r, a]
  ), m = k(() => {
    try {
      return o == null ? void 0 : o(u);
    } catch (i) {
      return console.error("Error rendering showTotal:", i), null;
    }
  }, [o, u]);
  return /* @__PURE__ */ p(I, { className: M(o && "flex items-center justify-between"), children: [
    m && /* @__PURE__ */ t("div", { className: "flex items-center text-[length:var(--typography-base-sizes-small-font-size)]", children: m }),
    /* @__PURE__ */ p(E, { children: [
      /* @__PURE__ */ t(h, { children: /* @__PURE__ */ t(
        L,
        {
          onClick: () => r(e - 1),
          "aria-disabled": e <= 1,
          tabIndex: e <= 1 ? -1 : 0,
          className: e <= 1 ? "opacity-[var(--opacity-opacity-50)] pointer-events-none" : "",
          children: C
        }
      ) }),
      a.map((i) => typeof i == "string" ? /* @__PURE__ */ t(h, { children: /* @__PURE__ */ t(
        S,
        {
          onClick: () => g(i),
          className: "cursor-pointer hover:bg-[color:var(--colors-background-on-surface)]",
          "aria-label": i === d ? "Jump to previous pages" : "Jump to next pages",
          hoverIcon: i === d ? "ChevronsLeft" : "ChevronsRight"
        }
      ) }, i) : /* @__PURE__ */ t(h, { children: /* @__PURE__ */ t(H, { isActive: i === e, onClick: () => r(i), "aria-label": `Page ${i}`, children: i }) }, i)),
      /* @__PURE__ */ t(h, { children: /* @__PURE__ */ t(
        j,
        {
          onClick: () => r(e + 1),
          "aria-disabled": e >= n,
          tabIndex: e >= n ? -1 : 0,
          className: e >= n ? "opacity-[var(--opacity-opacity-50)] pointer-events-none" : "",
          children: x
        }
      ) })
    ] })
  ] });
};
export {
  _ as default
};
//# sourceMappingURL=Pagination.js.map
