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