from __future__ import annotations

from typing import *  # type: ignore

import rio

from .page_builder import build_page
from .. import components as comps
from .. import services


class Member(rio.Component):
    database_service: services.DatabaseService

    def __init__(self) -> None:
        super().__init__()
        self.database_service = self.session[services.DatabaseService]

    @rio.event.on_populate
    async def on_populate(self) -> None:
        await self.session.set_title("EZ GG e.V. - Mitglieder")

    def build(self) -> rio.Component:
        grid = rio.Grid()
        for i, member in enumerate(self.database_service.get_members()):
            grid.add(
                comps.MemberCard(member),
                row=i // 2,
                column=i % 2,
            )
        return build_page(grid, window_width=self.session.window_width)
