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