import React from 'react';
import { prevPageLink, paginationNav, nextPageLink } from './pagination.module.css';

interface Pagination {
  currentPage: number;
  numPages: number;
  rootPath: string;
}

export default ({
  currentPage,
  numPages,
  rootPath,
}: Pagination): JSX.Element => {
  let prevPageLinkItem = null;
  if (currentPage === 2) {
    prevPageLinkItem = (
      <a href={rootPath} className={prevPageLink}>
        &lt;&lt;
      </a>
    );
  } else if (currentPage !== 1) {
    prevPageLinkItem = (
      <a
        href={rootPath + '/' + (currentPage - 1)}
        className={prevPageLink}
      >
        &lt;&lt;
      </a>
    );
  }

  if (numPages !== 1) {
    return (
      <p className={paginationNav}>
        {prevPageLinkItem}
        {currentPage}
        {currentPage !== numPages && (
          <a
            href={rootPath + '/' + (currentPage + 1)}
            className={nextPageLink}
          >
            &gt;&gt;
          </a>
        )}
      </p>
    );
  }

  return null;
};
