import flet as ft
from pages.orders_in_page import OrdersInPage
from pages.orders_out_page import OrdersOutPage
from pages.archive_in_page import ArchiveInPage
from pages.archive_page import ArchivePage

class OrdersPage:
    def __init__(self, page: ft.Page, dashboard):
        self.page = page
        self.dashboard = dashboard

    def on_orders_in_btn_click(self, e):
        order_in_page = OrdersInPage(self.page, self.dashboard)
        self.dashboard.placeholder.content = order_in_page.build()
        self.dashboard.placeholder.update()

    def on_orders_out_btn_click(self, e):
        orders_out_page = OrdersOutPage(self.page, self.dashboard)
        self.dashboard.placeholder.content = orders_out_page.build()
        self.dashboard.placeholder.update()

    def on_archive_order_out_btn_click(self, e):
        archive = ArchivePage(self.page, self.dashboard, self)
        self.dashboard.placeholder.content = archive.build()
        self.dashboard.placeholder.update()

    def on_archive_order_in_btn_click(self, e):
        archive = ArchiveInPage(self.page, self.dashboard, self)
        self.dashboard.placeholder.content = archive.build()
        self.dashboard.placeholder.update()

    def build(self):
        return ft.Container(
            content=ft.Column(
                [
                    ft.Text("Orders", size=24, weight=ft.FontWeight.BOLD),
                    ft.Row(
                        [
                            ft.Container(
                                content=ft.Column(
                                    [
                                        ft.Icon(ft.Icons.ARROW_CIRCLE_DOWN, size=150),
                                        ft.Container(
                                            ft.Row(
                                                [
                                                    ft.Text("Orders In", size=20)
                                                ],
                                                alignment=ft.MainAxisAlignment.CENTER
                                            ),
                                            bgcolor=ft.Colors.BLUE_200,
                                            width=250,
                                            height=80
                                        ),
                                        ft.Row(
                                            [
                                                ft.FilledButton(
                                                    "Create",
                                                    on_click=self.on_orders_in_btn_click,
                                                    width=100
                                                ),
                                                ft.FilledButton(
                                                    "Archive",
                                                    on_click=self.on_archive_order_in_btn_click,
                                                    width=100
                                                )
                                            ],
                                            alignment=ft.MainAxisAlignment.SPACE_EVENLY
                                        )
                                        
                                    ],
                                    alignment=ft.MainAxisAlignment.CENTER,
                                    horizontal_alignment=ft.CrossAxisAlignment.CENTER
                                ),
                                border=ft.border.all(1, ft.Colors.GREY_300),
                                bgcolor=ft.Colors.BLUE_50,
                                padding = ft.padding.symmetric(vertical=20),
                                width=250,
                                height=350,
                                border_radius=20
                            ),
                            ft.Container(
                                content=ft.Column(
                                    [
                                        ft.Icon(ft.Icons.ARROW_CIRCLE_UP, size=150),
                                        ft.Container(
                                            ft.Row(
                                                [
                                                    ft.Text("Orders Out", size=20)
                                                ],
                                                alignment=ft.MainAxisAlignment.CENTER
                                            ),
                                            bgcolor=ft.Colors.BLUE_200,
                                            width=250,
                                            height=80
                                        ),
                                        ft.Row(
                                            [
                                                ft.FilledButton(
                                                    "Create",
                                                    on_click=self.on_orders_out_btn_click,
                                                    width=100
                                                ),
                                                ft.FilledButton(
                                                    "Archive",
                                                    on_click=self.on_archive_order_out_btn_click,
                                                    width=100
                                                )
                                            ],
                                            alignment=ft.MainAxisAlignment.SPACE_EVENLY
                                        )
                                    ],
                                    alignment=ft.MainAxisAlignment.CENTER,
                                    horizontal_alignment=ft.CrossAxisAlignment.CENTER
                                ),
                                border=ft.border.all(1, ft.Colors.GREY_300),
                                bgcolor=ft.Colors.BLUE_50,
                                padding = ft.padding.symmetric(vertical=20),
                                width=250,
                                height=350,
                                border_radius=20
                            )
                        ],
                        alignment=ft.MainAxisAlignment.CENTER,
                        spacing=50
                    ),
                    ft.Text(" ")
                ],
                expand=True,
                alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
            ),
            expand=True
        )