import { Button } from '@/components/ui/button';

type DataTablePaginationProps = {
    pageIndex: number;
    pageCount: number;
    pageSize: number;
    totalRows: number;
    pageRowCount: number;
    onPreviousPage: () => void;
    onNextPage: () => void;
};

export function DataTablePagination({
    pageIndex,
    pageCount,
    pageSize,
    totalRows,
    pageRowCount,
    onPreviousPage,
    onNextPage,
}: DataTablePaginationProps) {
    const pageStart =
        totalRows === 0 || pageRowCount === 0 ? 0 : pageIndex * pageSize + 1;
    const pageEnd =
        totalRows === 0 || pageRowCount === 0
            ? 0
            : pageIndex * pageSize + pageRowCount;

    return (
        <div className="flex flex-col gap-3 py-4 sm:flex-row sm:items-center sm:justify-between">
            <p className="text-sm text-muted-foreground">
                Showing {pageStart}-{pageEnd} of {totalRows} row
                {totalRows === 1 ? '' : 's'}
            </p>
            <div className="flex items-center gap-2">
                <span className="px-2 text-xs text-muted-foreground">
                    Page {totalRows === 0 ? 0 : pageIndex + 1} of{' '}
                    {totalRows === 0 ? 0 : pageCount}
                </span>
                <Button
                    type="button"
                    variant="outline"
                    size="sm"
                    onClick={onPreviousPage}
                    disabled={pageIndex <= 0}
                >
                    Previous
                </Button>
                <Button
                    type="button"
                    variant="outline"
                    size="sm"
                    onClick={onNextPage}
                    disabled={pageIndex >= pageCount - 1 || totalRows === 0}
                >
                    Next
                </Button>
            </div>
        </div>
    );
}
