from rio import Column, Component, event, Text, Spacer, Row, Link

from src.ezgg_lan_manager import ConfigurationService, TicketingService
from src.ezgg_lan_manager.components.MainViewContentBox import MainViewContentBox


class OverviewPage(Component):
    @event.on_populate
    async def on_populate(self) -> None:
        await self.session.set_title(f"{self.session[ConfigurationService].get_lan_info().name} - Übersicht")

    def build(self) -> Component:
        lan_info = self.session[ConfigurationService].get_lan_info()
        return Column(
            MainViewContentBox(
                Column(
                    Text(lan_info.name, font_size=2, justify="center", fill=self.session.theme.neutral_color, margin_top=0.5),
                    Text(f"Edition {lan_info.iteration}", font_size=0.9, justify="center", fill=self.session.theme.neutral_color, margin_bottom=1.5)
                )
            ),
            MainViewContentBox(
                Column(
                    Text("Allgemeines", font_size=2, justify="center", fill=self.session.theme.neutral_color, margin_top=0.5, margin_bottom=1),
                    Column(
                        Row(
                            Text("Wann?", fill=self.session.theme.neutral_color, margin_left=1),
                            Spacer(),
                            Text(f"{lan_info.date_from.strftime("%d.%m.")} bis {lan_info.date_till.strftime("%d.%m.%Y")}", fill=self.session.theme.neutral_color, margin_right=1),
                            margin_bottom=0.3
                        ),
                        Row(
                            Text("Wo?", fill=self.session.theme.neutral_color, margin_left=1),
                            Spacer(),
                            Link(Text(f"DGH Donsbach", fill=self.session.theme.secondary_color, margin_right=1), target_url="https://maps.app.goo.gl/3Zyue776A22jdoxz5", open_in_new_tab=True),
                            margin_bottom=0.3
                        ),
                        Row(
                            Text("Einlass", fill=self.session.theme.neutral_color, margin_left=1),
                            Spacer(),
                            Text(lan_info.date_from.strftime("Freitag %H:%M Uhr"), fill=self.session.theme.neutral_color, margin_right=1),
                            margin_bottom=0.3
                        ),
                        Row(
                            Text("Ende", fill=self.session.theme.neutral_color, margin_left=1),
                            Spacer(),
                            Text(lan_info.date_till.strftime("Sonntag %H:%M Uhr"), fill=self.session.theme.neutral_color, margin_right=1),
                            margin_bottom=0.3
                        ),
                        Row(
                            Text("Anmeldung", fill=self.session.theme.neutral_color, margin_left=1),
                            Spacer(),
                            Text("Geöffnet", fill=self.session.theme.success_color, margin_right=1),
                            margin_bottom=0.3
                        ),
                        Row(
                            Text("Teilnehmer", fill=self.session.theme.neutral_color, margin_left=1),
                            Spacer(),
                            Text(str(self.session[TicketingService].get_total_tickets()), fill=self.session.theme.neutral_color, margin_right=1),
                            margin_bottom=0.3
                        )
                        ,
                        Row(
                            Text("Ticket Preise", fill=self.session.theme.neutral_color, margin_left=1),
                            Spacer(),
                            Link(Text(f"Preisliste", fill=self.session.theme.secondary_color, margin_right=1), target_url="./buy_ticket", open_in_new_tab=False),
                            margin_bottom=0.3
                        )
                    )
                )
            ),
            MainViewContentBox(
                Column(
                    Text("Technisches", font_size=2, justify="center", fill=self.session.theme.neutral_color, margin_top=0.5, margin_bottom=1),
                    Column(
                        Row(
                            Text("Internet", fill=self.session.theme.neutral_color, margin_left=1),
                            Spacer(),
                            Text(f"100/50 Mbit/s (down/up)", fill=self.session.theme.neutral_color, margin_right=1),
                            margin_bottom=0.3
                        ),
                        Row(
                            Text("Routing", fill=self.session.theme.neutral_color, margin_left=1),
                            Spacer(),
                            Text(f"Flaches Netz", fill=self.session.theme.neutral_color, margin_right=1),
                            margin_bottom=0.3
                        ),
                        Row(
                            Text("WLAN", fill=self.session.theme.neutral_color, margin_left=1),
                            Spacer(),
                            Text(f"vorhanden", fill=self.session.theme.neutral_color, margin_right=1),
                            margin_bottom=0.3
                        )
                    )
                )
            ),
            MainViewContentBox(
                Column(
                    Text("Sonstiges", font_size=2, justify="center", fill=self.session.theme.neutral_color, margin_top=0.5, margin_bottom=1),
                    Column(
                        Row(
                            Text("Schlafen", fill=self.session.theme.neutral_color, margin_left=1, justify="center"),
                            margin_bottom=0.3
                        ),
                        Row(
                            Text("Es steht ein Schlafsaal zur Verfügung. Nach der Eröffnung steht auch die Bühne als Schlafbereich zur Verfügung.", font_size=0.7,
                                 fill=self.session.theme.neutral_color, margin_left=1, overflow="wrap"),
                            margin_bottom=0.3
                        ),
                        Row(
                            Text("Essen & Trinken", fill=self.session.theme.neutral_color, margin_left=1, justify="center"),
                            margin_bottom=0.3
                        ),
                        Row(
                            Text("Wir sorgen für euer leibliches Wohl, ihr dürft aber auch eure eigenen Speißen und Getränke mitbringen.", font_size=0.7, fill=self.session.theme.neutral_color, margin_left=1, overflow="wrap"),
                            margin_bottom=0.3
                        ),
                        Row(
                            Text("Parken", fill=self.session.theme.neutral_color, margin_left=1, justify="center"),
                            margin_bottom=0.3
                        ),
                        Row(
                            Text("Vor der Halle sind ausreichend Parkplätze vorhanden.", font_size=0.7, fill=self.session.theme.neutral_color, margin_left=1, overflow="wrap"),
                            margin_bottom=0.3
                        )
                    )
                )
            ),
            Spacer()
        )
