import React from 'react';
import style from './pagination.module.css';

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

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

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

  return null;
};
