"use client";
import { jsxs as m, jsx as n } from "react/jsx-runtime";
import { useState as b, useEffect as N, useMemo as h } from "react";
import { I as s } from "./input-group-Bl6tgD5-.js";
import { CaretDoubleLeftIcon as x, CaretLeftIcon as v, CaretRightIcon as I, CaretDoubleRightIcon as M } from "@phosphor-icons/react";
const w = {
  controls: "full"
};
function g({
  page: i = 1,
  perPage: t,
  totalCount: r,
  setPage: o,
  controls: c = w.controls
}) {
  const [d, a] = b(1);
  N(() => {
    a(i);
  }, [i]);
  const f = h(() => {
    let e = i * (t ?? 1) - (t ?? 0) + 1, u = Math.min(i * (t ?? 0), r ?? 0);
    return Number.isNaN(e) && (e = 0), Number.isNaN(u) && (u = 0), `${e}-${u}`;
  }, [i, t, r]), l = h(() => Math.ceil((r ?? 1) / (t ?? 1)), [r, t]);
  return /* @__PURE__ */ m("div", { className: "flex items-center justify-between gap-2", children: [
    /* @__PURE__ */ n("div", { className: "grow text-sm text-kumo-strong", children: r && r > 0 ? `Showing ${f} of ${r}` : null }),
    /* @__PURE__ */ n("div", { children: /* @__PURE__ */ m(s, { focusMode: "individual", children: [
      c === "full" && /* @__PURE__ */ n(
        s.Button,
        {
          variant: "secondary",
          "aria-label": "First page",
          disabled: i <= 1,
          onClick: () => {
            o(1), a(1);
          },
          children: /* @__PURE__ */ n(x, { size: 16 })
        }
      ),
      /* @__PURE__ */ n(
        s.Button,
        {
          variant: "secondary",
          "aria-label": "Previous page",
          disabled: i <= 1,
          onClick: () => {
            const e = Math.max(i - 1, 1);
            o(e), a(e);
          },
          children: /* @__PURE__ */ n(v, { size: 16 })
        }
      ),
      c === "full" && /* @__PURE__ */ n(
        s.Input,
        {
          style: { width: 50 },
          className: "text-center",
          "aria-label": "Page number",
          value: d,
          onValueChange: (e) => {
            a(Number(e));
          },
          onBlur: () => {
            let e = Math.max(d, 1);
            e = Math.min(e, l), o(e), a(e);
          }
        }
      ),
      /* @__PURE__ */ n(
        s.Button,
        {
          variant: "secondary",
          "aria-label": "Next page",
          disabled: i === l,
          onClick: () => {
            const e = Math.min(i + 1, l);
            o(e), a(e);
          },
          children: /* @__PURE__ */ n(I, { size: 16 })
        }
      ),
      c === "full" && /* @__PURE__ */ n(
        s.Button,
        {
          variant: "secondary",
          "aria-label": "Last page",
          disabled: i === l,
          onClick: () => {
            o(l), a(l);
          },
          children: /* @__PURE__ */ n(M, { size: 16 })
        }
      )
    ] }) })
  ] });
}
export {
  g as P
};
//# sourceMappingURL=pagination-C4HQqodz.js.map
