import { defineComponent as L, useCssModule as N, computed as D, toRef as u, openBlock as i, createElementBlock as l, createElementVNode as p, normalizeClass as o, unref as n, createVNode as _, toDisplayString as m, Fragment as v, renderList as E, createCommentVNode as d } from "vue";
import { u as $ } from "./usePaginationStats-d_q39naC.js";
import { t as g } from "./locale.js";
import h from "./Icon.js";
import { _ as w } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const B = {
  class: "stash-paginate flex justify-center",
  "data-test": "stash-paginate"
}, F = ["aria-label", "disabled"], V = {
  key: 0,
  class: "mx-3 text-ice-900"
}, G = ["onClick"], I = ["aria-label", "disabled"], j = /* @__PURE__ */ L({
  name: "ll-paginate",
  __name: "Paginate",
  props: {
    currentPage: { default: 1 },
    listLength: { default: 1 },
    pageSize: { default: 50 },
    isNextDisabled: { type: Boolean, default: !1 },
    variant: { default: "standard" }
  },
  emits: ["set-page"],
  setup(b, { emit: P }) {
    const e = b, x = P, r = N(), a = D(() => Math.ceil(e.listLength / e.pageSize)), k = e.variant === "stats" ? $({
      currentPage: u(() => e.currentPage),
      pageSize: u(() => e.pageSize),
      totalItems: u(() => e.listLength)
    }) : null;
    function c(t) {
      x("set-page", t);
    }
    function S() {
      e.currentPage < a.value && c(e.currentPage + 1);
    }
    function y() {
      e.currentPage > 1 && c(e.currentPage - 1);
    }
    function C(t) {
      const f = Math.abs(e.currentPage - t);
      return a.value < 10 || t === 1 || t === a.value || e.currentPage < 6 && t < 8 || a.value - e.currentPage < 5 && a.value - t < 7 || f < 3;
    }
    function z(t) {
      return a.value > 9 && e.currentPage > 5 && t === 2;
    }
    function M(t) {
      return a.value > 9 && a.value - e.currentPage > 4 && t === a.value - 1;
    }
    return (t, f) => (i(), l("div", B, [
      p("ul", {
        class: o(["stash-paginate__list flex items-center", n(r).pagination]),
        "data-test": "stash-paginate|list"
      }, [
        p("button", {
          "aria-label": n(g)("ll.previous"),
          "data-test": "stash-paginate|prev-page",
          class: o(n(r).prev),
          disabled: e.currentPage === 1,
          onClick: y
        }, [
          _(h, {
            size: "small",
            name: "chevron-left"
          })
        ], 10, F),
        e.variant === "stats" ? (i(), l("span", V, m(n(g)("ll.pageStats", n(k))), 1)) : (i(!0), l(v, { key: 1 }, E(a.value, (s) => (i(), l(v, null, [
          z(s) ? (i(), l("button", {
            key: `${s}-ellipsis`,
            class: "pointer-events-none",
            "data-test": "stash-paginate|first-ellipsis",
            tabindex: "-1"
          }, " … ")) : d("", !0),
          C(s) ? (i(), l("button", {
            key: s,
            "data-test": "stash-paginate|page-number",
            class: o({ [n(r)["is-active"]]: e.currentPage === s }),
            onClick: (J) => c(s)
          }, m(s), 11, G)) : d("", !0),
          M(s) ? (i(), l("button", {
            key: `${s}-ellipsis`,
            class: "pointer-events-none",
            "data-test": "stash-paginate|last-ellipsis",
            tabindex: "-1"
          }, " … ")) : d("", !0)
        ], 64))), 256)),
        p("button", {
          "aria-label": n(g)("ll.next"),
          "data-test": "stash-paginate|next-page",
          class: o(n(r).next),
          disabled: e.isNextDisabled || e.currentPage === a.value,
          onClick: S
        }, [
          _(h, {
            size: "small",
            class: "rotate-180",
            name: "chevron-left"
          })
        ], 10, I)
      ], 2)
    ]));
  }
}), A = "_pagination_rAX9G", R = "_prev__e-_b", X = "_next_pMbvM", q = {
  pagination: A,
  prev: R,
  next: X,
  "is-active": "_is-active_FogGa"
}, H = {
  $style: q
}, W = /* @__PURE__ */ w(j, [["__cssModules", H]]);
export {
  W as default
};
//# sourceMappingURL=Paginate.js.map
