import { jsx as l, jsxs as _ } from "react/jsx-runtime";
import { useState as q, useMemo as F, useCallback as j, createElement as G } from "react";
import { d as H, e as J, f as Q } from "../tools/icons.js";
import { c as U, s as W, m as w, x as X, a as Y } from "../tools/tools.js";
import { P as Z } from "./pagination-basic.js";
import { P as C } from "./pagination-item.js";
import { P as g } from "./pagination-link.js";
import { P as x } from "./pagination-nav.js";
import { P as I } from "./pagination-span.js";
const E = (b, p, P, h) => X(b, p, P, h).map((m, d) => ({
  active: b === m,
  dots: typeof m == "string",
  hover: !1,
  id: d,
  value: m
})), c = function(p) {
  const {
    alignment: P,
    alwaysShowEllipsis: h = !1,
    as: m = "ul",
    className: d,
    dropOldClass: N,
    maxVisible: f = 4,
    navProps: K,
    next: R = !0,
    nextOption: e,
    onChange: u,
    option: s,
    page: T = 0,
    previous: V = !0,
    previousOption: r,
    size: D,
    style: L,
    total: v = 0,
    variables: M,
    ...$
  } = p, [i, B] = q(
    E(T, v, f, h)
  ), z = F(() => {
    const a = U(
      !N && "pagination",
      D && `pagination-${D}`,
      P && `justify-content-${P}`,
      d
    ), o = W((n, t) => ({ tKey: Y(t) }), M, L);
    return { className: a, style: o };
  }, [P, d, N, D, L, M]), k = j(
    (a, o) => {
      var S;
      const n = ((S = i.find((A) => A.active)) == null ? void 0 : S.value) ?? 0;
      let t;
      a === "<" ? t = Math.max(n - f, 0) : a === ">" ? t = Math.min(n + f, v) : t = a, B(E(t, v, f, h)), u == null || u(t, o);
    },
    [h, u, i, f, v]
  ), y = j(() => {
    const a = i.find((o) => o.active);
    return a ? a.value : 0;
  }, [i]);
  if (!(v <= 0))
    return /* @__PURE__ */ l(x, { ...K, children: /* @__PURE__ */ _(m, { ...$, ...z, children: [
      V && /* @__PURE__ */ l(
        C,
        {
          ...r == null ? void 0 : r.itemProps,
          disabled: (r == null ? void 0 : r.disabled) ?? y() === i[0].value,
          children: /* @__PURE__ */ l(
            g,
            {
              ...w(r == null ? void 0 : r.linkProps, { href: (r == null ? void 0 : r.href) ?? "" }),
              onClick: (a) => {
                a.preventDefault(), k(y() - 1, "previous");
              },
              children: (r == null ? void 0 : r.link) ?? "Previous"
            }
          )
        }
      ),
      i.map((a, o) => /* @__PURE__ */ G(C, { ...s == null ? void 0 : s.itemProps, active: a.active, key: a.id }, a.dots ? /* @__PURE__ */ l(
        g,
        {
          ...s == null ? void 0 : s.linkProps,
          href: "",
          onClick: (n) => {
            n.preventDefault(), k(a.value, a.value);
          },
          onMouseEnter: () => B((n) => (n[o].hover = !0, [...n])),
          onMouseLeave: () => B((n) => (n[o].hover = !1, [...n])),
          children: a.hover ? a.value === "<" ? /* @__PURE__ */ l(H, {}) : /* @__PURE__ */ l(J, {}) : /* @__PURE__ */ l(Q, {})
        }
      ) : a.active && !(s != null && s.clickableActive) ? /* @__PURE__ */ l(I, { ...s == null ? void 0 : s.spanProps, children: a.value }) : /* @__PURE__ */ l(
        g,
        {
          ...s == null ? void 0 : s.linkProps,
          href: "",
          onClick: (n) => {
            n.preventDefault(), k(a.value, "page");
          },
          children: a.value
        }
      ))),
      R && /* @__PURE__ */ l(
        C,
        {
          ...e == null ? void 0 : e.itemProps,
          disabled: (e == null ? void 0 : e.disabled) ?? y() === i[i.length - 1].value,
          children: /* @__PURE__ */ l(
            g,
            {
              ...w(e == null ? void 0 : e.linkProps, { href: (e == null ? void 0 : e.href) ?? "" }),
              onClick: (a) => {
                a.preventDefault(), k(y() + 1, "next");
              },
              children: (e == null ? void 0 : e.link) ?? "Next"
            }
          )
        }
      )
    ] }) });
};
c.Basic = Z;
c.Item = C;
c.Nav = x;
c.Link = g;
c.Span = I;
c.displayName = "BRL.Pagination";
export {
  c as P
};
//# sourceMappingURL=pagination.js.map
