"use client";
import { jsx as a, jsxs as g, Fragment as C } from "react/jsx-runtime";
import { useState as O, useEffect as R, useMemo as b, createContext as T, useContext as _ } from "react";
import { I as c } from "./input-group-cjsy8kh4vf9312xl.js";
import { CaretDoubleLeftIcon as B, CaretLeftIcon as L, CaretRightIcon as D, CaretDoubleRightIcon as F } from "@phosphor-icons/react";
import { c as u } from "./cn-ct4n7r74mh8y0f48.js";
import { S as v } from "./select-hnt87e3cfos48qql.js";
const V = [25, 50, 100, 250], f = {
  controls: "full"
}, h = T(null);
function S() {
  const t = _(h);
  if (!t)
    throw new Error(
      "Pagination compound components must be used within a Pagination component"
    );
  return t;
}
function I({ children: t, className: l }) {
  const { page: n, perPage: e, totalCount: o, pageShowingRange: r } = S(), s = t ? t({ page: n, perPage: e, totalCount: o, pageShowingRange: r }) : o && o > 0 ? /* @__PURE__ */ g(C, { children: [
    "Showing ",
    /* @__PURE__ */ a("span", { className: "tabular-nums", children: r }),
    " of",
    " ",
    /* @__PURE__ */ a("span", { className: "tabular-nums", children: o })
  ] }) : null;
  return /* @__PURE__ */ a(
    "div",
    {
      "data-slot": "pagination-info",
      className: u("text-sm text-kumo-strong", l),
      children: s
    }
  );
}
I.displayName = "Pagination.Info";
function w({
  value: t,
  onChange: l,
  options: n = V,
  label: e = "Per page:",
  className: o
}) {
  return /* @__PURE__ */ g(
    "div",
    {
      "data-slot": "pagination-page-size",
      className: u("flex items-center gap-2", o),
      children: [
        e && /* @__PURE__ */ a("span", { className: "text-sm text-kumo-strong", children: e }),
        /* @__PURE__ */ a(
          v,
          {
            "aria-label": "Page size",
            value: t,
            onValueChange: (r) => l(r),
            children: n.map((r) => /* @__PURE__ */ a(v.Option, { value: r, children: r }, r))
          }
        )
      ]
    }
  );
}
w.displayName = "Pagination.PageSize";
function P({
  controls: t = f.controls,
  className: l
}) {
  const { page: n, maxPage: e, setPage: o, editingPage: r, setEditingPage: s } = S();
  return /* @__PURE__ */ a(
    "div",
    {
      "data-slot": "pagination-controls",
      className: u("grow flex flex-col items-end", l),
      children: /* @__PURE__ */ a("div", { children: /* @__PURE__ */ g(c, { focusMode: "individual", children: [
        t === "full" && /* @__PURE__ */ a(
          c.Button,
          {
            variant: "secondary",
            "aria-label": "First page",
            disabled: n <= 1,
            onClick: () => {
              o(1), s(1);
            },
            children: /* @__PURE__ */ a(B, { size: 16 })
          }
        ),
        /* @__PURE__ */ a(
          c.Button,
          {
            variant: "secondary",
            "aria-label": "Previous page",
            disabled: n <= 1,
            onClick: () => {
              const i = Math.max(n - 1, 1);
              o(i), s(i);
            },
            children: /* @__PURE__ */ a(L, { size: 16 })
          }
        ),
        t === "full" && /* @__PURE__ */ a(
          c.Input,
          {
            style: { width: 50 },
            className: "text-center",
            "aria-label": "Page number",
            value: r,
            onValueChange: (i) => {
              s(Number(i));
            },
            onBlur: () => {
              let i = Math.max(r, 1);
              i = Math.min(i, e), o(i), s(i);
            },
            autoComplete: "off",
            "data-1p-ignore": !0,
            "data-lpignore": "true",
            "data-form-type": "other"
          }
        ),
        /* @__PURE__ */ a(
          c.Button,
          {
            variant: "secondary",
            "aria-label": "Next page",
            disabled: n === e,
            onClick: () => {
              const i = Math.min(n + 1, e);
              o(i), s(i);
            },
            children: /* @__PURE__ */ a(D, { size: 16 })
          }
        ),
        t === "full" && /* @__PURE__ */ a(
          c.Button,
          {
            variant: "secondary",
            "aria-label": "Last page",
            disabled: n === e,
            onClick: () => {
              o(e), s(e);
            },
            children: /* @__PURE__ */ a(F, { size: 16 })
          }
        )
      ] }) })
    }
  );
}
P.displayName = "Pagination.Controls";
function y({ className: t }) {
  return /* @__PURE__ */ a(
    "div",
    {
      "data-slot": "pagination-separator",
      className: u("mx-2 h-6 border-l border-kumo-line", t)
    }
  );
}
y.displayName = "Pagination.Separator";
function M(t) {
  const { page: l = 1, perPage: n, totalCount: e, setPage: o, children: r, className: s } = t, i = "text" in t ? t.text : void 0, k = "controls" in t ? t.controls ?? f.controls : f.controls, [E, x] = O(1);
  R(() => {
    x(l);
  }, [l]);
  const d = b(() => {
    let m = l * (n ?? 1) - (n ?? 0) + 1, p = Math.min(l * (n ?? 0), e ?? 0);
    return Number.isNaN(m) && (m = 0), Number.isNaN(p) && (p = 0), `${m}-${p}`;
  }, [l, n, e]), z = b(() => Math.ceil((e ?? 1) / (n ?? 1)), [e, n]), N = {
    page: l,
    perPage: n,
    totalCount: e,
    maxPage: z,
    pageShowingRange: d,
    setPage: o,
    editingPage: E,
    setEditingPage: x
  };
  if (r)
    return /* @__PURE__ */ a(h.Provider, { value: N, children: /* @__PURE__ */ a(
      "div",
      {
        "data-slot": "pagination",
        className: u("flex items-center gap-2 w-full", s),
        children: r
      }
    ) });
  const A = () => i ? i({ page: l, perPage: n, totalCount: e, pageShowingRange: d }) : e && e > 0 ? /* @__PURE__ */ g(C, { children: [
    "Showing ",
    /* @__PURE__ */ a("span", { className: "tabular-nums", children: d }),
    " of",
    " ",
    /* @__PURE__ */ a("span", { className: "tabular-nums", children: e })
  ] }) : null;
  return /* @__PURE__ */ a(h.Provider, { value: N, children: /* @__PURE__ */ g(
    "div",
    {
      "data-slot": "pagination",
      className: u("flex items-center gap-2 w-full", s),
      children: [
        /* @__PURE__ */ a(
          "div",
          {
            "data-slot": "pagination-info",
            className: "grow text-sm text-kumo-strong",
            children: A()
          }
        ),
        /* @__PURE__ */ a(P, { controls: k })
      ]
    }
  ) });
}
M.displayName = "Pagination";
const q = Object.assign(M, {
  Info: I,
  PageSize: w,
  Controls: P,
  Separator: y
});
export {
  q as P
};
//# sourceMappingURL=pagination-e3dp8bd80s35f7sd.js.map
