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