import { PdfFile } from '../../types/drawing.ts'
import { CurrentUserMark, Mark, MarkConfigDetails } from '../../types/mark.ts'
import PdfPageItem  from './PdfPageItem.tsx';

interface PdfItemProps {
  pdfFile: PdfFile
  marks: Mark[]
  handleMarkClick: (id: number) => void
  currentMarkValue: string
  currentUserMark: CurrentUserMark | null
}

const PdfItem = ({ pdfFile, marks, handleMarkClick, currentMarkValue, currentUserMark }: PdfItemProps) => {
  const filterByPage = (marks: Mark[], page: number): Mark[] => {
    return marks.filter((mark) => mark.location.page === page);
  }
  return (
    pdfFile.pages.map((page, i) => {
      return (
        <PdfPageItem
          page={page}
          key={i}
          marks={filterByPage(marks, i)}
          handleMarkClick={handleMarkClick}
          currentMarkValue={currentMarkValue}
          currentUserMark={currentUserMark}
        />
      )
  }))
}

export default PdfItem