import React from 'react'
import { Pagination as FlowbitePagination } from 'flowbite-react'
import paginationTheme from '../themes/pagination'
import NumberOfRow from './NumberOfRow'
import { useIsMobile } from '@/lib/hooks/useIsMobile'

interface PaginationProps {
  from: number | null
  to: number | null
  total: number
  currentPage: number
  lastPage: number
  limit?: number
  handleLimitChange: (limit: number) => void
  handlePageChange: (page: number) => void
}

export default function Pagination({
  from,
  to,
  total,
  currentPage,
  lastPage,
  limit,
  handleLimitChange,
  handlePageChange,
}: PaginationProps) {
  const isMobile = useIsMobile()

  return from ? (
    <div className="flex items-center justify-between w-full mt-10 flex-wrap">
      <div className="flex items-center flex-wrap gap-2">
        {limit && (
          <NumberOfRow limit={limit} handleLimitChange={handleLimitChange} />
        )}

        <p className="text-body text-nowrap">
          Showing from <b>{from}</b> to <b>{to}</b> of <b>{total}</b> entries
        </p>
      </div>

      <FlowbitePagination
        layout={`${isMobile ? 'navigation' : 'pagination'}`}
        currentPage={currentPage}
        totalPages={lastPage}
        showIcons
        onPageChange={handlePageChange}
        theme={paginationTheme}
      />
    </div>
  ) : null
}
