using Gtk 4.0;
using Adw 1;

template $PackagesPage : Adw.BreakpointBin {
    width-request: 1;
	height-request: 1;

    Adw.Breakpoint packages_bpt {
		condition ("max-width: 600")

		setters {
			packages_split.collapsed: true;
            packages_split.show-content: false;
            content_stack.transition-duration: 9999999;
            reset_filters_button.visible: true;
		}
	}

    Adw.NavigationPage {
        title: _("Packages");
        Stack stack {
            Adw.ToolbarView loading_view {
                [top]
                Adw.HeaderBar {
                    [start]
                    $SidebarButton {}
                }
            }
            Adw.ToolbarView uninstalling_view {
                [top]
                Adw.HeaderBar {
                    [start]
                    $SidebarButton {}
                }
            }
            Adw.ToolbarView reinstalling_view {
                [top]
                Adw.HeaderBar {
                    [start]
                    $SidebarButton {}
                }
            }
            Adw.ToolbarView changing_version_view {
                [top]
                Adw.HeaderBar {
                    [start]
                    $SidebarButton {}
                }
            }
            Adw.NavigationSplitView packages_split {
                sidebar-width-fraction: 0.5;
                max-sidebar-width: 999999999;
                sidebar:
                    Adw.NavigationPage packages_navpage {
                        title: _("Packages");
                        Adw.ToastOverlay packages_toast_overlay {
                            Adw.ToolbarView packages_tbv {
                                [top]
                                Adw.HeaderBar {
                                    [start]
                                    $SidebarButton {}
                                    [start]
                                    ToggleButton search_button {
                                        icon-name: "loupe-large-symbolic";
                                        tooltip-text: _("Search Packages");
                                    }
                                    [end]
                                    ToggleButton filter_button {
                                        icon-name: "funnel-symbolic";
                                        tooltip-text: _("Filter Packages");
                                    }
                                    [end]
                                    ToggleButton select_button {
                                        icon-name: "selection-mode-symbolic";
                                        tooltip-text: _("Select Packages");
                                    }
                                }
                                [top]
                                SearchBar search_bar {
                                    search-mode-enabled: bind search_button.active bidirectional;
                                    SearchEntry search_entry {
                                        hexpand: true;
                                        placeholder-text: _("Search Packages");
                                    }
                                }
                                Stack status_stack {
                                    ScrolledWindow scrolled_window {
                                        ListBox packages_list_box {
                                            styles ["navigation-sidebar"]
                                        }
                                    }
                                    Adw.StatusPage no_filter_results {
                                        title: _("No Packages Match Filters");
                                        description: _("No installed package matches all of the currently applied filters");
                                        icon-name: "funnel-symbolic";
                                        Button reset_filters_button {
                                            label: _("Reset Filters");
                                            halign: center;
                                            visible: false;
                                            styles ["pill"]
                                        }
                                    }
                                    Adw.StatusPage no_packages {
                                        title: _("No Packages Found");
                                        description: _("Warehouse cannot see the list of installed packages or your system has no packages installed");
                                        icon-name: "error-symbolic";
                                    }
                                    Adw.StatusPage no_results {
                                        title: _("No Results Found");
                                        description: _("Try a different search");
                                        icon-name: "system-search-symbolic";
                                    }
                                }
                                [bottom]
                                Revealer {
                                    reveal-child: bind select_button.active;
                                    transition-type: slide_up;
                                    [center]
                                    Box bottom_bar {
                                        styles ["toolbar"]
                                        hexpand: true;
                                        homogeneous: true;
                                        Button select_all_button {
                                            styles ["raised"]
                                            Adw.ButtonContent {
                                                icon-name: "selection-mode-symbolic";
                                                label: _("Select All");
                                                can-shrink: true;
                                            }
                                        }
                                        MenuButton copy_button {
                                            styles ["raised"]
                                            Adw.ButtonContent {
                                                icon-name: "edit-copy-symbolic";
                                                label: _("Copy");
                                                can-shrink: true;
                                            }
                                            popover: copy_pop;
                                        }
                                        Button uninstall_button {
                                            styles ["raised"]
                                            Adw.ButtonContent {
                                                icon-name: "user-trash-symbolic";
                                                label: _("Uninstall");
                                                can-shrink: true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                ;
                content:
                    Adw.NavigationPage {
                        title: "Content Stack";
                        Stack content_stack {
                            transition-type: slide_left_right;
                            $PropertiesPage properties_page {}
                            $FiltersPage filters_page {}
                        }
                    }
                ;
            }
        }
    }
}

Popover copy_pop {
    styles ["menu"]
    ListBox copy_menu {
        Label copy_names {
            label: _("Copy Names");
            halign: start;
        }
        Label copy_ids {
            label: _("Copy IDs");
            halign: start;
        }
        Label copy_refs {
            label: _("Copy Refs");
            halign: start;
        }
    }
}
