import flet as ft
from pages.auth.login import Login

class Auth:
    def __init__(self, page: ft.Page):
        self.page = page
        self.placeholder = ft.Container(
            width=350,
            border_radius=20,
            bgcolor=ft.Colors.BLUE_200 if self.page.theme_mode == ft.ThemeMode.LIGHT else ft.Colors.BLUE_900,
            padding=20
        )
        self.login = Login(self.page, self)
        self.placeholder.content = self.login.build()
        self.choose_them_color_btn = ft.IconButton(
            icon=ft.Icons.DARK_MODE,
            on_click=self.change_theme_mode
        )

    def change_theme_mode(self, e):
        self.page.theme_mode = ft.ThemeMode.DARK if self.page.theme_mode == ft.ThemeMode.LIGHT else ft.ThemeMode.LIGHT 
        self.choose_them_color_btn.icon = ft.Icons.DARK_MODE if self.page.theme_mode == ft.ThemeMode.LIGHT else ft.Icons.SUNNY
        self.choose_them_color_btn.update()
        self.placeholder.bgcolor = ft.Colors.BLUE_200 if self.page.theme_mode == ft.ThemeMode.LIGHT else ft.Colors.BLUE_800
        self.placeholder.update()
        self.page.update()


    async def set_value(self, key, value):
        await ft.SharedPreferences().set(key, str(value))

    def build(self):
        return ft.Container(
            content=ft.Column(
                [
                    # ft.Row(
                    #     [
                    #         self.choose_them_color_btn
                    #     ],
                    #     width=350,
                    #     alignment=ft.MainAxisAlignment.END,
                    #     spacing=20
                    # ),
                    ft.Row(
                        [
                            ft.Image(
                                src = "images/logo_juridic_block.png",
                                width=250
                            ),
                        ], 
                        alignment=ft.MainAxisAlignment.CENTER,
                        width=350,
                    ),
                    self.placeholder,
                ],
                alignment=ft.MainAxisAlignment.CENTER,
                spacing=20,
                expand=True
            ),
            padding=20,
            expand=True
        )