import { CurrentUserMark } from '../../types/mark.ts'
import styles from '../DrawPDFFields/style.module.scss'
import { FONT_SIZE, FONT_TYPE, inPx } from '../../utils/pdf.ts'

interface PdfMarkItemProps {
  userMark: CurrentUserMark
  handleMarkClick: (id: number) => void
  selectedMarkValue: string
  selectedMark: CurrentUserMark | null
  scale: number
}

/**
 * Responsible for display an individual Pdf Mark.
 */
const PdfMarkItem = ({
  selectedMark,
  handleMarkClick,
  selectedMarkValue,
  userMark,
  scale
}: PdfMarkItemProps) => {
  const { location } = userMark.mark
  const handleClick = () => handleMarkClick(userMark.mark.id)
  const isEdited = () => selectedMark?.mark.id === userMark.mark.id
  const getMarkValue = () =>
    isEdited() ? selectedMarkValue : userMark.currentValue
  return (
    <div
      onClick={handleClick}
      className={`file-mark ${styles.drawingRectangle} ${isEdited() && styles.edited}`}
      style={{
        left: inPx(location.left * scale),
        top: inPx(location.top * scale),
        width: inPx(location.width * scale),
        height: inPx(location.height * scale),
        fontFamily: FONT_TYPE,
        fontSize: inPx(FONT_SIZE * scale)
      }}
    >
      {getMarkValue()}
    </div>
  )
}

export default PdfMarkItem
