from model import *
from imgui_bundle import imgui

class StudentList:
    def __init__(self):
        super().__init__()
    
        self.select: int = 0

    def __call__(self, clas: Class):
        id = clas.id if clas else None
        students = Student.select().where(Student.class_id == id) if id else None

        with imgui.begin("Student Table", False, imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_COLLAPSE):
            if not students:
                imgui.text("No Dataset could be queried")
                return 
    
            for n, student in enumerate(students, start=1):
                display = f"{n}. {student.prename} {student.surname}"
                opened, _ = imgui.selectable(display, self.select == n-1)
                if opened:
                    self.select = n-1

        return students[self.select]
    
    
