import flet as ft
from dbActions.products import Products
from admin.inventory.providers import Providers
from admin.inventory.goods_reception import GoodsReception
from admin.inventory.packing import Packing

class Inventory:
    def __init__(self, page: ft.Page, dashboard):
        self.page = page
        self.dashboard = dashboard
        self.product_manager = Products()

    def on_providers_btn_click(self, e):
        providers = Providers(self.page, self.dashboard, self)
        self.dashboard.placeholder.content = providers.build()
        self.dashboard.placeholder.update()

    def on_goods_btn_click(self, e):
        goods = GoodsReception(self.page, self.dashboard, self)
        self.dashboard.placeholder.content = goods.build()
        self.dashboard.placeholder.update()

    def on_packing_btn_click(self, e):
        pack = Packing(self.page, self.dashboard, self)
        self.dashboard.placeholder.content = pack.build()
        self.dashboard.placeholder.update()

    def build(self):
        return ft.Container(
            content=ft.Column(
                [
                    ft.GridView(
                        [
                            ft.Card(
                                content=ft.Container(
                                    content=ft.Column(
                                        [
                                            ft.Icon(name=ft.Icons.FIRE_TRUCK, size=100),
                                            ft.Text("Management Furnizori", size=16, weight=ft.FontWeight.BOLD),
                                            ft.Button("Furnizori", icon=ft.Icons.FORWARD, on_click=self.on_providers_btn_click)
                                        ],
                                        horizontal_alignment=ft.CrossAxisAlignment.CENTER
                                    ),
                                    padding=10
                                )
                            ),
                            ft.Card(
                                content=ft.Container(
                                    content=ft.Column(
                                        [
                                            ft.Icon(name=ft.Icons.TABLE_VIEW, size=100),
                                            ft.Text("Receptie Marfa", size=16, weight=ft.FontWeight.BOLD),
                                            ft.Button("Marfa", icon=ft.Icons.FORWARD, on_click=self.on_goods_btn_click)
                                        ],
                                        horizontal_alignment=ft.CrossAxisAlignment.CENTER
                                    ),
                                    padding=10
                                )
                            ),
                            ft.Card(
                                content=ft.Container(
                                    content=ft.Column(
                                        [
                                            ft.Icon(name=ft.Icons.MOVE_TO_INBOX, size=100),
                                            ft.Text("Ambalare Produse", size=16, weight=ft.FontWeight.BOLD),
                                            ft.Button("Ambalare", icon=ft.Icons.FORWARD, on_click=self.on_packing_btn_click)
                                        ],
                                        horizontal_alignment=ft.CrossAxisAlignment.CENTER
                                    ),
                                    padding=10
                                )
                            )
                        ],
                        spacing=10,
                        runs_count=4,
                        max_extent=250,
                        child_aspect_ratio=1.0,
                        expand=True,
                        width=1000
                    )
                ]
            )
        )