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