from rio import Component, Rectangle, Text, Column, Icon, TextStyle, PointerEventListener, PointerEvent


class AdminNavigationCard(Component):
    icon_name: str
    display_text: str
    target_url: str

    def on_press(self, _: PointerEvent) -> None:
        if self.target_url:
            self.session.navigate_to(self.target_url)

    def build(self) -> Component:
        return PointerEventListener(
            Rectangle(
                content=Column(
                    Icon(
                        self.icon_name,
                        min_width=3.5,
                        min_height=3.5,
                        fill="background",
                        margin=1
                    ),
                    Text(self.display_text, style=TextStyle(fill=self.session.theme.background_color), justify="center", margin=1, margin_top=0)
                ),
                cursor="pointer",
                stroke_width=0.2,
                stroke_color=self.session.theme.background_color,
                hover_stroke_width=0.2,
                hover_stroke_color=self.session.theme.hud_color,
                min_width=10,
                min_height=10,
                corner_radius=0.2
            ),
            on_press=self.on_press
        )