# This library plots data on a canvas (not required for the assignment).
import matplotlib.pyplot as plt


def show_image(pixels: list[list[list[int]]]) -> None:
    """Plot image.

    Parameters
    ----------
    pixels : list of list of list of int
        3-D matrix of RGB pixel values.
    """

    # Plot image in window
    plt.imshow(pixels)
    plt.axis("off")
    plt.show()


def parse_ppm_image(file_path: str) -> list[list[list[int]]]:
    """Read a PPM file into a 3-D pixel matrix.

    This assignment uses a simplified PPM parser (P3/ASCII only). More
    information about the PPM format:
    http://netpbm.sourceforge.net/doc/ppm.html

    Expected file structure (simplified):

    - Header is exactly three lines:
      1) magic number "P3"
      2) "<width> <height>"
      3) maximum color value (assumed to be 255)
    - After the header, each remaining *line* represents one image row.
      Each line contains whitespace-separated integers that form RGB triples.
      This intentionally does not implement the full PPM spec with comments or
      arbitrary line breaks.

    Parameters
    ----------
    file_path : str
        Path to the PPM file.

    Returns
    -------
    list of list of list of int
        3-D matrix of RGB pixel values.

    Examples
    --------
    >>> parse_ppm_image('path/to/image.ppm')
    [[[255, 0, 0], [0, 0, 0]],
     [[0, 0, 0], [255, 0, 0]]]

    Assuming ``path/to/image.ppm`` is:

    ```
    P3
    2 2
    255
    255 0   0   0   0   0
    0   0   0   255 0   0
    ```
    """

    raise NotImplementedError("Complete this function.")


if __name__ == "__main__":
    # Run your code in the terminal to see the plotted results.

    # 2x2 image
    img_pixel_matrix = parse_ppm_image("data/image_2x2.ppm")
    show_image(img_pixel_matrix)

    img_pixel_matrix = parse_ppm_image("data/image_50x50.ppm")
    show_image(img_pixel_matrix)
