from __future__ import annotations

from pathlib import Path

import rio
from from_root import from_root

from . import pages
from . import components as comps
from . import services
from .services import AuthenticationStatus

rio.Icon.register_single_icon(
    set_name="custom",
    icon_name="steam",
    icon_source=from_root("ezgg_website/assets/icons/steam.svg")
)

rio.Icon.register_single_icon(
    set_name="custom",
    icon_name="discord",
    icon_source=from_root("ezgg_website/assets/icons/discord.svg")
)

rio.Icon.register_single_icon(
    set_name="custom",
    icon_name="x",
    icon_source=from_root("ezgg_website/assets/icons/x.svg")
)

rio.Icon.register_single_icon(
    set_name="custom",
    icon_name="facebook",
    icon_source=from_root("ezgg_website/assets/icons/facebook.svg")
)

rio.Icon.register_single_icon(
    set_name="custom",
    icon_name="youtube",
    icon_source=from_root("ezgg_website/assets/icons/youtube.svg")
)

rio.Icon.register_single_icon(
    set_name="custom",
    icon_name="twitch",
    icon_source=from_root("ezgg_website/assets/icons/twitch.svg")
)

rio.Icon.register_single_icon(
    set_name="custom",
    icon_name="instagram",
    icon_source=from_root("ezgg_website/assets/icons/instagram.svg")
)

rio.Icon.register_single_icon(
    set_name="custom",
    icon_name="linkedin",
    icon_source=from_root("ezgg_website/assets/icons/linkedin.svg")
)

rio.Icon.register_single_icon(
    set_name="custom",
    icon_name="git",
    icon_source=from_root("ezgg_website/assets/icons/git.svg")
)

themes = [
    # Grey/Purple
    rio.Theme.from_colors(
        primary_color=rio.Color.from_hex("bb86fc"),
        secondary_color=rio.Color.from_hex("6200ee"),
        neutral_color=rio.Color.from_hex("1e1e1e"),
        background_color=rio.Color.from_hex("121212"),
        hud_color=rio.Color.from_hex("bb86fc"),
        text_color=rio.Color.from_hex("FFFFFF"),
        light=False,
    ),

    # Grey/Turquoise
    rio.Theme.from_colors(
        primary_color=rio.Color.from_hex("03dac5"),
        secondary_color=rio.Color.from_hex("018786"),
        neutral_color=rio.Color.from_hex("1e1e1e"),
        background_color=rio.Color.from_hex("121212"),
        hud_color=rio.Color.from_hex("03dac5"),
        text_color=rio.Color.from_hex("FFFFFF"),
        light=False,
    ),

    # Grey/Pink
    rio.Theme.from_colors(
        primary_color=rio.Color.from_hex("fe1f70"),
        secondary_color=rio.Color.from_hex("a32263"),
        neutral_color=rio.Color.from_hex("1e1e1e"),
        background_color=rio.Color.from_hex("121212"),
        hud_color=rio.Color.from_hex("fe1f70"),
        text_color=rio.Color.from_hex("FFFFFF"),
        light=False,
    ),

    # Grey/Red
    rio.Theme.from_colors(
        primary_color=rio.Color.from_hex("ec1e2a"),
        secondary_color=rio.Color.from_hex("9b1725"),
        neutral_color=rio.Color.from_hex("1e1e1e"),
        background_color=rio.Color.from_hex("121212"),
        hud_color=rio.Color.from_hex("ec1e2a"),
        text_color=rio.Color.from_hex("FFFFFF"),
        light=False,
    ),

    # Grey/Orange
    rio.Theme.from_colors(
        primary_color=rio.Color.from_hex("ff800d"),
        secondary_color=rio.Color.from_hex("ae5714"),
        neutral_color=rio.Color.from_hex("1e1e1e"),
        background_color=rio.Color.from_hex("121212"),
        hud_color=rio.Color.from_hex("ff800d"),
        text_color=rio.Color.from_hex("FFFFFF"),
        light=False,
    ),

    # Grey/Blue
    rio.Theme.from_colors(
        primary_color=rio.Color.from_hex("2c89ff"),
        secondary_color=rio.Color.from_hex("2376dc"),
        neutral_color=rio.Color.from_hex("1e1e1e"),
        background_color=rio.Color.from_hex("121212"),
        hud_color=rio.Color.from_hex("2c89ff"),
        text_color=rio.Color.from_hex("FFFFFF"),
        light=False,
    ),
    # Turquoise - Dark
    rio.Theme.from_colors(
        primary_color=rio.Color.from_hex("03dac5"),
        secondary_color=rio.Color.from_hex("018786"),
        neutral_color=rio.Color.from_hex("1e1e1e"),
        background_color=rio.Color.from_hex("121212"),
        hud_color=rio.Color.from_hex("03dac5"),
        text_color=rio.Color.from_hex("FFFFFF"),
        light=False,
    ),
    # Turquoise - Light
    rio.Theme.from_colors(
        primary_color=rio.Color.from_hex("03dac5"),
        secondary_color=rio.Color.from_hex("018786"),
        neutral_color=rio.Color.from_hex("FFFFFF"),
        background_color=rio.Color.from_hex("FFFFFF"),
        hud_color=rio.Color.from_hex("03dac5"),
        text_color=rio.Color.from_hex("000000"),
        light=True,
    )
]


