import os
from typing import List
from src.model.cell import Cell
from src.model.maze import Maze
from .observer import Observer


class ConsoleView(Observer):
    def update(self, event: str):
        print(f"[EVENT] {event}")

    def render(self, maze: Maze, player_pos: Cell = None, path: List[Cell] = None):
        os.system('cls' if os.name == 'nt' else 'clear')

        path_set = set(path) if path else set()

        for y in range(maze.height):
            row = ""
            for x in range(maze.width):
                cell = maze.get_cell(x, y)

                if cell.is_wall:
                    row += "#"
                elif cell.is_start:
                    row += "S"
                elif cell.is_exit:
                    row += "E"
                elif player_pos and cell.x == player_pos.x and cell.y == player_pos.y:
                    row += "@"
                elif cell in path_set:
                    row += "*"
                else:
                    row += " "
            print(row)
