from __future__ import annotations

from typing import *  # type: ignore

import rio
from from_root import from_root

from .page_builder import build_page
from .. import components as comps
from ..components.news_post import NewsPostImage


class Home(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.")

    def build(self) -> rio.Component:
        self.session.get_permission_level = True
        return build_page(rio.Column(
            rio.Rectangle(
                content=rio.Markdown("### Willkommen auf der Homepage der EZ GG e.V.", margin=1),
                fill=self.session.theme.neutral_color,
                corner_radius=self.session.theme.corner_radius_medium,
                shadow_radius=0.5,
                shadow_color=self.session.theme.hud_color,
                shadow_offset_y=0,
                margin_bottom=1,
                margin_right=1
            ),
            comps.build_news_post(
                header="EZGG LAN Edition 1.0",
                article_text_path_or_text=from_root("ezgg_website/assets/news_26_05_26.md"),
                date="26.05.2026",
                images=[NewsPostImage(
                    from_root("ezgg_website/assets/ezgglan1.jpg"),
                    "https://verwaltung.ezgg-ev.de/adm_program/modules/photos/photo_show.php?photo_uuid=9022b270-be58-41a3-b2fd-51be34308f3c&photo_nr=18"
                )],
            ),
            comps.build_news_post(
                header="LAN Party im Hasenheim",
                article_text_path_or_text=from_root("ezgg_website/assets/news_31_03_26.md"),
                date="31.03.2026",
                images=[NewsPostImage(
                    from_root("ezgg_website/assets/hasenheim_lan.jpg"),
                    "https://verwaltung.ezgg-ev.de/adm_program/modules/photos/photo_show.php?photo_uuid=d6abd7e8-9d93-48c9-b396-f70c80c8a63b&photo_nr=12&max_width=4000&max_height=4000"
                )],
            ),
            comps.build_news_post(
                header="Die EZ GG auf dem Wintermarkt",
                article_text_path_or_text=from_root("ezgg_website/assets/news_16_11_25.md"),
                date="16.11.2025",
                images=[NewsPostImage(
                    from_root("ezgg_website/assets/wintermarkt_2025.jpeg"),
                    "https://verwaltung.ezgg-ev.de/adm_program/modules/photos/photos.php?photo_uuid=aa6b59b5-1fb9-44f4-bb16-dcfab3c0cbf4"
                )],
            ),
            comps.build_news_post(
                header="Bottenhorner Wintermarkt",
                article_text_path_or_text=from_root("ezgg_website/assets/news_11_11_25.md"),
                date="11.11.2025",
                images=[],
            ),
            comps.build_news_post(
                header="Das war die BieberLAN 49",
                article_text_path_or_text=from_root("ezgg_website/assets/news_07_10_25.md"),
                date="07.10.2025",
                images=[NewsPostImage(
                    from_root("ezgg_website/assets/bl49.jpeg"),
                    "https://verwaltung.ezgg-ev.de/adm_program/modules/photos/photos.php?photo_uuid=0a515422-b1fc-44ef-ac5b-ad4ec0385a20"
                )],
            ),
            comps.build_news_post(
                header="Himmelfahrt und Maibowle",
                article_text_path_or_text=from_root("ezgg_website/assets/news_30_05_25.md"),
                date="30.05.2025",
                images=[NewsPostImage(
                    from_root("ezgg_website/assets/himmelfahrt_2025.jpg"),
                    "https://verwaltung.ezgg-ev.de/adm_program/modules/photos/photos.php?photo_uuid=87fc4564-6aba-48a0-af6e-1b393abebd61"
                )],
            ),
            comps.build_news_post(
                header="Meter-Meister EZ GG !",
                article_text_path_or_text=from_root("ezgg_website/assets/news_14_04_25.md"),
                date="14.04.2025",
                images=[NewsPostImage(
                        from_root("ezgg_website/assets/meterpokal.jpg"),
                        "https://verwaltung.ezgg-ev.de/adm_program/modules/photos/photo_show.php?photo_uuid=133f2828-15c6-4105-acdb-272da9774a3f&photo_nr=18"
                    )],
            ),
            comps.build_news_post(
                header="Hier kommt die EZ-LAN",
                article_text_path_or_text=from_root("ezgg_website/assets/news_27_03_25.md"),
                date="27.03.2025",
                images=[],
            ),
            comps.build_news_post(
                header="Das war die BK-LuxusLAN 15",
                article_text_path_or_text=from_root("ezgg_website/assets/news_25_11_24.md"),
                date="25.11.2024",
                images=[
                    NewsPostImage(
                        from_root("ezgg_website/assets/bk_luxus_lan_15.jpeg"),
                        "https://verwaltung.ezgg-ev.de/adm_program/modules/photos/photo_show.php?photo_uuid=bc0c54ce-a87e-426a-893d-2bbcc2c28ce3&photo_nr=3"
                    )
                ],
            ),
            # ToDo: Add "load more" feature
            # comps.build_news_post(
            #     header="Eine Laura und 21 Bilder",
            #     article_text_path_or_text=from_root("ezgg_website/assets/news_25_10_24.md"),
            #     date="25.10.2024"
            # ),
            # comps.build_news_post(
            #     header="LANd in Sicht!",
            #     article_text_path_or_text=from_root("ezgg_website/assets/news_18_10_24.md"),
            #     date="18.10.2024"
            # ),
            # comps.build_news_post(
            #     header="Doppelte Neuaufnahme",
            #     article_text_path_or_text=from_root("ezgg_website/assets/news_10_08_24.md"),
            #     date="10.08.2024"
            # ),
            # comps.build_news_post(
            #     header="Weiterer Neuzugang im Verein!",
            #     article_text_path_or_text=from_root("ezgg_website/assets/news_23_07_24.md"),
            #     date="23.07.2024"
            # ),
            # comps.build_news_post(
            #     header="Neuzugang im Verein!",
            #     article_text_path_or_text=from_root("ezgg_website/assets/news_19_07_24.md"),
            #     date="19.07.2024"
            # ),
            # comps.build_news_post(
            #     header="Eintragung abgeschlossen!",
            #     article_text_path_or_text=from_root("ezgg_website/assets/news_06_06_24.md"),
            #     images=[NewsPostImage(from_root("ezgg_website/assets/a38.png"), None)],
            #     date="06.06.2024"
            # ),
            # comps.build_news_post(
            #     header="Beitrittsformular verfügbar",
            #     article_text_path_or_text=from_root("ezgg_website/assets/news_02_06_24.md"),
            #     date="02.06.2024"
            # ),
            # comps.build_news_post(
            #     header="Startschuss für Homepage",
            #     article_text_path_or_text=from_root("ezgg_website/assets/news_27_05_24.md"),
            #     date="24.05.2024"
            # )
        ), window_width=self.session.window_width)