async def on_session_start(s: rio.Session) -> None:
    s.authentication_status = AuthenticationStatus(None, None)
    await s.set_title("EZ GG e.V.")

# Create the Rio app
database_service = services.DatabaseService()
authentication_service = services.FileBasedAuthenticationService(
    from_root("pw.txt"),
    raise_broken_entries=False
)
app = rio.App(
    name='EZGG Homepage',
    pages=[
        rio.Page(
            name="Home",
            page_url='',
            build=pages.Home
        ),
        rio.Page(
            name="About",
            page_url='about',
            build=pages.About
        ),
        rio.Page(
            name="Member",
            page_url='member',
            build=pages.Member
        ),
        rio.Page(
            name="Constitution",
            page_url='constitution',
            build=pages.Constitution
        ),
        rio.Page(
            name="Join",
            page_url='join',
            build=pages.Join
        ),
        rio.Page(
            name="Pics",
            page_url='pics',
            build=pages.Pics
        ),
        rio.Page(
            name="Imprint",
            page_url='imprint',
            build=pages.Imprint
        ),
        rio.Page(
            name="Privacy",
            page_url='privacy',
            build=pages.Privacy
        )
    ],
    theme=themes[6],
    icon=from_root("ezgg_website/assets/icons/favicon.png"),
    assets_dir=Path(__file__).parent / "assets",
    on_session_start=on_session_start,
    default_attachments=[database_service, authentication_service],
    meta_tags={
        # "content-Type": "text/html; utf-8",  # Temporarily disabled until "http-equiv" is supported by Rio
        # "Pragma": "cache",  # Temporarily disabled until "http-equiv" is supported by Rio
        "robots": "INDEX,FOLLOW",
        # "content-Language": "de",  # Temporarily disabled until "http-equiv" is supported by Rio
        "description": "Homepage der Einfach Zocken Gaming Gesellschaft. Ein eingetragener Verein der sich mit "
                       "Videospielen und themenverwandten Aktivitäten befasst.",
        "og:description": "Homepage der Einfach Zocken Gaming Gesellschaft. Ein eingetragener Verein der sich mit "
                       "Videospielen und themenverwandten Aktivitäten befasst.",
        "keywords": "Gaming, Clan, Guild, Verein, Club, Einfach, Zocken, Genuss, Gesellschaft, Videospiele, "
                    "Videogames, LAN, Party",
        "author": "David Rodenkirchen",
        "publisher": "EZ GG e.V.",
        "copyright": "EZ GG e.V.",
        "audience": "Alle",
        "page-type": "Private Homepage",
        "page-topic": "Gesellschaft",
        # "Reply-to": "vorstand@ezgg-ev.de",  # Temporarily disabled until "http-equiv" is supported by Rio
        "expires": "",
        "revisit-after": "2 days"
    }
)
