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):
    @rio.event.on_window_size_change
    async def on_window_size_change(self) -> None:
        await self.force_refresh()

    @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.session[services.DatabaseService].get_members()):
            grid.add(
                comps.build_member_card(member),
                row=i // 3,
                column=i % 3,
            )
        return build_page(grid, window_width=self.session.window_width)
