import { Search } from "lucide-react"; import { useEffect, useState, type ReactNode } from "react"; import { Button, Input, Select } from "./Ui"; export function useDebouncedValue(value: T, delay = 350) { const [debounced, setDebounced] = useState(value); useEffect(() => { const timer = window.setTimeout(() => setDebounced(value), delay); return () => window.clearTimeout(timer); }, [value, delay]); return debounced; } export function ListToolbar({ search, onSearch, total, children, placeholder = "جست‌وجو…" }: { search: string; onSearch: (value: string) => void; total: number; children?: ReactNode; placeholder?: string; }) { return
{children}
{total} رکورد
; } export function PaginationControls({ page, pageSize, total, loading, onPage, onPageSize }: { page: number; pageSize: number; total: number; loading: boolean; onPage: (page: number) => void; onPageSize: (pageSize: number) => void; }) { const totalPages = Math.max(1, Math.ceil(total / pageSize)); const pages = pageNumbers(page, totalPages); return
{pages.map((number, index) => number === null ? … : )}
صفحه {page} از {totalPages}
; } function pageNumbers(current: number, total: number): Array { if (total <= 7) return Array.from({ length: total }, (_, index) => index + 1); const values = new Set([1, total, current - 1, current, current + 1]); const sorted = [...values].filter(x => x >= 1 && x <= total).sort((a, b) => a - b); const result: Array = []; sorted.forEach((value, index) => { if (index && value - sorted[index - 1] > 1) result.push(null); result.push(value); }); return result; }