uikit/dist/pagination.js
2026-06-16 10:25:04 +03:30

269 lines
7.3 KiB
JavaScript

import { jsxs as I, jsx as s } from "react/jsx-runtime";
import { useState as C, useRef as N, useEffect as v, useCallback as E } from "react";
import { HStack as y, IconButton as A, Button as g, Input as j, Text as M } from "@chakra-ui/react";
import { IoChevronForwardOutline as z, IoChevronBackOutline as S } from "react-icons/io5";
import { toFaDigits as f, toEnDigits as k } from "./utils.js";
import { P as G } from "./chunks/Pagination-6xafzB0w.js";
const L = ({
currentPage: e,
totalPages: l,
totalCount: D,
onPageChange: a
}) => {
const [r, n] = C(f(e)), [d, c] = C(!1), [b, o] = C(null), x = N(null), h = [.../* @__PURE__ */ new Set([1, e, l])].filter(
(i) => i >= 1 && i <= l
);
v(() => {
if (b !== null) {
e === b && (o(null), c(!1), n(f(e)));
return;
}
d || n(f(e));
}, [e, d, b]), v(() => {
if (!d || !r || b !== null) return;
const i = parseInt(k(r), 10);
if (isNaN(i)) return;
const m = setTimeout(() => {
var B;
const u = Math.min(Math.max(i, 1), l);
u !== e ? (o(u), n(f(u)), a(u)) : (c(!1), n(f(e))), (B = x.current) == null || B.blur();
}, 1e3);
return () => clearTimeout(m);
}, [
r,
d,
b,
l,
e,
a
]);
const w = () => {
var u, B;
const i = parseInt(k(r), 10);
if (isNaN(i)) {
n(f(e)), c(!1), o(null), (u = x.current) == null || u.blur();
return;
}
const m = Math.min(Math.max(i, 1), l);
m !== e ? (o(m), n(f(m)), a(m)) : (n(f(e)), c(!1), o(null)), (B = x.current) == null || B.blur();
};
return l === 0 || !D ? null : /* @__PURE__ */ I(
y,
{
justifyContent: "space-around",
backgroundColor: "white",
py: "10px",
px: "16px",
rounded: "lg",
border: "1px",
borderColor: "blue.200",
w: "100%",
children: [
/* @__PURE__ */ I(y, { spacing: 2, alignItems: "center", justifyContent: "center", children: [
/* @__PURE__ */ s(
A,
{
size: "md",
bg: "#e6e6f1",
color: "#4B49AC",
_hover: { bg: "#cbcbe8" },
onClick: () => a(e - 1),
isDisabled: e === 1,
icon: /* @__PURE__ */ s(z, {}),
"aria-label": "صفحه قبلی"
}
),
h.map((i) => /* @__PURE__ */ s(
g,
{
size: "md",
px: 2,
bg: e === i ? "#4B49AC" : "#e6e6f1",
color: e === i ? "#e6e6f1" : "#4B49AC",
_hover: { bg: e === i ? "#4B49AC" : "#cbcbe8" },
onClick: () => a(i),
variant: "soft",
children: f(i)
},
i
)),
/* @__PURE__ */ s(
A,
{
size: "md",
bg: "#e6e6f1",
color: "#4B49AC",
_hover: { bg: "#cbcbe8" },
onClick: () => a(e + 1),
isDisabled: e === l,
icon: /* @__PURE__ */ s(S, {}),
"aria-label": "صفحه بعدی"
}
),
/* @__PURE__ */ s(
j,
{
ref: x,
type: "text",
inputMode: "numeric",
placeholder: "صفحه",
w: "56px",
value: r,
onFocus: () => {
c(!0), o(null), n("");
},
onChange: (i) => {
const m = i.target.value, u = k(m).replace(/\D/g, "");
n(f(u));
},
onBlur: () => {
r || (n(f(e)), c(!1), o(null));
},
onKeyDown: (i) => {
i.key === "Enter" && w();
},
textAlign: "center",
color: "#1D2939",
px: 1,
minW: 0,
dir: "ltr"
}
)
] }),
/* @__PURE__ */ I(y, { spacing: 2, children: [
/* @__PURE__ */ s(M, { w: "auto", fontWeight: "bold", whiteSpace: "nowrap", children: "تعداد کل:" }),
/* @__PURE__ */ s(M, { children: f(D) })
] })
]
}
);
}, O = ({
currentPage: e,
totalPages: l,
totalCount: D,
onPageChange: a
}) => {
const [r, n] = C(""), [d, c] = C(!1), [b, o] = C(null), x = N(null), h = b ?? e, w = E(
(t) => {
const p = Math.min(Math.max(t, 1), l);
c(!1), n(""), o(null), p !== e && a(p);
},
[e, l, a]
), i = E(() => {
if (!r) {
c(!1), n(""), o(null);
return;
}
const t = parseInt(k(r), 10);
if (isNaN(t)) {
c(!1), n(""), o(null);
return;
}
const p = Math.min(Math.max(t, 1), l);
c(!1), n(""), p !== e ? (o(p), a(p)) : o(null);
}, [r, e, l, a]);
v(() => {
var t;
d && ((t = x.current) == null || t.focus());
}, [d]), v(() => {
b !== null && e === b && o(null);
}, [e, b]), v(() => {
if (!d || !r) return;
const t = setTimeout(() => {
i();
}, 1e3);
return () => clearTimeout(t);
}, [r, d, i]);
const m = () => {
o(null), n(""), c(!0);
}, u = (t, p = !1) => /* @__PURE__ */ s(
g,
{
size: "md",
bg: p ? "#4B49AC" : "#e6e6f1",
color: p ? "#e6e6f1" : "#4B49AC",
_hover: { bg: p ? "#4B49AC" : "#cbcbe8" },
onClick: p ? m : () => w(t),
variant: "soft",
children: f(t)
},
t
);
if (l === 0 || !D) return null;
const B = l > 1 && h !== 1, T = l > 1 && h !== l;
return /* @__PURE__ */ s(
y,
{
justifyContent: "center",
backgroundColor: "white",
py: "10px",
px: "16px",
rounded: "lg",
border: "1px",
borderColor: "blue.200",
w: "100%",
children: /* @__PURE__ */ I(y, { spacing: 2, alignItems: "center", justifyContent: "center", children: [
/* @__PURE__ */ s(
A,
{
size: "md",
bg: "#e6e6f1",
color: "#4B49AC",
_hover: { bg: "#cbcbe8" },
onClick: () => w(h - 1),
isDisabled: h === 1,
icon: /* @__PURE__ */ s(z, {}),
"aria-label": "صفحه قبلی"
}
),
B && u(1),
d ? /* @__PURE__ */ s(
j,
{
ref: x,
type: "text",
inputMode: "numeric",
placeholder: "صفحه",
w: "48px",
value: r,
onChange: (t) => {
const p = t.target.value, V = k(p).replace(/\D/g, "");
n(f(V));
},
onBlur: () => {
r ? i() : (n(""), c(!1), o(null));
},
onKeyDown: (t) => {
t.key === "Enter" && i(), t.key === "Escape" && (n(""), c(!1), o(null));
},
textAlign: "center",
color: "#1D2939",
px: 1,
minW: 0,
dir: "ltr"
}
) : u(h, !0),
T && u(l),
/* @__PURE__ */ s(
A,
{
size: "md",
bg: "#e6e6f1",
color: "#4B49AC",
_hover: { bg: "#cbcbe8" },
onClick: () => w(h + 1),
isDisabled: h === l,
icon: /* @__PURE__ */ s(S, {}),
"aria-label": "صفحه بعدی"
}
)
] })
}
);
};
export {
L as LightPagination,
G as Pagination,
O as SimplePagination
};