import { jsx as i, jsxs as v } from "react/jsx-runtime";
import { useMemo as Q, forwardRef as k, useId as U, createElement as ue, useState as q, useEffect as ce } from "react";
import { b as me } from "./icon-DNHpBTHs-JfI8WyiR.mjs";
import { i as de } from "./arrow-right.es-C7SkjAB6.mjs";
import { V as S } from "./visually-hidden-BYFkJEp1.mjs";
import { c as w } from "./bind-CU-R61T-.mjs";
import { L as W } from "./label-7sJe5-pX.mjs";
import { a as X } from "./paragraph-DNtj7OLr.mjs";
import { S as Y } from "./select-BEmu_fh9.mjs";
const $e = {
  name: "arrow-left",
  svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path fill-rule="evenodd" d="M3.1 12a.9.9 0 0 1 .264-.636l5.5-5.5a.9.9 0 0 1 1.272 1.272L6.173 11.1H20a.9.9 0 0 1 0 1.8H6.173l3.963 3.964a.9.9 0 1 1-1.272 1.272l-5.5-5.5A.9.9 0 0 1 3.1 12Z" clip-rule="evenodd"/></svg>',
  keywords: ["arrow-left"],
  category: "utility"
}, B = (e) => /* @__PURE__ */ i(me, { ...e, svg: $e });
B.displayName = "IconArrowLeft";
const O = (e) => {
  window.location.href = e;
}, ye = {
  "purpur-pagination": "_purpur-pagination_1g3as_1",
  "purpur-pagination__pagination-container": "_purpur-pagination__pagination-container_1g3as_5",
  "purpur-pagination__pagination-container--with-page-size-select": "_purpur-pagination__pagination-container--with-page-size-select_1g3as_12",
  "purpur-pagination__page-size-select-container": "_purpur-pagination__page-size-select-container_1g3as_20",
  "purpur-pagination__page-navigation-container": "_purpur-pagination__page-navigation-container_1g3as_30",
  "purpur-pagination__step-trigger-label": "_purpur-pagination__step-trigger-label_1g3as_51",
  "purpur-pagination__step-trigger-label--not-icon-only": "_purpur-pagination__step-trigger-label--not-icon-only_1g3as_64",
  "purpur-pagination__step-trigger": "_purpur-pagination__step-trigger_1g3as_51",
  "purpur-pagination__page-trigger-container": "_purpur-pagination__page-trigger-container_1g3as_78",
  "purpur-pagination__pages": "_purpur-pagination__pages_1g3as_83",
  "purpur-pagination__pages--visible": "_purpur-pagination__pages--visible_1g3as_86",
  "purpur-pagination__page-selector": "_purpur-pagination__page-selector_1g3as_94",
  "purpur-pagination__page-selector--visible": "_purpur-pagination__page-selector--visible_1g3as_97"
}, he = {
  "purpur-pagination-page-selector": "_purpur-pagination-page-selector_7pxsw_1",
  "purpur-pagination-page-selector__select-container": "_purpur-pagination-page-selector__select-container_7pxsw_6",
  "purpur-pagination-page-selector__of-total-pages-label": "_purpur-pagination-page-selector__of-total-pages-label_7pxsw_10"
}, ve = (e) => ({
  options: Q(
    () => Array.from({ length: e }, (a, g) => ({ label: `${g + 1}`, value: `${g + 1}` })),
    [e]
  )
}), G = w.bind(he), M = "purpur-pagination-page-selector", T = k(
  ({
    ["data-testid"]: e = "purpur-pagination-page-selector",
    asLink: r,
    className: a,
    currentPage: g,
    hrefGetter: n,
    navigationFunction: t,
    numberOfPages: _,
    onPageChange: p,
    outOfLabel: l,
    pageSelectorId: u,
    pageSelectorLabel: d,
    ...$
  }, h) => {
    const c = U(), b = G(a, M), { options: z } = ve(_), f = (x) => {
      const C = x.target.value ? Number(x.target.value) : 1;
      if (p(C), r) {
        const F = n?.(C) ?? "";
        t(C, F);
      }
    };
    return /* @__PURE__ */ v("div", { className: b, "data-testid": e, ref: h, ...$, children: [
      /* @__PURE__ */ v("div", { className: G(`${M}__select-container`), children: [
        /* @__PURE__ */ i(S, { children: /* @__PURE__ */ i(W, { "data-testid": `${e}-label`, htmlFor: c, children: d }) }),
        /* @__PURE__ */ i(
          Y,
          {
            className: G(`${M}__select`),
            "data-testid": `${e}-select`,
            id: u ?? c,
            onChange: f,
            options: z,
            value: String(g)
          }
        )
      ] }),
      /* @__PURE__ */ i(
        X,
        {
          className: G(`${M}__of-total-pages-label`),
          "data-testid": `${e}-of-total-pages`,
          children: `${l} ${_}`
        }
      )
    ] });
  }
);
T.displayName = "PaginationPageSelector";
const be = {
  "purpur-pagination-page-size-selector": "_purpur-pagination-page-size-selector_11x2p_1",
  "purpur-pagination-page-size-selector__select": "_purpur-pagination-page-size-selector__select_11x2p_12",
  "purpur-pagination-page-size-selector__items-per-page-label": "_purpur-pagination-page-size-selector__items-per-page-label_11x2p_17",
  "purpur-pagination-page-size-selector__items-per-page-label-text": "_purpur-pagination-page-size-selector__items-per-page-label-text_11x2p_27"
}, fe = (e) => ({
  options: Q(
    () => e.map((a) => ({
      label: `${a}`,
      value: `${a}`
    })),
    [e]
  )
}), j = w.bind(be), H = "purpur-pagination-page-size-selector", I = k(
  ({
    ["data-testid"]: e = "purpur-pagination-page-size-selector",
    asLink: r,
    availablePageSizes: a,
    className: g,
    hrefGetter: n,
    navigationFunction: t,
    onPageSizeChange: _,
    pageSize: p,
    pageSizeLabel: l,
    ...u
  }, d) => {
    const $ = U(), h = j(g, H), { options: c } = fe(a), b = (z) => {
      const f = Number(z.target.value);
      if (_(f), r) {
        const x = n({ page: 1, pageSize: f });
        t ? t({ currentPage: 1, pageSize: f, url: x }) : O(x);
      }
    };
    return /* @__PURE__ */ v("div", { className: h, "data-testid": e, ref: d, ...u, children: [
      /* @__PURE__ */ i(
        W,
        {
          className: j(`${H}__items-per-page-label`),
          "data-testid": `${e}-item-per-page-label`,
          htmlFor: $,
          children: /* @__PURE__ */ i("span", { className: j(`${H}__items-per-page-label-text`), children: l })
        }
      ),
      /* @__PURE__ */ i(
        Y,
        {
          className: j(`${H}__select`),
          "data-testid": `${e}-select`,
          id: $,
          onChange: b,
          options: c,
          value: p
        }
      )
    ] });
  }
);
I.displayName = "PaginationPageSizeSelector";
const xe = {
  "purpur-pagination-page-trigger": "_purpur-pagination-page-trigger_1pnyd_1",
  "purpur-pagination-page-trigger__trigger-item": "_purpur-pagination-page-trigger__trigger-item_1pnyd_4",
  "purpur-pagination-page-trigger__trigger-item--xs": "_purpur-pagination-page-trigger__trigger-item--xs_1pnyd_25",
  "purpur-pagination-page-trigger__trigger-item--icon-only": "_purpur-pagination-page-trigger__trigger-item--icon-only_1pnyd_28",
  "purpur-pagination-page-trigger__trigger-item--sm": "_purpur-pagination-page-trigger__trigger-item--sm_1pnyd_31",
  "purpur-pagination-page-trigger__trigger-item--md": "_purpur-pagination-page-trigger__trigger-item--md_1pnyd_37",
  "purpur-pagination-page-trigger__trigger-item--lg": "_purpur-pagination-page-trigger__trigger-item--lg_1pnyd_43",
  "purpur-pagination-page-trigger__trigger-item--full-width": "_purpur-pagination-page-trigger__trigger-item--full-width_1pnyd_49",
  "purpur-pagination-page-trigger__trigger-item--primary": "_purpur-pagination-page-trigger__trigger-item--primary_1pnyd_67",
  "purpur-pagination-page-trigger__trigger-item--disabled": "_purpur-pagination-page-trigger__trigger-item--disabled_1pnyd_71",
  "purpur-pagination-page-trigger__trigger-item--primary-negative": "_purpur-pagination-page-trigger__trigger-item--primary-negative_1pnyd_77",
  "purpur-pagination-page-trigger__trigger-item--secondary": "_purpur-pagination-page-trigger__trigger-item--secondary_1pnyd_89",
  "purpur-pagination-page-trigger__trigger-item--secondary-negative": "_purpur-pagination-page-trigger__trigger-item--secondary-negative_1pnyd_100",
  "purpur-pagination-page-trigger__trigger-item--expressive": "_purpur-pagination-page-trigger__trigger-item--expressive_1pnyd_111",
  "purpur-pagination-page-trigger__trigger-item--expressive-negative": "_purpur-pagination-page-trigger__trigger-item--expressive-negative_1pnyd_121",
  "purpur-pagination-page-trigger__trigger-item--page-trigger": "_purpur-pagination-page-trigger__trigger-item--page-trigger_1pnyd_133",
  "purpur-pagination-page-trigger__trigger-item--selected": "_purpur-pagination-page-trigger__trigger-item--selected_1pnyd_142"
}, V = w.bind(xe), m = "purpur-pagination-page-trigger", ee = k(
  ({
    ["data-testid"]: e = "purpur-pagination-page-trigger",
    linkElement: r,
    asLink: a,
    className: g,
    disabled: n,
    hrefGetter: t,
    onPageChange: _,
    pageNumber: p,
    selected: l,
    stepNumberPrefix: u,
    ...d
  }, $) => {
    const h = V(g, m);
    return /* @__PURE__ */ i("li", { className: h, "data-testid": e, ref: $, ...d, children: a ? n ? /* @__PURE__ */ v(
      "span",
      {
        className: V(
          `${m}__trigger-item`,
          `${m}__trigger-item--page-trigger`,
          `${m}__trigger-item--sm`,
          `${m}__trigger-item--icon-only`,
          `${m}__trigger-item--disabled`
        ),
        "aria-current": l ? "page" : void 0,
        "data-testid": `${e}-disabled-link`,
        children: [
          /* @__PURE__ */ i(S, { children: `${u} ` }),
          p
        ]
      }
    ) : /* @__PURE__ */ v(
      r,
      {
        className: V(
          `${m}__trigger-item`,
          `${m}__trigger-item--page-trigger`,
          `${m}__trigger-item--sm`,
          `${m}__trigger-item--icon-only`,
          { [`${m}__trigger-item--selected`]: l }
        ),
        "aria-current": l ? "page" : void 0,
        "data-testid": `${e}-link`,
        href: t(p),
        onClick: () => _(p),
        children: [
          /* @__PURE__ */ i(S, { children: `${u} ` }),
          p
        ]
      }
    ) : /* @__PURE__ */ v(
      "button",
      {
        "aria-disabled": n,
        className: V(
          `${m}__trigger-item`,
          `${m}__trigger-item--page-trigger`,
          `${m}__trigger-item--sm`,
          `${m}__trigger-item--icon-only`,
          { [`${m}__trigger-item--selected`]: l }
        ),
        "data-testid": `${e}-button`,
        "aria-current": l ? "page" : void 0,
        disabled: n,
        onClick: () => _(p),
        type: "button",
        children: [
          /* @__PURE__ */ i(S, { children: `${u} ` }),
          p
        ]
      }
    ) });
  }
);
ee.displayName = "PaginationPageTrigger";
const Ne = {
  "purpur-pagination-pages": "_purpur-pagination-pages_2g8is_1"
}, ze = {
  "purpur-pagination-truncation-separator": "_purpur-pagination-truncation-separator_b9cij_1"
}, Ce = w.bind(ze), we = "purpur-pagination-truncation-separator", ie = ({
  ["data-testid"]: e = "purpur-pagination-truncation-separator",
  className: r,
  ["aria-label"]: a,
  ...g
}) => {
  const n = Ce(r, we);
  return /* @__PURE__ */ i("li", { className: n, "data-testid": e, ...g, children: /* @__PURE__ */ i(X, { "aria-label": a, children: "..." }) });
};
ie.displayName = "PaginationTruncationSeparator";
const Se = w.bind(Ne), ke = "purpur-pagination-pages", re = k(
  ({
    ["data-testid"]: e = "purpur-pagination-pages",
    linkElement: r,
    asLink: a,
    className: g,
    currentPage: n,
    hrefGetter: t,
    onPageChange: _,
    pages: p,
    stepNumberPrefix: l,
    truncationSeparatorAriaLabel: u,
    ...d
  }, $) => {
    const h = Se(g, ke);
    return /* @__PURE__ */ i("ol", { className: h, "data-testid": e, ref: $, ...d, children: p.flatMap((c, b, z) => {
      const f = /* @__PURE__ */ ue(
        ee,
        {
          ...a ? { asLink: !0, hrefGetter: t } : {
            asLink: void 0,
            hrefGetter: void 0
          },
          linkElement: r,
          "data-testid": `${e}-page-${c}`,
          key: c,
          onPageChange: _,
          selected: c === n,
          stepNumberPrefix: l,
          pageNumber: c
        }
      );
      return b === 0 || z[b - 1] + 1 === c ? [f] : [
        /* @__PURE__ */ i(
          ie,
          {
            "data-testid": `${e}-truncation-separator-${c}`,
            "aria-label": u
          },
          `${c}-separator`
        ),
        f
      ];
    }) });
  }
);
re.displayName = "PaginationPages";
const Pe = {
  "purpur-pagination-step-trigger__trigger-item": "_purpur-pagination-step-trigger__trigger-item_1t19c_1",
  "purpur-pagination-step-trigger__trigger-item--xs": "_purpur-pagination-step-trigger__trigger-item--xs_1t19c_22",
  "purpur-pagination-step-trigger__trigger-item--icon-only": "_purpur-pagination-step-trigger__trigger-item--icon-only_1t19c_25",
  "purpur-pagination-step-trigger__trigger-item--sm": "_purpur-pagination-step-trigger__trigger-item--sm_1t19c_28",
  "purpur-pagination-step-trigger__trigger-item--md": "_purpur-pagination-step-trigger__trigger-item--md_1t19c_34",
  "purpur-pagination-step-trigger__trigger-item--lg": "_purpur-pagination-step-trigger__trigger-item--lg_1t19c_40",
  "purpur-pagination-step-trigger__trigger-item--full-width": "_purpur-pagination-step-trigger__trigger-item--full-width_1t19c_46",
  "purpur-pagination-step-trigger__trigger-item--primary": "_purpur-pagination-step-trigger__trigger-item--primary_1t19c_64",
  "purpur-pagination-step-trigger__trigger-item--disabled": "_purpur-pagination-step-trigger__trigger-item--disabled_1t19c_68",
  "purpur-pagination-step-trigger__trigger-item--primary-negative": "_purpur-pagination-step-trigger__trigger-item--primary-negative_1t19c_74",
  "purpur-pagination-step-trigger__trigger-item--secondary": "_purpur-pagination-step-trigger__trigger-item--secondary_1t19c_86",
  "purpur-pagination-step-trigger__trigger-item--secondary-negative": "_purpur-pagination-step-trigger__trigger-item--secondary-negative_1t19c_97",
  "purpur-pagination-step-trigger__trigger-item--expressive": "_purpur-pagination-step-trigger__trigger-item--expressive_1t19c_108",
  "purpur-pagination-step-trigger__trigger-item--expressive-negative": "_purpur-pagination-step-trigger__trigger-item--expressive-negative_1t19c_118",
  "purpur-pagination-step-trigger__trigger-item--step-trigger": "_purpur-pagination-step-trigger__trigger-item--step-trigger_1t19c_130",
  "purpur-pagination-step-trigger__trigger-item--step-trigger--not-icon-only": "_purpur-pagination-step-trigger__trigger-item--step-trigger--not-icon-only_1t19c_137"
}, D = w.bind(Pe), s = "purpur-pagination-step-trigger", J = k(
  ({
    ["aria-label"]: e,
    ["data-testid"]: r = "purpur-pagination-step-trigger",
    linkElement: a,
    asLink: g,
    children: n,
    className: t,
    disabled: _,
    hrefGetter: p,
    onPageChange: l,
    pageToNavigateTo: u,
    isIconOnly: d,
    ...$
  }, h) => {
    const c = D(t, s);
    return /* @__PURE__ */ i("div", { className: c, "data-testid": r, ref: h, ...$, children: g ? _ ? /* @__PURE__ */ i(
      "span",
      {
        "aria-label": e,
        className: D(
          `${s}__trigger-item`,
          `${s}__trigger-item--step-trigger`,
          `${s}__trigger-item--secondary`,
          `${s}__trigger-item--sm`,
          `${s}__trigger-item--disabled`,
          { [`${s}__trigger-item--step-trigger--not-icon-only`]: !d }
        ),
        "data-testid": `${r}-disabled-link`,
        children: n
      }
    ) : /* @__PURE__ */ i(
      a,
      {
        "aria-label": e,
        className: D(
          `${s}__trigger-item`,
          `${s}__trigger-item--step-trigger`,
          `${s}__trigger-item--secondary`,
          `${s}__trigger-item--sm`,
          { [`${s}__trigger-item--step-trigger--not-icon-only`]: !d }
        ),
        "data-testid": `${r}-link`,
        href: p(u),
        onClick: () => l(u),
        children: n
      }
    ) : /* @__PURE__ */ i(
      "button",
      {
        "aria-disabled": _,
        "aria-label": e,
        className: D(
          `${s}__trigger-item`,
          `${s}__trigger-item--step-trigger`,
          `${s}__trigger-item--secondary`,
          `${s}__trigger-item--sm`,
          {
            [`${s}__trigger-item--disabled`]: _,
            [`${s}__trigger-item--step-trigger--not-icon-only`]: !d
          }
        ),
        "data-testid": `${r}-button`,
        disabled: _,
        onClick: () => l(u),
        type: "button",
        children: n
      }
    ) });
  }
);
J.displayName = "PaginationStepTrigger";
const Le = (e, r, a) => {
  const [g, n] = q([]), [t, _] = q(0);
  return ce(() => {
    const p = Math.ceil(e / r);
    _(p), n(Ae(p, a));
  }, [e, r, a]), {
    pages: g,
    numberOfPages: t
  };
};
function Ae(e, r) {
  if (e <= 5)
    return Array.from({ length: e }, (n, t) => t + 1);
  const a = [1, 2, 3];
  if (a.includes(r))
    return [...a, 4, e];
  const g = [e - 2, e - 1, e];
  return g.includes(r) ? [1, e - 3, ...g] : [1, r - 1, r, r + 1, e];
}
const y = w.bind(ye), o = "purpur-pagination", Ee = k(
  ({
    ["data-testid"]: e = "purpur-pagination",
    linkElement: r = "a",
    asLink: a,
    availablePageSizes: g,
    className: n,
    currentPage: t = 1,
    hrefGetter: _,
    navigationFunction: p,
    nextButtonAriaLabel: l,
    nextButtonText: u,
    onPageChange: d,
    outOfLabel: $,
    pageSelectorId: h,
    pageSelectorLabel: c,
    pageSize: b = 10,
    pageSizeLabel: z,
    previousButtonAriaLabel: f,
    previousButtonText: x,
    stepNumberPrefix: C,
    totalItems: F,
    truncationSeparatorAriaLabel: te,
    ...ae
  }, ge) => {
    const pe = y(n, o), [R, ne] = q(b), { pages: Z, numberOfPages: P } = Le(F, R, t), L = !x && !u, A = (N) => {
      d?.({ currentPage: N, pageSize: b });
    }, _e = (N) => _?.({ page: N, pageSize: b }) ?? "", se = (N) => {
      ne(N), d?.({ currentPage: 1, pageSize: N });
    }, oe = (N, K) => {
      p ? p({ currentPage: N, pageSize: R, url: K }) : O(K);
    }, E = a ? { asLink: !0, hrefGetter: _e } : {
      asLink: void 0,
      hrefGetter: void 0
    }, le = a ? "nav" : "div";
    return P ? /* @__PURE__ */ i(le, { className: pe, "data-testid": e, ref: ge, ...ae, children: /* @__PURE__ */ v(
      "div",
      {
        className: y(`${o}__pagination-container`, {
          [`${o}__pagination-container--with-page-size-select`]: !!g
        }),
        children: [
          /* @__PURE__ */ v("div", { className: y(`${o}__page-navigation-container`), children: [
            /* @__PURE__ */ v(
              J,
              {
                ...E,
                linkElement: r,
                "aria-label": f,
                className: y(`${o}__step-trigger`),
                "data-testid": `${e}-previous-step-trigger`,
                disabled: t === 1,
                onPageChange: A,
                pageToNavigateTo: t - 1,
                isIconOnly: L,
                children: [
                  /* @__PURE__ */ i(B, { size: "sm" }),
                  /* @__PURE__ */ i(
                    "span",
                    {
                      className: y(`${o}__step-trigger-label`, {
                        [`${o}__step-trigger-label--not-icon-only`]: !L
                      }),
                      children: x
                    }
                  ),
                  t !== 1 && /* @__PURE__ */ i(S, { "data-testid": `${e}-previous-step-trigger-hidden-text`, children: `${C} ${t - 1}` })
                ]
              }
            ),
            /* @__PURE__ */ v("div", { className: y(`${o}__page-trigger-container`), children: [
              /* @__PURE__ */ i(
                T,
                {
                  ...E,
                  className: y(`${o}__page-selector`, {
                    [`${o}__page-selector--visible`]: Z.length > 3
                  }),
                  currentPage: t,
                  "data-testid": `${e}-page-selector`,
                  navigationFunction: oe,
                  numberOfPages: P,
                  onPageChange: A,
                  outOfLabel: $,
                  pageSelectorId: h,
                  pageSelectorLabel: c
                }
              ),
              /* @__PURE__ */ i(
                re,
                {
                  ...E,
                  linkElement: r,
                  className: y(`${o}__pages`, {
                    [`${o}__pages--visible`]: Z.length <= 3
                  }),
                  currentPage: t,
                  "data-testid": `${e}-pages`,
                  stepNumberPrefix: C,
                  onPageChange: A,
                  truncationSeparatorAriaLabel: te,
                  pages: Z
                }
              )
            ] }),
            /* @__PURE__ */ v(
              J,
              {
                ...E,
                linkElement: r,
                "aria-label": l,
                className: y(`${o}__step-trigger`),
                "data-testid": `${e}-next-step-trigger`,
                disabled: t === P,
                onPageChange: A,
                pageToNavigateTo: t + 1,
                isIconOnly: L,
                children: [
                  /* @__PURE__ */ i(
                    "span",
                    {
                      className: y(`${o}__step-trigger-label`, {
                        [`${o}__step-trigger-label--not-icon-only`]: !L
                      }),
                      children: u
                    }
                  ),
                  t !== P && /* @__PURE__ */ i(S, { "data-testid": `${e}-next-step-trigger-hidden-text`, children: `${C} ${t + 1}` }),
                  /* @__PURE__ */ i(de, { size: "sm" })
                ]
              }
            )
          ] }),
          g && /* @__PURE__ */ i("div", { className: y(`${o}__page-size-select-container`), children: /* @__PURE__ */ i(
            I,
            {
              ...a ? { asLink: !0, hrefGetter: _, navigationFunction: p } : { asLink: void 0, hrefGetter: void 0 },
              availablePageSizes: g,
              className: y(`${o}__page-size-selector`),
              "data-testid": `${e}-page-size-selector`,
              onPageSizeChange: se,
              pageSize: R,
              pageSizeLabel: z
            }
          ) })
        ]
      }
    ) }) : null;
  }
);
Ee.displayName = "Pagination";
export {
  Ee as P
};
//# sourceMappingURL=pagination-CVVCAQ65.mjs.map
