import flet as ft
from pages.documents.home import DocumentsHome

class NavigationUser:
    def __init__(self, page: ft.Page, home):
        self.page = page
        self.home = home

        self.documente_juridice = ft.NavigationRailDestination(
            icon=ft.Icons.BALANCE_OUTLINED,
            selected_icon=ft.Icons.BALANCE,
            label="Documente Juridice",
        )
        self.articole_si_publicatii = ft.NavigationRailDestination(
            icon=ft.Icons.ARTICLE_OUTLINED,
            selected_icon=ft.Icons.ARTICLE,
            label="Articole si Publicatii",
        )
        self.comunicare = ft.NavigationRailDestination(
            icon=ft.Icons.CHAT_BUBBLE_OUTLINE,
            selected_icon=ft.Icons.CHAT,
            label=ft.Text("Comunicare"),
        )
        self.consultanta = ft.NavigationRailDestination(
            icon=ft.Icons.HANDSHAKE_OUTLINED,
            selected_icon=ft.Icons.HANDSHAKE,
            label=ft.Text("Consultanta"),
        )
        self.convocator = ft.NavigationRailDestination(
            icon=ft.Icons.BUSINESS_OUTLINED,
            selected_icon=ft.Icons.BUSINESS,
            label=ft.Text("Convocator"),
        )
        self.licitatii_si_lucrari = ft.NavigationRailDestination(
            icon=ft.Icons.ASSIGNMENT_TURNED_IN_OUTLINED,
            selected_icon=ft.Icons.ASSIGNMENT_TURNED_IN,
            label=ft.Text("Licitatii si Lucrari"),
        )
        self.profil = ft.NavigationRailDestination(
            icon=ft.Icons.ACCOUNT_BOX_OUTLINED,
            selected_icon=ft.Icons.ACCOUNT_BOX,
            label=ft.Text("Profil"),
        )
        self.abonamente = ft.NavigationRailDestination(
            icon=ft.Icons.REPEAT_OUTLINED,
            selected_icon=ft.Icons.REPEAT_ON,
            label=ft.Text("Abonamente"),
        )
        self.setari = ft.NavigationRailDestination(
            icon=ft.Icons.SETTINGS_OUTLINED,
            selected_icon=ft.Icons.SETTINGS,
            label=ft.Text("Setari"),
        )
        self.logout = ft.NavigationRailDestination(
            icon=ft.Icons.LOGOUT_OUTLINED,
            selected_icon=ft.Icons.LOGOUT,
            label=ft.Text("Deconectare"),
        )

    def build(self):
        return [
            self.documente_juridice,
            self.articole_si_publicatii,
            self.comunicare,
            self.consultanta,
            self.convocator,
            self.licitatii_si_lucrari,
            self.profil,
            self.abonamente,
            self.setari,
            self.logout
        ]

    def build_documente_juridice(self):
        self.docs = DocumentsHome(self.page, self.home)
        return self.docs.build()
    
    async def on_nav_change(self, e):
        print( "Selected destination:", e.control.selected_index)
        if e.control.selected_index == 0:
            self.home.placeholder.content = self.build_documente_juridice()
            self.page.update()

        if e.control.selected_index == 1:
            pass

        if e.control.selected_index == 2:
            pass

        if e.control.selected_index == 3:
            await ft.SharedPreferences().clear()
            self.page.session.store.clear()
            self.page.go('/auth')